Bladeren bron

fixed 微信卡券对接相关功能迭代

fushengqian 1 jaar geleden
bovenliggende
commit
a0fe497b77

+ 3 - 1
fuint-application/src/main/java/com/fuint/common/enums/YesOrNoEnum.java

@@ -8,7 +8,9 @@ package com.fuint.common.enums;
  */
 public enum YesOrNoEnum {
     YES("Y", "是"),
-    NO("N", "否");
+    NO("N", "否"),
+    TRUE("true", "真"),
+    FALSE("false", "假");
 
     private String key;
 

+ 2 - 1
fuint-application/src/main/java/com/fuint/common/service/WeixinService.java

@@ -23,10 +23,11 @@ public interface WeixinService {
      * 获取微信登录token
      *
      * @param merchantId 商户ID
+     * @param isMinApp 是否小程序
      * @param useCache 是否从缓存中读取
      * @return
      * */
-    String getAccessToken(Integer merchantId, boolean useCache) throws BusinessCheckException;
+    String getAccessToken(Integer merchantId, boolean isMinApp, boolean useCache) throws BusinessCheckException;
 
     /**
      * 提交预支付订单

+ 1 - 1
fuint-application/src/main/java/com/fuint/common/service/impl/MemberServiceImpl.java

@@ -630,7 +630,7 @@ public class MemberServiceImpl extends ServiceImpl<MtUserMapper, MtUser> impleme
         if (StringUtil.isEmpty(mobile) && user == null) {
             MtSetting mtSetting = settingService.querySettingByName(merchantId, UserSettingEnum.LOGIN_NEED_PHONE.getKey());
             if (mtSetting != null) {
-                if (mtSetting.getValue().equals("true")) {
+                if (mtSetting.getValue().equals(YesOrNoEnum.TRUE.getKey())) {
                     MtUser tempUser = new MtUser();
                     tempUser.setOpenId(openId);
                     tempUser.setId(0);

+ 5 - 5
fuint-application/src/main/java/com/fuint/common/service/impl/OrderServiceImpl.java

@@ -686,7 +686,7 @@ public class OrderServiceImpl extends ServiceImpl<MtOrderMapper, MtOrder> implem
         }
 
         MtSetting config = settingService.querySettingByName(merchantId, OrderSettingEnum.IS_CLOSE.getKey());
-        if (config != null && config.getValue().equals("true")) {
+        if (config != null && config.getValue().equals(YesOrNoEnum.TRUE.getKey())) {
             throw new BusinessCheckException("系统已关闭交易功能,请稍后再试!");
         }
 
@@ -747,7 +747,7 @@ public class OrderServiceImpl extends ServiceImpl<MtOrderMapper, MtOrder> implem
 
         MtSetting pointSetting = settingService.querySettingByName(merchantId, PointSettingEnum.CAN_USE_AS_MONEY.getKey());
         // 使用积分数量
-        if (pointSetting != null && pointSetting.getValue().equals("true")) {
+        if (pointSetting != null && pointSetting.getValue().equals(YesOrNoEnum.TRUE.getKey())) {
             orderDto.setUsePoint(usePoint);
         } else {
             orderDto.setUsePoint(0);
@@ -824,7 +824,7 @@ public class OrderServiceImpl extends ServiceImpl<MtOrderMapper, MtOrder> implem
         // 使用积分抵扣
         if (usePoint > 0) {
             List<MtSetting> settingList = settingService.getSettingList(merchantId, SettingTypeEnum.POINT.getKey());
-            String canUsedAsMoney = "false";
+            String canUsedAsMoney = YesOrNoEnum.FALSE.getKey();
             String exchangeNeedPoint = "0";
             for (MtSetting setting : settingList) {
                 if (setting.getName().equals("canUsedAsMoney")) {
@@ -834,7 +834,7 @@ public class OrderServiceImpl extends ServiceImpl<MtOrderMapper, MtOrder> implem
                 }
             }
             // 是否可以使用积分,并且积分数量足够
-            if (canUsedAsMoney.equals("true") && Float.parseFloat(exchangeNeedPoint) > 0 && (userInfo.getPoint() >= usePoint)) {
+            if (canUsedAsMoney.equals(YesOrNoEnum.TRUE.getKey()) && Float.parseFloat(exchangeNeedPoint) > 0 && (userInfo.getPoint() >= usePoint)) {
                 orderDto.setUsePoint(usePoint);
                 orderDto.setPointAmount(new BigDecimal(usePoint).divide(new BigDecimal(exchangeNeedPoint), BigDecimal.ROUND_CEILING, 3));
                 if (orderDto.getPayAmount().compareTo(orderDto.getPointAmount()) > 0) {
@@ -1832,7 +1832,7 @@ public class OrderServiceImpl extends ServiceImpl<MtOrderMapper, MtOrder> implem
 
         // 设置是否不能用积分抵扣
         MtSetting pointSetting = settingService.querySettingByName(merchantId, PointSettingEnum.CAN_USE_AS_MONEY.getKey());
-        if (pointSetting != null && !pointSetting.getValue().equals("true")) {
+        if (pointSetting != null && !pointSetting.getValue().equals(YesOrNoEnum.TRUE.getKey())) {
             isUsePoint = false;
         }
 

+ 15 - 9
fuint-application/src/main/java/com/fuint/common/service/impl/WeixinServiceImpl.java

@@ -108,15 +108,21 @@ public class WeixinServiceImpl implements WeixinService {
      * 获取微信accessToken
      *
      * @param merchantId 商户ID
+     * @param isMinApp 是否小程序
      * @param useCache 是否读取缓存
      * @throws BusinessCheckException
      * @return
      * */
     @Override
-    public String getAccessToken(Integer merchantId, boolean useCache) throws BusinessCheckException {
+    public String getAccessToken(Integer merchantId, boolean isMinApp, boolean useCache) throws BusinessCheckException {
+        String platForm = isMinApp == true ? "minApp" : "mp";
         String wxAppId = env.getProperty("weixin.official.appId");
         String wxAppSecret = env.getProperty("weixin.official.appSecret");
-        String tokenKey = FUINT_ACCESS_TOKEN_PRE;
+        if (isMinApp) {
+            wxAppId = env.getProperty("wxpay.appId");
+            wxAppSecret = env.getProperty("wxpay.appSecret");
+        }
+        String tokenKey = FUINT_ACCESS_TOKEN_PRE + platForm;
         if (merchantId != null && merchantId > 0) {
             MtMerchant mtMerchant = merchantService.queryMerchantById(merchantId);
             if (mtMerchant != null && StringUtil.isNotEmpty(mtMerchant.getWxAppId()) && StringUtil.isNotEmpty(mtMerchant.getWxAppSecret())) {
@@ -518,12 +524,12 @@ 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);
+            String url = "https://api.weixin.qq.com/cgi-bin/message/subscribe/send?access_token=" + getAccessToken(merchantId, true,true);
             String response = HttpRESTDataClient.requestPost(url, "application/json; charset=utf-8", reqDataJsonStr);
             logger.info("WeixinService sendSubscribeMessage response={}", response);
             JSONObject json = (JSONObject) JSONObject.parse(response);
             if (json.get("errcode").toString().equals("40001")) {
-                getAccessToken(merchantId, true);
+                getAccessToken(merchantId, true,true);
                 logger.error("发送订阅消息出错error1:" + json.get("errcode").toString());
                 return false;
             } else if (!json.get("errcode").toString().equals("0")) {
@@ -640,7 +646,7 @@ public class WeixinServiceImpl implements WeixinService {
     @Override
     public String createStoreQrCode(Integer merchantId, Integer storeId, Integer width) {
         try {
-            String accessToken = getAccessToken(merchantId, true);
+            String accessToken = getAccessToken(merchantId, true,true);
             String url = "https://api.weixin.qq.com/cgi-bin/wxaapp/createwxaqrcode?access_token=" + accessToken;
             String reqDataJsonStr = "";
 
@@ -651,7 +657,7 @@ public class WeixinServiceImpl implements WeixinService {
             reqDataJsonStr = JsonUtil.toJSONString(reqData);
 
             byte[] bytes = HttpRESTDataClient.requestPost(url, reqDataJsonStr);
-            logger.info("WechatService createStoreQrCode response success");
+            logger.info("WechatService createStoreQrCode reqData:{}", reqDataJsonStr);
 
             String pathRoot = env.getProperty("images.root");
             String baseImage = env.getProperty("images.path");
@@ -695,7 +701,7 @@ public class WeixinServiceImpl implements WeixinService {
             }
             WxCardDto wxCardDto = JsonUtil.parseObject(mtSetting.getValue(), WxCardDto.class);
 
-            String accessToken = getAccessToken(merchantId, true);
+            String accessToken = getAccessToken(merchantId, false,true);
             String url = "https://api.weixin.qq.com/card/create?access_token=" + accessToken;
 
             Map<String, Object> params = new HashMap<>();
@@ -771,13 +777,13 @@ public class WeixinServiceImpl implements WeixinService {
     @Override
     public String getApiTicket(Integer merchantId) {
         try {
-            String accessToken = getAccessToken(merchantId, true);
+            String accessToken = getAccessToken(merchantId, false,true);
             String url = "https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token=" + accessToken + "&type=wx_card";
             String response = HttpRESTDataClient.requestGet(url);
             logger.error("微信卡券apiTicket接口返回:{}", response);
             JSONObject data = (JSONObject) JSONObject.parse(response);
             if (data.get("errcode").toString().equals("0")) {
-                return data.get("card_id").toString();
+                return data.get("ticket").toString();
             }
         } catch (Exception e) {
             return "";

+ 5 - 4
fuint-application/src/main/java/com/fuint/module/backendApi/controller/BackendMemberController.java

@@ -5,6 +5,7 @@ import com.fuint.common.dto.*;
 import com.fuint.common.enums.SettingTypeEnum;
 import com.fuint.common.enums.StatusEnum;
 import com.fuint.common.enums.UserSettingEnum;
+import com.fuint.common.enums.YesOrNoEnum;
 import com.fuint.common.service.*;
 import com.fuint.common.util.DateUtil;
 import com.fuint.common.util.PhoneFormatCheckUtils;
@@ -388,10 +389,10 @@ public class BackendMemberController extends BaseController {
 
         List<MtSetting> settingList = settingService.getSettingList(accountInfo.getMerchantId(), SettingTypeEnum.USER.getKey());
 
-        String getCouponNeedPhone = "false";
-        String submitOrderNeedPhone = "false";
-        String loginNeedPhone = "false";
-        String openWxCard = "false";
+        String getCouponNeedPhone = YesOrNoEnum.FALSE.getKey();
+        String submitOrderNeedPhone = YesOrNoEnum.FALSE.getKey();
+        String loginNeedPhone = YesOrNoEnum.FALSE.getKey();
+        String openWxCard = YesOrNoEnum.FALSE.getKey();
         WxCardDto wxMemberCard = null;
         for (MtSetting setting : settingList) {
             if (StringUtil.isNotEmpty(setting.getValue())) {

+ 1 - 1
fuint-application/src/main/java/com/fuint/module/backendApi/controller/BackendOrderController.java

@@ -471,7 +471,7 @@ public class BackendOrderController extends BaseController {
     public ResponseObject saveSetting(HttpServletRequest request, @RequestBody Map<String, Object> param) throws BusinessCheckException {
         String token = request.getHeader("Access-Token");
         String deliveryFee = param.get("deliveryFee") != null ? param.get("deliveryFee").toString() : "0";
-        String isClose = param.get("isClose") != null ? param.get("isClose").toString() : "false";
+        String isClose = param.get("isClose") != null ? param.get("isClose").toString() : YesOrNoEnum.FALSE.getKey();
 
         AccountInfo accountInfo = TokenUtil.getAccountInfoByToken(token);
         if (accountInfo == null) {

+ 2 - 1
fuint-application/src/main/java/com/fuint/module/backendApi/controller/BackendPointController.java

@@ -6,6 +6,7 @@ import com.fuint.common.dto.PointDto;
 import com.fuint.common.enums.PointSettingEnum;
 import com.fuint.common.enums.SettingTypeEnum;
 import com.fuint.common.enums.StatusEnum;
+import com.fuint.common.enums.YesOrNoEnum;
 import com.fuint.common.service.MemberService;
 import com.fuint.common.service.PointService;
 import com.fuint.common.service.SettingService;
@@ -180,7 +181,7 @@ public class BackendPointController extends BaseController {
     public ResponseObject saveSetting(HttpServletRequest request, @RequestBody Map<String, Object> param) throws BusinessCheckException {
         String token = request.getHeader("Access-Token");
         String pointNeedConsume = param.get("pointNeedConsume") != null ? param.get("pointNeedConsume").toString() : "1";
-        String canUsedAsMoney = param.get("canUsedAsMoney") != null ? param.get("canUsedAsMoney").toString() : "false";
+        String canUsedAsMoney = param.get("canUsedAsMoney") != null ? param.get("canUsedAsMoney").toString() : YesOrNoEnum.FALSE.getKey();
         String exchangeNeedPoint = param.get("exchangeNeedPoint") != null ? param.get("exchangeNeedPoint").toString() : "0";
         String rechargePointSpeed = param.get("rechargePointSpeed") != null ? param.get("rechargePointSpeed").toString() : "1";
         String status = request.getParameter("status");

+ 1 - 1
fuint-application/src/main/java/com/fuint/module/clientApi/controller/ClientCartController.java

@@ -200,7 +200,7 @@ public class ClientCartController extends BaseController {
         String orderMode = params.getOrderMode() == null ? OrderModeEnum.ONESELF.getKey() : params.getOrderMode();
         Integer merchantId = merchantService.getMerchantId(merchantNo);
         boolean isUsePoint = false;
-        if (point.equals("true")) {
+        if (point.equals(YesOrNoEnum.TRUE.getKey())) {
             isUsePoint = true;
         }
 

+ 3 - 2
fuint-application/src/main/java/com/fuint/module/clientApi/controller/ClientPayController.java

@@ -4,6 +4,7 @@ import com.alipay.api.AlipayApiException;
 import com.fuint.common.dto.*;
 import com.fuint.common.enums.OrderStatusEnum;
 import com.fuint.common.enums.SettingTypeEnum;
+import com.fuint.common.enums.YesOrNoEnum;
 import com.fuint.common.service.*;
 import com.fuint.common.util.TokenUtil;
 import com.fuint.framework.exception.BusinessCheckException;
@@ -106,7 +107,7 @@ public class ClientPayController extends BaseController {
         Map<String, Object> outParams = new HashMap<>();
 
         List<MtSetting> settingList = settingService.getSettingList(mtUser.getMerchantId(), SettingTypeEnum.POINT.getKey());
-        String canUsedAsMoney = "false";
+        String canUsedAsMoney = YesOrNoEnum.FALSE.getKey();
         String exchangeNeedPoint = "0";
         for (MtSetting setting : settingList) {
             if (setting.getName().equals("canUsedAsMoney")) {
@@ -139,7 +140,7 @@ public class ClientPayController extends BaseController {
 
         // 可用积分
         Integer canUsePointAmount = 0;
-        if (mtUser != null && canUsedAsMoney.equals("true")) {
+        if (mtUser != null && canUsedAsMoney.equals(YesOrNoEnum.TRUE.getKey())) {
             canUsePointAmount = mtUser.getPoint();
         }
 

+ 4 - 3
fuint-application/src/main/java/com/fuint/module/clientApi/controller/ClientSignController.java

@@ -6,6 +6,7 @@ import com.fuint.common.dto.UserInfo;
 import com.fuint.common.enums.GenderEnum;
 import com.fuint.common.enums.MemberSourceEnum;
 import com.fuint.common.enums.StatusEnum;
+import com.fuint.common.enums.YesOrNoEnum;
 import com.fuint.common.service.*;
 import com.fuint.common.util.TokenUtil;
 import com.fuint.framework.exception.BusinessCheckException;
@@ -270,7 +271,7 @@ public class ClientSignController extends BaseController {
         if (StringUtil.isNotEmpty(mobile) && StringUtil.isNotEmpty(verifyCode)) {
             // 如果已经登录,免输入验证码
             if (StringUtil.isNotEmpty(token) && TokenUtil.checkTokenLogin(token)) {
-                dto.setIsLogin("true");
+                dto.setIsLogin(YesOrNoEnum.TRUE.getKey());
                 dto.setToken(token);
                 return getSuccessResult(JSONObject.toJSONString(dto));
             }
@@ -303,11 +304,11 @@ public class ClientSignController extends BaseController {
                 loginInfo.setToken(userToken);
                 TokenUtil.saveToken(loginInfo);
 
-                dto.setIsLogin("true");
+                dto.setIsLogin(YesOrNoEnum.TRUE.getKey());
                 dto.setToken(userToken);
                 dto.setTokenCreatedTime(System.currentTimeMillis());
             } else {
-                dto.setIsLogin("false");
+                dto.setIsLogin(YesOrNoEnum.FALSE.getKey());
                 return getFailureResult(201, "验证码错误或已过期,登录失败");
             }
         }

+ 8 - 7
fuint-application/src/main/java/com/fuint/module/clientApi/controller/ClientUserController.java

@@ -13,6 +13,7 @@ import com.fuint.framework.web.BaseController;
 import com.fuint.framework.web.ResponseObject;
 import com.fuint.repository.model.*;
 import com.fuint.utils.Digests;
+import com.fuint.utils.Encodes;
 import com.fuint.utils.StringUtil;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
@@ -150,7 +151,7 @@ public class ClientUserController extends BaseController {
         // 是否开通微信会员卡
         if (StringUtil.isNotEmpty(mtUser.getOpenId())) {
             MtSetting cardSetting = settingService.querySettingByName(mtUser.getMerchantId(), UserSettingEnum.OPEN_WX_CARD.getKey());
-            if (cardSetting != null && cardSetting.getValue().equals(YesOrNoEnum.YES.getKey())) {
+            if (cardSetting != null && cardSetting.getValue().equals(YesOrNoEnum.TRUE.getKey())) {
                 MtSetting cardIdSetting = settingService.querySettingByName(mtUser.getMerchantId(), UserSettingEnum.WX_MEMBER_CARD_ID.getKey());
                 if (cardIdSetting != null) {
                     String apiTicket = weixinService.getApiTicket(mtUser.getMerchantId());
@@ -158,23 +159,23 @@ public class ClientUserController extends BaseController {
                         String cardId = cardIdSetting.getValue();
                         String openId = mtUser.getOpenId();
                         String code = mtUser.getUserNo();
-                        String timestamp = System.currentTimeMillis() + "";
-                        String nonce_str = CommonUtil.createAccountKey();
-                        String str = nonce_str + timestamp + code + apiTicket + cardId;
-                        String signature = Digests.sha1(str.getBytes()).toString();
-
+                        String timestamp = (System.currentTimeMillis()/1000) + "";
+                        String nonceStr = "WeApp";
+                        String str = nonceStr + timestamp + apiTicket + cardId;
+                        byte[] signatureByte = Digests.sha1(str.getBytes());
+                        String signature = Encodes.encodeHex(signatureByte);
                         OpenWxCardDto openWxCardDto = new OpenWxCardDto();
                         openWxCardDto.setCode(code);
                         openWxCardDto.setOpenId(openId);
                         openWxCardDto.setTimestamp(timestamp);
                         openWxCardDto.setSignature(signature);
                         openWxCardDto.setCardId(cardId);
+                        openWxCardDto.setNonceStr(nonceStr);
                         outParams.put("openCardPara", openWxCardDto);
                     }
                 }
             }
         }
-
         return getSuccessResult(outParams);
     }