|
@@ -523,7 +523,11 @@ public class WeixinServiceImpl implements WeixinService {
|
|
|
@Override
|
|
|
public Boolean doSendSubscribeMessage(Integer merchantId, String reqDataJsonStr) {
|
|
|
try {
|
|
|
- String url = "https://api.weixin.qq.com/cgi-bin/message/subscribe/send?access_token=" + getAccessToken(merchantId, true,true);
|
|
|
+ String token = getAccessToken(merchantId, true,true);
|
|
|
+ if (StringUtil.isEmpty(token)) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ String url = "https://api.weixin.qq.com/cgi-bin/message/subscribe/send?access_token=" + token;
|
|
|
String response = HttpRESTDataClient.requestPost(url, "application/json; charset=utf-8", reqDataJsonStr);
|
|
|
logger.info("WeixinService sendSubscribeMessage response={}", response);
|
|
|
JSONObject json = (JSONObject) JSONObject.parse(response);
|
|
@@ -648,6 +652,10 @@ public class WeixinServiceImpl implements WeixinService {
|
|
|
public String createQrCode(Integer merchantId, String type, Integer id, String page, Integer width) throws BusinessCheckException {
|
|
|
try {
|
|
|
String accessToken = getAccessToken(merchantId, true,true);
|
|
|
+ if (StringUtil.isEmpty(accessToken)) {
|
|
|
+ throw new BusinessCheckException("生成二维码出错,请检查小程序配置");
|
|
|
+ }
|
|
|
+
|
|
|
String url = "https://api.weixin.qq.com/cgi-bin/wxaapp/createwxaqrcode?access_token=" + accessToken;
|
|
|
String reqDataJsonStr = "";
|
|
|
|
|
@@ -657,34 +665,58 @@ public class WeixinServiceImpl implements WeixinService {
|
|
|
reqData.put("width", width);
|
|
|
reqDataJsonStr = JsonUtil.toJSONString(reqData);
|
|
|
|
|
|
- byte[] bytes = HttpRESTDataClient.requestPost(url, reqDataJsonStr);
|
|
|
- logger.info("WechatService createStoreQrCode reqData:{}", reqDataJsonStr);
|
|
|
-
|
|
|
- String pathRoot = env.getProperty("images.root");
|
|
|
- String baseImage = env.getProperty("images.path");
|
|
|
-
|
|
|
- String filePath = "Qr" + type + id + ".png";
|
|
|
- String path = pathRoot + baseImage + filePath;
|
|
|
- QRCodeUtil.saveQrCodeToLocal(bytes, path);
|
|
|
-
|
|
|
- // 上传阿里云oss
|
|
|
- String mode = env.getProperty("aliyun.oss.mode");
|
|
|
- if (mode.equals("1")) { // 检查是否开启上传
|
|
|
- String endpoint = env.getProperty("aliyun.oss.endpoint");
|
|
|
- String accessKeyId = env.getProperty("aliyun.oss.accessKeyId");
|
|
|
- String accessKeySecret = env.getProperty("aliyun.oss.accessKeySecret");
|
|
|
- String bucketName = env.getProperty("aliyun.oss.bucketName");
|
|
|
- String folder = env.getProperty("aliyun.oss.folder");
|
|
|
- OSS ossClient = AliyunOssUtil.getOSSClient(accessKeyId, accessKeySecret, endpoint);
|
|
|
- File ossFile = new File(path);
|
|
|
- return AliyunOssUtil.upload(ossClient, ossFile, bucketName, folder);
|
|
|
- } else {
|
|
|
- return baseImage + filePath;
|
|
|
+ JSONObject jsonParam = new JSONObject();
|
|
|
+ jsonParam.put("path", page);
|
|
|
+ jsonParam.put("width", width);
|
|
|
+
|
|
|
+ InputStream inputStream = HttpRESTDataClient.doWXPost(url, jsonParam);
|
|
|
+
|
|
|
+ ByteArrayOutputStream output = new ByteArrayOutputStream();
|
|
|
+ byte[] buffer = new byte[1024];
|
|
|
+ int n;
|
|
|
+ while (-1 != (n = inputStream.read(buffer))) {
|
|
|
+ output.write(buffer, 0, n);
|
|
|
+ }
|
|
|
+ byte[] bytes = output.toByteArray();
|
|
|
+
|
|
|
+ String resStr = output.toString();
|
|
|
+ try {
|
|
|
+ JSONObject res = JSON.parseObject(resStr);
|
|
|
+ String errCode = res.get("errcode").toString();
|
|
|
+ if (errCode.equals("40001")) {
|
|
|
+ getAccessToken(merchantId, true, false);
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ logger.info("WechatService createStoreQrCode reqData:{}", reqDataJsonStr);
|
|
|
+
|
|
|
+ String pathRoot = env.getProperty("images.root");
|
|
|
+ String baseImage = env.getProperty("images.path");
|
|
|
+
|
|
|
+ String filePath = "Qr" + type + id + ".png";
|
|
|
+ String path = pathRoot + baseImage + filePath;
|
|
|
+ QRCodeUtil.saveQrCodeToLocal(bytes, path);
|
|
|
+
|
|
|
+ // 上传阿里云oss
|
|
|
+ String mode = env.getProperty("aliyun.oss.mode");
|
|
|
+ if (mode.equals("1")) { // 检查是否开启上传
|
|
|
+ String endpoint = env.getProperty("aliyun.oss.endpoint");
|
|
|
+ String accessKeyId = env.getProperty("aliyun.oss.accessKeyId");
|
|
|
+ String accessKeySecret = env.getProperty("aliyun.oss.accessKeySecret");
|
|
|
+ String bucketName = env.getProperty("aliyun.oss.bucketName");
|
|
|
+ String folder = env.getProperty("aliyun.oss.folder");
|
|
|
+ OSS ossClient = AliyunOssUtil.getOSSClient(accessKeyId, accessKeySecret, endpoint);
|
|
|
+ File ossFile = new File(path);
|
|
|
+ return AliyunOssUtil.upload(ossClient, ossFile, bucketName, folder);
|
|
|
+ } else {
|
|
|
+ return baseImage + filePath;
|
|
|
+ }
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
logger.error("生成店铺二维码出错啦:{}", e.getMessage());
|
|
|
- throw new BusinessCheckException("生成店铺二维码出错,请检查小程序配置");
|
|
|
+ throw new BusinessCheckException("生成二维码出错,请检查小程序配置.");
|
|
|
}
|
|
|
+
|
|
|
+ throw new BusinessCheckException("生成二维码出错,请稍后再试.");
|
|
|
}
|
|
|
|
|
|
/**
|