Sfoglia il codice sorgente

fix:“优化微信公众号订单推送功能“

soobin 1 anno fa
parent
commit
d9234e3aa3

+ 2 - 1
src/main/java/com/szwl/mapper/xml/TAdminMapper.xml

@@ -36,6 +36,7 @@
         <result column="company_type" property="companyType" />
         <result column="wechat_pay_id" property="wechatPayId" />
         <result column="order_notice" property="orderNotice" />
+        <result column="api_key" property="apiKey" />
     </resultMap>
 
     <!-- 通用查询结果列 -->
@@ -44,7 +45,7 @@
         locked_date, login_date, login_failure_count, login_ip, trade_merchant_no, name,
         parent_id, password, notice_id, type, username, phone, is_refund, if_foreign, open,
         promo_code_open, apply_start_time, apply_end_time, code, pay_platform, relation_admin_id,
-        company_type, wechat_pay_id, order_notice
+        company_type, wechat_pay_id, order_notice, api_key
     </sql>
 
 </mapper>

+ 4 - 1
src/main/java/com/szwl/model/entity/TAdmin.java

@@ -103,7 +103,7 @@ public class TAdmin implements Serializable {
     @ApiModelProperty(value = "短信验证码;")
     private String code;
 
-    @ApiModelProperty(value = "支付平台; 0或null为汇聚,1为汇付支付")
+    @ApiModelProperty(value = "支付平台; 0或null为汇聚;1为汇付支付;2为收钱吧支付")
     private String payPlatform;
 
     @ApiModelProperty(value = "关联商家,相当于以前的parent_id")
@@ -121,6 +121,9 @@ public class TAdmin implements Serializable {
     @ApiModelProperty(value = "微信公众号订单通知,0:关闭,1:开启,默认关闭")
     private String orderNotice;
 
+    @ApiModelProperty(value = "第三方调用API密钥")
+    private String apiKey;
+
     @Transient
     public String getManagerId() {
 

+ 78 - 78
src/main/java/com/szwl/service/impl/TOrderServiceImpl.java

@@ -95,8 +95,6 @@ public class TOrderServiceImpl extends ServiceImpl<TOrderMapper, TOrder> impleme
     @Resource
     TAlipayConfigService alipayConfigService;
 
-    @Autowired
-    private StringRedisTemplate redisTemplate;
 
     @Autowired
     private TOrderDetailsService orderDetailsService;
@@ -522,18 +520,20 @@ public class TOrderServiceImpl extends ServiceImpl<TOrderMapper, TOrder> impleme
         String accessToken = "";
         try {
             if(StringUtils.isEmpty(companyType) || companyType.equals("0")) {
-                accessToken = redisTemplate.opsForValue().get(SZ_ACCESS_TOKEN_KEY);
+                TAdmin admin = R.getDataIfSuccess(szwlFeign.getAdmin("2738"));
+                accessToken = admin.getApiKey();
                 log.info("申泽的accessToken:{}", accessToken);
             } else {
-                accessToken = redisTemplate.opsForValue().get(SC_ACCESS_TOKEN_KEY);
+                TAdmin admin = R.getDataIfSuccess(szwlFeign.getAdmin("2739"));
+                accessToken = admin.getApiKey();
                 log.info("七云的accessToken:{}", accessToken);
             }
         } catch (Exception e) {
             e.printStackTrace();
         }
-        if(StringUtils.isEmpty(accessToken)) {
-            accessToken = getAccessToken(companyType);
-        }
+//        if(StringUtils.isEmpty(accessToken)) {
+//            accessToken = getAccessToken(companyType);
+//        }
         // 推送消息
         // 模板参数
         Map<String, WeChatTemplateMsg> sendMag = new HashMap();
@@ -568,13 +568,13 @@ public class TOrderServiceImpl extends ServiceImpl<TOrderMapper, TOrder> impleme
         } else {
             sendBody.put("template_id", HuifuConstant.SC_TEMPLATE_ID);
         }
-        String messageCode = sendMessage(accessToken, restTemplate, sendBody);
-        if (StringUtils.isNotEmpty(messageCode) && messageCode.equals("40001")) {
-            // 获取到新的accessToken
-            accessToken = getAccessToken(companyType);
-            messageCode = sendMessage(accessToken, restTemplate, sendBody);
-            log.info("微信推送结果:{}","messageCode : " + messageCode);
-        }
+        sendMessage(accessToken, restTemplate, sendBody);
+//        if (StringUtils.isNotEmpty(messageCode) && messageCode.equals("40001")) {
+//            // 获取到新的accessToken
+//            accessToken = getAccessToken(companyType);
+//            messageCode = sendMessage(accessToken, restTemplate, sendBody);
+//            log.info("微信推送结果:{}","messageCode : " + messageCode);
+//        }
     }
 
     /**
@@ -600,70 +600,70 @@ public class TOrderServiceImpl extends ServiceImpl<TOrderMapper, TOrder> impleme
      * @param companyType
      * @return
      */
-    private String getAccessToken(String companyType) {
-        String accessToken = "";
-        String url = "";
-        if(StringUtils.isEmpty(companyType) || companyType.equals("0")) {
-            url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid="
-                    + HuifuConstant.SZ_WX_SUB_APP_ID + "&secret=" + HuifuConstant.SZ_WX_APP_SECRET;
-        } else {
-            url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid="
-                    + HuifuConstant.SC_WX_SUB_APP_ID + "&secret=" + HuifuConstant.SC_WX_APP_SECRET;
-        }
-        PrintWriter out = null;
-        BufferedReader in = null;
-        String line;
-        StringBuffer stringBuffer = new StringBuffer();
-        try {
-            URL realUrl = new URL(url);
-            // 打开和URL之间的连接
-            URLConnection conn = realUrl.openConnection();
-
-            // 设置通用的请求属性 设置请求格式
-            //设置返回类型
-            conn.setRequestProperty("contentType", "text/plain");
-            //设置请求类型
-            conn.setRequestProperty("content-type", "application/x-www-form-urlencoded");
-            //设置超时时间
-            conn.setConnectTimeout(1000);
-            conn.setReadTimeout(1000);
-            conn.setDoOutput(true);
-            conn.connect();
-            // 获取URLConnection对象对应的输出流
-            out = new PrintWriter(conn.getOutputStream());
-            // flush输出流的缓冲
-            out.flush();
-            // 定义BufferedReader输入流来读取URL的响应    设置接收格式
-            in = new BufferedReader(
-                    new InputStreamReader(conn.getInputStream(), "UTF-8"));
-            while ((line = in.readLine()) != null) {
-                stringBuffer.append(line);
-            }
-            JSONObject jsonObject = JSONObject.parseObject(stringBuffer.toString());
-            log.info("获取token:{}",jsonObject.toString());
-            accessToken = jsonObject.getString("access_token");
-            if(StringUtils.isEmpty(companyType) || companyType.equals("0")) {
-                redisTemplate.opsForValue().set(SZ_ACCESS_TOKEN_KEY, accessToken, EXPIRATION_TIME, TimeUnit.SECONDS);
-            } else {
-                redisTemplate.opsForValue().set(SZ_ACCESS_TOKEN_KEY, accessToken, EXPIRATION_TIME, TimeUnit.SECONDS);
-            }
-        } catch (Exception e) {
-            e.printStackTrace();
-        } finally {
-            //使用finally块来关闭输出流、输入流
-            try {
-                if (out != null) {
-                    out.close();
-                }
-                if (in != null) {
-                    in.close();
-                }
-            } catch (IOException ex) {
-                ex.printStackTrace();
-            }
-        }
-        return accessToken;
-    }
+//    private String getAccessToken(String companyType) {
+//        String accessToken = "";
+//        String url = "";
+//        if(StringUtils.isEmpty(companyType) || companyType.equals("0")) {
+//            url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid="
+//                    + HuifuConstant.SZ_WX_SUB_APP_ID + "&secret=" + HuifuConstant.SZ_WX_APP_SECRET;
+//        } else {
+//            url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid="
+//                    + HuifuConstant.SC_WX_SUB_APP_ID + "&secret=" + HuifuConstant.SC_WX_APP_SECRET;
+//        }
+//        PrintWriter out = null;
+//        BufferedReader in = null;
+//        String line;
+//        StringBuffer stringBuffer = new StringBuffer();
+//        try {
+//            URL realUrl = new URL(url);
+//            // 打开和URL之间的连接
+//            URLConnection conn = realUrl.openConnection();
+//
+//            // 设置通用的请求属性 设置请求格式
+//            //设置返回类型
+//            conn.setRequestProperty("contentType", "text/plain");
+//            //设置请求类型
+//            conn.setRequestProperty("content-type", "application/x-www-form-urlencoded");
+//            //设置超时时间
+//            conn.setConnectTimeout(1000);
+//            conn.setReadTimeout(1000);
+//            conn.setDoOutput(true);
+//            conn.connect();
+//            // 获取URLConnection对象对应的输出流
+//            out = new PrintWriter(conn.getOutputStream());
+//            // flush输出流的缓冲
+//            out.flush();
+//            // 定义BufferedReader输入流来读取URL的响应    设置接收格式
+//            in = new BufferedReader(
+//                    new InputStreamReader(conn.getInputStream(), "UTF-8"));
+//            while ((line = in.readLine()) != null) {
+//                stringBuffer.append(line);
+//            }
+//            JSONObject jsonObject = JSONObject.parseObject(stringBuffer.toString());
+//            log.info("获取token:{}",jsonObject.toString());
+//            accessToken = jsonObject.getString("access_token");
+//            if(StringUtils.isEmpty(companyType) || companyType.equals("0")) {
+//                redisTemplate.opsForValue().set(SZ_ACCESS_TOKEN_KEY, accessToken, EXPIRATION_TIME, TimeUnit.SECONDS);
+//            } else {
+//                redisTemplate.opsForValue().set(SZ_ACCESS_TOKEN_KEY, accessToken, EXPIRATION_TIME, TimeUnit.SECONDS);
+//            }
+//        } catch (Exception e) {
+//            e.printStackTrace();
+//        } finally {
+//            //使用finally块来关闭输出流、输入流
+//            try {
+//                if (out != null) {
+//                    out.close();
+//                }
+//                if (in != null) {
+//                    in.close();
+//                }
+//            } catch (IOException ex) {
+//                ex.printStackTrace();
+//            }
+//        }
+//        return accessToken;
+//    }
 
     public void processRefund(Map<String, Object> bodyMap) {
         String decrypt = wechatPayConfigService.decryptFromResource(bodyMap);