zhijiezhao пре 2 месеци
родитељ
комит
090fa087cf

+ 1 - 1
src/main/java/com/caimei365/order/components/HeliPayUtil.java

@@ -160,7 +160,7 @@ public class HeliPayUtil {
                 // 联合丽格
                 pay.setP5_appid(mcareAppId);
             } else {
-                pay.setP5_appid(miniAppId);
+                pay.setP5_appid("wx3122abbfea989c49");
             }
         }
         return pay;

+ 73 - 64
src/main/java/com/caimei365/order/components/WeChatService.java

@@ -2,11 +2,8 @@ package com.caimei365.order.components;
 
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONObject;
-import com.alibaba.fastjson.annotation.JSONType;
-
 import com.caimei365.order.model.ResponseJson;
 import com.caimei365.order.utils.RequestUtil;
-
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.codec.binary.Base64;
 import org.apache.commons.lang.StringUtils;
@@ -69,6 +66,7 @@ public class WeChatService {
     private String messageTemplateReceipt;
 
     private RedisService redisService;
+
     @Autowired
     public void setRedisService(RedisService redisService) {
         this.redisService = redisService;
@@ -154,6 +152,12 @@ public class WeChatService {
             log.info("联合丽格小程序appId: ---" + mcareAppId);
             // 联合丽格小程序appSecret
             requestUrlParam.put("secret", mcareAppSecret);
+        } else if (mode == 5) {
+            // 二手小程序appId
+            requestUrlParam.put("appid", "wx3122abbfea989c49");
+            log.info("二手小程序appId: ---" + mcareAppId);
+            // 二手小程序appSecret
+            requestUrlParam.put("secret", "a04496eacf388779c2eab14f78abba21");
         } else {
             // 呵呵商城小程序appId
             requestUrlParam.put("appid", heHeAppId);
@@ -207,7 +211,7 @@ public class WeChatService {
             // 静默授权
             link = link.replace("snsapi_userinfo", "snsapi_base");
         }
-        log.info("》》》》授权消息"+link);
+        log.info("》》》》授权消息" + link);
         return link;
     }
 
@@ -234,7 +238,7 @@ public class WeChatService {
         link = link.replace("CODE", code);
         // 发送授权链接,得到微信用户信息
         String result = RequestUtil.sendGet(link);
-        log.info("用户信息获取成功"+result);
+        log.info("用户信息获取成功" + result);
         Map<String, Object> map = JSONObject.parseObject(result, Map.class);
         return map;
     }
@@ -282,7 +286,7 @@ public class WeChatService {
     public Map<String, Object> getUserInfoByWeb(String access_token, String openId) throws Exception {
         String requestUrl = "https://api.weixin.qq.com/sns/userinfo?access_token=" + access_token + "&openid=" + openId;
         String userInfo = RequestUtil.sendGet(requestUrl);
-        log.info("获取用户信息"+userInfo);
+        log.info("获取用户信息" + userInfo);
         Map<String, Object> map = JSONObject.parseObject(userInfo, Map.class);
         return map;
     }
@@ -290,20 +294,21 @@ public class WeChatService {
 
     /**
      * 推送收款微信模板消息(公众号)
-     *
+     * <p>
      * 模板内容:
      * {{first.DATA}}
      * 交易金额:{{keyword1.DATA}}
      * 交易时间:{{keyword2.DATA}}
      * {{remark.DATA}}
      * 在发送时,需要将内容中的参数({{.DATA}}内为参数)赋值替换为需要的信息
+     *
      * @param accessToken 微信公众号 access_token
-     * @param openid 被推送人微信公众号的openid
-     * @param title 标题
-     * @param money 金额
-     * @param time 日期时间
-     * @param remarkText 备注文本:收款类型+确认时间
-     * @param pagePath 小程序跳转链接
+     * @param openid      被推送人微信公众号的openid
+     * @param title       标题
+     * @param money       金额
+     * @param time        日期时间
+     * @param remarkText  备注文本:收款类型+确认时间
+     * @param pagePath    小程序跳转链接
      */
     public void sendTemplateMsg(String accessToken, String openid, String title, Double money, String time, String remarkText, String pagePath) {
         JSONObject first = new JSONObject();
@@ -331,8 +336,8 @@ public class WeChatService {
 
         JSONObject json = new JSONObject();
         json.put("touser", openid);
-        json.put("template_id",messageTemplateReceipt);
-        json.put("url","https://www.caimei365.com/");
+        json.put("template_id", messageTemplateReceipt);
+        json.put("url", "https://www.caimei365.com/");
         json.put("miniprogram", miniProgram);
         json.put("data", data);
         // json 字符串
@@ -340,7 +345,7 @@ public class WeChatService {
         log.info(">>>>>>>>推送微信模板消息:" + jsonString);
         try {
             // https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=ACCESS_TOKEN
-            String requestUrl = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token="+accessToken;
+            String requestUrl = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=" + accessToken;
             // 发送请求
             String result = RequestUtil.httpRequest(requestUrl, "POST", jsonString);
             log.info(">>>>>>>>推送结果:" + result);
@@ -351,16 +356,17 @@ public class WeChatService {
 
     /**
      * 下单消息推送
+     *
      * @param accessToken 微信公众号
-     * @param openid 公众号的openid
-     * @param title 标题
-     * @param name 商品名称
-     * @param orderno 订单编号
-     * @param money 金额
-     * @param remarkText 备注
-     * @param pagePath 跳转链接
+     * @param openid      公众号的openid
+     * @param title       标题
+     * @param name        商品名称
+     * @param orderno     订单编号
+     * @param money       金额
+     * @param remarkText  备注
+     * @param pagePath    跳转链接
      */
-    public void sendTemplateMsgs(String accessToken, String openid, String title, String name,String orderno, Double money, String remarkText, String pagePath) {
+    public void sendTemplateMsgs(String accessToken, String openid, String title, String name, String orderno, Double money, String remarkText, String pagePath) {
         JSONObject first = new JSONObject();
         first.put("value", title);
         JSONObject keyword1 = new JSONObject();
@@ -379,14 +385,14 @@ public class WeChatService {
         data.put("keyword3", keyword3);
         data.put("remark", remark);
 
-       JSONObject miniProgram = new JSONObject();
-       miniProgram.put("appid", miniAppId);
-       miniProgram.put("pagepath", pagePath);
+        JSONObject miniProgram = new JSONObject();
+        miniProgram.put("appid", miniAppId);
+        miniProgram.put("pagepath", pagePath);
 
         JSONObject json = new JSONObject(new LinkedHashMap());
-        json.put("touser",openid);
-        json.put("template_id","lLPssEY0tx6k5jT-8tDQgEpInf5quA3_M9RsI9aw3IM");
-        json.put("url","https://www.caimei365.com/");
+        json.put("touser", openid);
+        json.put("template_id", "lLPssEY0tx6k5jT-8tDQgEpInf5quA3_M9RsI9aw3IM");
+        json.put("url", "https://www.caimei365.com/");
         json.put("miniprogram", miniProgram);
         json.put("data", data);
         // json 字符串
@@ -395,7 +401,7 @@ public class WeChatService {
         try {
             // https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=ACCESS_TOKEN
 //            String requestUrl =  "https://api.weixin.qq.com/cgi-bin/message/wxopen/template/send?access_token="+accessToken;
-            String requestUrl = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token="+accessToken;
+            String requestUrl = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=" + accessToken;
             // 发送请求
             String result = RequestUtil.httpRequest(requestUrl, "POST", jsonString);
             log.info(">>>>>>>>推送结果:" + result);
@@ -406,17 +412,18 @@ public class WeChatService {
 
     /**
      * 发货消息推送
+     *
      * @param accessToken
      * @param openid
-     * @param title 标题
-     * @param orderno 订单编号
-     * @param time 发货时间
-     * @param company 快递名称
-     * @param companyno 快递编号
-     * @param remarkText 备注
-     * @param pagePath 跳转链接
+     * @param title       标题
+     * @param orderno     订单编号
+     * @param time        发货时间
+     * @param company     快递名称
+     * @param companyno   快递编号
+     * @param remarkText  备注
+     * @param pagePath    跳转链接
      */
-    public void sendTemplateMsgy(String accessToken, String openid, String title, String orderno,String time, String company, String companyno,String remarkText, String pagePath) {
+    public void sendTemplateMsgy(String accessToken, String openid, String title, String orderno, String time, String company, String companyno, String remarkText, String pagePath) {
         JSONObject first = new JSONObject();
         first.put("value", title);
         first.put("color", "#000000");
@@ -459,7 +466,7 @@ public class WeChatService {
         log.info(">>>>>>>>推送微信模板消息:" + jsonString);
         try {
             // https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=ACCESS_TOKEN
-              String requestUrl =  "https://api.weixin.qq.com/cgi-bin/message/wxopen/template/send?access_token=ACCESS_TOKEN";
+            String requestUrl = "https://api.weixin.qq.com/cgi-bin/message/wxopen/template/send?access_token=ACCESS_TOKEN";
 //            String requestUrl = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token="+accessToken;
             // 发送请求
             String result = RequestUtil.httpRequest(requestUrl, "POST", jsonString);
@@ -471,17 +478,18 @@ public class WeChatService {
 
     /**
      * 购买成功消息推送
+     *
      * @param accessToken
      * @param openid
-     * @param title 标题
-     * @param paytime 付款时间
-     * @param name 商品名称
-     * @param orderno 商品编号
-     * @param money 订单金额
-     * @param remarkText 备注
-     * @param pagePath 跳转链接
+     * @param title       标题
+     * @param paytime     付款时间
+     * @param name        商品名称
+     * @param orderno     商品编号
+     * @param money       订单金额
+     * @param remarkText  备注
+     * @param pagePath    跳转链接
      */
-    public void sendTemplateMsgz(String accessToken, String openid, String title,String paytime, String name,String orderno, Double money, String remarkText, String pagePath) {
+    public void sendTemplateMsgz(String accessToken, String openid, String title, String paytime, String name, String orderno, Double money, String remarkText, String pagePath) {
         JSONObject first = new JSONObject();
         first.put("value", title);
         JSONObject keyword1 = new JSONObject();
@@ -519,7 +527,7 @@ public class WeChatService {
         log.info(">>>>>>>>推送微信模板json消息:" + json);
         try {
             // https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=ACCESS_TOKEN
-            String requestUrl = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token="+accessToken;
+            String requestUrl = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=" + accessToken;
             // 发送请求
             String result = RequestUtil.httpRequest(requestUrl, "POST", jsonString);
             log.info(">>>>>>>>推送结果:" + result);
@@ -530,14 +538,15 @@ public class WeChatService {
 
     /**
      * 续费会员消息推送
+     *
      * @param accessToken 微信公众号
-     * @param openid 公众号的openid
-     * @param title 标题
-     * @param name 商品名称
-     * @param remarkText 备注
-     * @param pagePath 跳转链接
+     * @param openid      公众号的openid
+     * @param title       标题
+     * @param name        商品名称
+     * @param remarkText  备注
+     * @param pagePath    跳转链接
      */
-    public void sendTempl(String accessToken, String openid, String title, String name,String type,String date,String remarkText, String pagePath) {
+    public void sendTempl(String accessToken, String openid, String title, String name, String type, String date, String remarkText, String pagePath) {
         JSONObject first = new JSONObject();
         first.put("value", title);
         JSONObject keyword1 = new JSONObject();
@@ -561,9 +570,9 @@ public class WeChatService {
         miniProgram.put("pagepath", pagePath);
 
         JSONObject json = new JSONObject(new LinkedHashMap());
-        json.put("touser",openid);
-        json.put("template_id","QHsM0AhlgGaX6kJ6vFm1wAKIkNjnZdWPjFGOKopLbsM");
-        json.put("url","https://www.caimei365.com/");
+        json.put("touser", openid);
+        json.put("template_id", "QHsM0AhlgGaX6kJ6vFm1wAKIkNjnZdWPjFGOKopLbsM");
+        json.put("url", "https://www.caimei365.com/");
         json.put("miniprogram", miniProgram);
         json.put("data", data);
         // json 字符串
@@ -572,7 +581,7 @@ public class WeChatService {
         try {
             // https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=ACCESS_TOKEN
 //            String requestUrl =  "https://api.weixin.qq.com/cgi-bin/message/wxopen/template/send?access_token="+accessToken;
-            String requestUrl = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token="+accessToken;
+            String requestUrl = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=" + accessToken;
             // 发送请求
             String result = RequestUtil.httpRequest(requestUrl, "POST", jsonString);
             log.info(">>>>>>>>推送结果:" + result);
@@ -585,7 +594,7 @@ public class WeChatService {
     /**
      * 续费会员消息推送
      */
-    public void sendTemplss(String accessToken, String openid,String Time, String pagePath) {
+    public void sendTemplss(String accessToken, String openid, String Time, String pagePath) {
         JSONObject first = new JSONObject();
         first.put("value", "恭喜您成功续费采美超级会员");
         JSONObject keyword1 = new JSONObject();
@@ -606,9 +615,9 @@ public class WeChatService {
         miniProgram.put("pagepath", pagePath);
 
         JSONObject json = new JSONObject(new LinkedHashMap());
-        json.put("touser",openid);
-        json.put("template_id","QHsM0AhlgGaX6kJ6vFm1wAKIkNjnZdWPjFGOKopLbsM");
-        json.put("url","https://www.caimei365.com/");
+        json.put("touser", openid);
+        json.put("template_id", "QHsM0AhlgGaX6kJ6vFm1wAKIkNjnZdWPjFGOKopLbsM");
+        json.put("url", "https://www.caimei365.com/");
         json.put("miniprogram", miniProgram);
         json.put("data", data);
         // json 字符串
@@ -617,7 +626,7 @@ public class WeChatService {
         try {
             // https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=ACCESS_TOKEN
 //            String requestUrl =  "https://api.weixin.qq.com/cgi-bin/message/wxopen/template/send?access_token="+accessToken;
-            String requestUrl = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token="+accessToken;
+            String requestUrl = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=" + accessToken;
             // 发送请求
             String result = RequestUtil.httpRequest(requestUrl, "POST", jsonString);
             log.info(">>>>>>>>推送结果:" + result);

+ 6 - 10
src/main/java/com/caimei365/order/service/impl/HeliPayNonOrderServiceImpl.java

@@ -14,7 +14,6 @@ import com.caimei365.order.model.bo.PayParamBo;
 import com.caimei365.order.model.bo.VipRecordBo;
 import com.caimei365.order.model.dto.HeliDto;
 import com.caimei365.order.model.dto.PayCouponDto;
-import com.caimei365.order.model.enums.AccountPayOrderType;
 import com.caimei365.order.model.enums.AppPayType;
 import com.caimei365.order.model.enums.PayType;
 import com.caimei365.order.model.po.*;
@@ -37,9 +36,6 @@ import org.springframework.stereotype.Service;
 import javax.annotation.Resource;
 import java.beans.IntrospectionException;
 import java.lang.reflect.InvocationTargetException;
-import java.math.BigDecimal;
-import java.security.NoSuchAlgorithmException;
-import java.security.spec.InvalidKeySpecException;
 import java.text.SimpleDateFormat;
 import java.util.*;
 
@@ -94,7 +90,7 @@ public class HeliPayNonOrderServiceImpl implements HeliPayNonOrderService {
         if ("GZH".equals(heliDto.getPayType()) || "XCX".equals(heliDto.getPayType())) {
             PayParamBo tempParam = new PayParamBo();
             BeanUtils.copyProperties(heliDto, tempParam);
-            ResponseJson<PayParamBo> jsonParam = getWeChatResponseJson(tempParam, headers);
+            ResponseJson<PayParamBo> jsonParam = getWeChatResponseJson(tempParam, headers, 1);
             if (-1 == jsonParam.getCode()) {
                 return ResponseJson.error(jsonParam.getMsg(), null);
             }
@@ -277,7 +273,7 @@ public class HeliPayNonOrderServiceImpl implements HeliPayNonOrderService {
         if ("GZH".equals(heliDto.getPayType()) || "XCX".equals(heliDto.getPayType())) {
             PayParamBo tempParam = new PayParamBo();
             BeanUtils.copyProperties(heliDto, tempParam);
-            ResponseJson<PayParamBo> jsonParam = getWeChatResponseJson(tempParam, headers);
+            ResponseJson<PayParamBo> jsonParam = getWeChatResponseJson(tempParam, headers, 5);
             if (-1 == jsonParam.getCode()) {
                 return ResponseJson.error(jsonParam.getMsg(), null);
             }
@@ -340,13 +336,13 @@ public class HeliPayNonOrderServiceImpl implements HeliPayNonOrderService {
      * @param headers  HttpHeaders
      * @return payParam获取微信支付信息
      */
-    private ResponseJson<PayParamBo> getWeChatResponseJson(PayParamBo payParam, HttpHeaders headers) {
+    private ResponseJson<PayParamBo> getWeChatResponseJson(PayParamBo payParam, HttpHeaders headers, Integer mode) {
         // 微信线上支付
         payParam.setPayWay("WEIXIN");
         String openId = null;
         if (null == payParam.getState()) {
             // 小程序微信授权获取登录信息
-            ResponseJson<Map<String, Object>> appletsInfo = weChatService.getInfoMapByApplets(payParam.getCode(), headers, 1);
+            ResponseJson<Map<String, Object>> appletsInfo = weChatService.getInfoMapByApplets(payParam.getCode(), headers, mode);
             if (appletsInfo.getCode() == -1) {
                 return ResponseJson.error(appletsInfo.getMsg(), null);
             }
@@ -538,7 +534,7 @@ public class HeliPayNonOrderServiceImpl implements HeliPayNonOrderService {
         if ("GZH".equals(heliDto.getPayType()) || "XCX".equals(heliDto.getPayType())) {
             PayParamBo tempParam = new PayParamBo();
             BeanUtils.copyProperties(heliDto, tempParam);
-            ResponseJson<PayParamBo> jsonParam = getWeChatResponseJson(tempParam, headers);
+            ResponseJson<PayParamBo> jsonParam = getWeChatResponseJson(tempParam, headers, 1);
             if (-1 == jsonParam.getCode()) {
                 return ResponseJson.error(jsonParam.getMsg(), null);
             }
@@ -1425,7 +1421,7 @@ public class HeliPayNonOrderServiceImpl implements HeliPayNonOrderService {
         if ("GZH".equals(heliDto.getPayType()) || "XCX".equals(heliDto.getPayType())) {
             PayParamBo tempParam = new PayParamBo();
             BeanUtils.copyProperties(heliDto, tempParam);
-            ResponseJson<PayParamBo> jsonParam = getWeChatResponseJson(tempParam, headers);
+            ResponseJson<PayParamBo> jsonParam = getWeChatResponseJson(tempParam, headers, 1);
             if (-1 == jsonParam.getCode()) {
                 return ResponseJson.error(jsonParam.getMsg(), null);
             }