| | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.matrix.core.tools.LogUtil; |
| | | import com.matrix.core.tools.PropertiesUtil; |
| | | import com.matrix.core.tools.StringUtils; |
| | | import com.matrix.system.common.constance.AppConstance; |
| | | import org.apache.http.HttpResponse; |
| | |
| | | import org.apache.http.entity.StringEntity; |
| | | import org.apache.http.impl.client.CloseableHttpClient; |
| | | import org.apache.http.impl.client.HttpClientBuilder; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.http.*; |
| | | import org.springframework.stereotype.Component; |
| | | import org.springframework.web.client.RestTemplate; |
| | | |
| | | import java.io.*; |
| | | import java.util.HashMap; |
| | | import java.util.Map; |
| | | |
| | | @Component |
| | | public class WxacodeUtil { |
| | | /** |
| | | * 小程序秘钥 |
| | | */ |
| | | private static final String XCX_SECRET = "xcx_secret"; |
| | | /** |
| | | * 小程序appid |
| | | */ |
| | | private static final String XCX_APPID = "xcx_appid"; |
| | | |
| | | |
| | | @Value("${file_storage_path}") |
| | | private String fileStoragePath; |
| | | |
| | | @Value("${static_resource_url}") |
| | | private String staticResourceUrl; |
| | | |
| | | |
| | | /** |
| | | * token获取地址 |
| | | */ |
| | |
| | | */ |
| | | private static final String GET_WXACODE ="https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token="; |
| | | |
| | | public static String getWxacode(String scene,String page,String fileName) throws Exception { |
| | | public String getWxacode(String scene,String page,String fileName,String appid,String secret) throws Exception { |
| | | LogUtil.debug("scene={},page={},fileName={}",scene,page,fileName); |
| | | //获取token |
| | | String appid = PropertiesUtil.getString(XCX_APPID); |
| | | String secret = PropertiesUtil.getString(XCX_SECRET); |
| | | String result1 = get(TOKEN_URL.replace("APPID", appid).replace("SECRET", secret)); |
| | | String access_token = JSONObject.parseObject(result1).getString("access_token"); |
| | | if(StringUtils.isNotBlank(access_token)) { |
| | |
| | | InputStream inputStream = response.getEntity().getContent(); |
| | | |
| | | // 图片保存目录路径 |
| | | String baseSavePath = PropertiesUtil.getString(AppConstance.FILES_TORAGE_PATH); |
| | | String baseSavePath = fileStoragePath; |
| | | File targetFile = new File(baseSavePath); |
| | | if(!targetFile.exists()){ |
| | | targetFile.mkdirs(); |