diff --git a/mallinkAdmin/src/main/java/com/iformall/controller/basic/WxProjectConfigController.java b/mallinkAdmin/src/main/java/com/iformall/controller/basic/WxProjectConfigController.java index 4ac381cb1..dca5729a7 100644 --- a/mallinkAdmin/src/main/java/com/iformall/controller/basic/WxProjectConfigController.java +++ b/mallinkAdmin/src/main/java/com/iformall/controller/basic/WxProjectConfigController.java @@ -367,7 +367,8 @@ public class WxProjectConfigController extends BaseController { if(byId == null){ return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(),"未找到小程序"); } - if(!EnumAppType.B.getCode().equals(byId.getType()) && !EnumAppType.C.getCode().equals(byId.getType())){ + if(!EnumAppType.B.getCode().equals(byId.getType()) + && !EnumAppType.C.getCode().equals(byId.getType())){ return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(),"小程序类型不支持"); } if(wxAppinfo.getEnable() == null || @@ -799,14 +800,15 @@ public class WxProjectConfigController extends BaseController { @GetMapping("/ttcallback/query/settings") @SystemControllerLog(description = "") @TenantIgnore - public ResultData ttcallbackQuerySettings(String appid) { + public ResultData ttcallbackQuerySettings(String tenantId,String appid) { logger.debug("[" + getIpAddr() + "] WxProjectConfigController::ttcallbackQuerySettings"); try { - WxAppinfo appinfo = wxAppinfoService.getByAppId(appid); + WxAppinfo appinfo = wxAppinfoService.getByAppId(appid,tenantId); if(appinfo == null){ return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(),"未找到对应的小程序"); } - if(!EnumAppPlat.TOUTIAO.getCode().equals(appinfo.getPlat()) || !EnumAppType.C.getCode().equals(appinfo.getType())){ + if(!EnumAppPlat.TOUTIAO.getCode().equals(appinfo.getPlat()) + || !EnumAppType.C.getCode().equals(appinfo.getType())){ return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(),"该小程序不支持"); } WxPayAccount payAccount = wxPayAccountService.getById(appinfo.getPayId()); @@ -829,6 +831,7 @@ public class WxProjectConfigController extends BaseController { public ResultData ttcallbackSettings(@RequestBody Map map) { logger.debug("[" + getIpAddr() + "] WxProjectConfigController::ttcallbackSettings"); String appid = map.get("appid"); + String tenantId = map.get("tenantId"); String create_order_callback = map.get("createOrderCallback"); String refund_callback = map.get("refundCallback"); String delivery_qrcode_redirect = map.get("deliveryQrcodeRedirect"); @@ -837,11 +840,12 @@ public class WxProjectConfigController extends BaseController { return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL); } try { - WxAppinfo appinfo = wxAppinfoService.getByAppId(appid); + WxAppinfo appinfo = wxAppinfoService.getByAppId(appid,tenantId); if(appinfo == null){ return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(),"未找到对应的小程序"); } - if(!EnumAppPlat.TOUTIAO.getCode().equals(appinfo.getPlat()) || !EnumAppType.C.getCode().equals(appinfo.getType())){ + if(!EnumAppPlat.TOUTIAO.getCode().equals(appinfo.getPlat()) + || !EnumAppType.C.getCode().equals(appinfo.getType())){ return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(),"该小程序不支持"); } WxPayAccount payAccount = wxPayAccountService.getById(appinfo.getPayId()); diff --git a/mallinkAdmin/src/main/resources/db/migration/V2022112200001__update_brand.sql b/mallinkAdmin/src/main/resources/db/migration/V2022112200001__update_brand.sql index 591f32362..582a07e34 100644 --- a/mallinkAdmin/src/main/resources/db/migration/V2022112200001__update_brand.sql +++ b/mallinkAdmin/src/main/resources/db/migration/V2022112200001__update_brand.sql @@ -1,4 +1,11 @@ --历史品牌数据 UPDATE `mallink`.`wx_brand` SET `tenant_id` = `parent_tenant_id` WHERE `parent_tenant_id` is not null and `parent_tenant_id` != ''; -UPDATE `mallink`.`wx_brand` SET `parent_tenant_id` = null; \ No newline at end of file +UPDATE `mallink`.`wx_brand` SET `parent_tenant_id` = null; + + + +--appinfo +ALTER TABLE `mallink`.`wx_appinfo` +DROP INDEX `appid_index`, +ADD INDEX `appid_index`(`app_id`, `tenant_id`) USING BTREE; \ No newline at end of file diff --git a/mallinkBApi/src/main/java/com/iformall/controller/BaseController.java b/mallinkBApi/src/main/java/com/iformall/controller/BaseController.java index 177b86c8d..5b0afe02f 100644 --- a/mallinkBApi/src/main/java/com/iformall/controller/BaseController.java +++ b/mallinkBApi/src/main/java/com/iformall/controller/BaseController.java @@ -168,6 +168,10 @@ public class BaseController { return wxAppinfoService.getByAppId(appId); } + public WxAppinfo getAppInfo(String appId,String tenantId) { + return wxAppinfoService.getByAppId(appId,tenantId); + } + public String getIpAddr() { HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest(); String ipaddress = IPUtil.getIpAddr(request); diff --git a/mallinkBApi/src/main/java/com/iformall/controller/WxInfoController.java b/mallinkBApi/src/main/java/com/iformall/controller/WxInfoController.java index cf534d0c2..c682d452b 100644 --- a/mallinkBApi/src/main/java/com/iformall/controller/WxInfoController.java +++ b/mallinkBApi/src/main/java/com/iformall/controller/WxInfoController.java @@ -446,7 +446,7 @@ public class WxInfoController extends BaseController { CUser user = getCUser(); if (user != null) { - WxAppinfo wxAppinfo = wxAppinfoService.getByAppId(user.getAppId()); + WxAppinfo wxAppinfo = getAppInfo(user.getAppId()); if(wxAppinfo == null){ return new ResultData(ErrorCode.APP_ID_NOT_FOUND); } diff --git a/mallinkBApi/src/main/java/com/iformall/controller/WxMallController.java b/mallinkBApi/src/main/java/com/iformall/controller/WxMallController.java index e9da433f9..7cdf0c0da 100644 --- a/mallinkBApi/src/main/java/com/iformall/controller/WxMallController.java +++ b/mallinkBApi/src/main/java/com/iformall/controller/WxMallController.java @@ -51,7 +51,7 @@ public class WxMallController extends BaseController { @GetMapping("/getAppIcon") @ApiImplicitParam(name = "appId", value = "appId", dataType = "String", paramType = "query", required = true) public ResultData getAppIcon(String appId) { - WxAppinfo appInfo = wxAppinfoService.getByAppId(appId); + WxAppinfo appInfo = getAppInfo(appId); if (appInfo == null) { return new ResultData(ErrorCode.APP_ID_NOT_FOUND); } diff --git a/mallinkBApi/src/main/java/com/iformall/controller/WxMerchantBUserController.java b/mallinkBApi/src/main/java/com/iformall/controller/WxMerchantBUserController.java index 118f11fad..168333504 100644 --- a/mallinkBApi/src/main/java/com/iformall/controller/WxMerchantBUserController.java +++ b/mallinkBApi/src/main/java/com/iformall/controller/WxMerchantBUserController.java @@ -149,7 +149,7 @@ public class WxMerchantBUserController extends BaseController { if (StringUtils.isNotBlank(latitude) && StringUtils.isNotBlank(longitude)) { logger.info("B端用户: " + phone + " 登录 IP" + ipaddress + ", 经纬度(" + longitude + "," + latitude + ")"); } - WxAppinfo wxAppinfo = wxAppinfoService.getByAppId(appId); + WxAppinfo wxAppinfo = getAppInfo(appId); if(wxAppinfo == null){ return new ResultData(ErrorCode.APP_ID_NOT_FOUND); } @@ -306,8 +306,7 @@ public class WxMerchantBUserController extends BaseController { if (StringUtils.isBlank(pwd)) { return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "密码不能为空"); } - - return wxMerchantBUserService.updatePwd(appId, phone, code, pwd); + return wxMerchantBUserService.updatePwd(getTenantInfo(), phone, code, pwd); } } diff --git a/mallinkBApi/src/main/java/com/iformall/controller/WxMicroPayController.java b/mallinkBApi/src/main/java/com/iformall/controller/WxMicroPayController.java index 8edc2fe6a..8edc30d11 100644 --- a/mallinkBApi/src/main/java/com/iformall/controller/WxMicroPayController.java +++ b/mallinkBApi/src/main/java/com/iformall/controller/WxMicroPayController.java @@ -299,7 +299,7 @@ public class WxMicroPayController extends BaseController { } WxMerchantBUser bUser = getLoginBUser(); - WxAppinfo appinfo = getAppInfo(bUser.getAppId()); + WxAppinfo appinfo = getAppInfo(bUser.getAppId(),bUser.getTenantId()); try { ResultData rd = wxRefundOrderService.createRefundOrderFromMicroPay(appinfo, orderId, EnumPayType.PAY_B_REFUND, bUser.getId()); return rd; diff --git a/mallinkBApi/src/main/java/com/iformall/controller/WxPayAccountController.java b/mallinkBApi/src/main/java/com/iformall/controller/WxPayAccountController.java index 00f545be3..9c21004d0 100644 --- a/mallinkBApi/src/main/java/com/iformall/controller/WxPayAccountController.java +++ b/mallinkBApi/src/main/java/com/iformall/controller/WxPayAccountController.java @@ -40,11 +40,12 @@ public class WxPayAccountController extends BaseController { public ResultData getPayAccount(@RequestBody Map paramMap) { logger.info("/api/payAccount/getPayAccount" + paramMap.toString()); String appId = paramMap.get("appId"); - if (StringUtils.isBlank(appId)) { - return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "appId不能为空"); + String tenantId = paramMap.get("tenantId"); + if (StringUtils.isBlank(appId) || StringUtils.isBlank(tenantId)) { + return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL); } - WxAppinfo wxAppinfo = getAppInfo(appId); + WxAppinfo wxAppinfo = getAppInfo(appId,tenantId); if(wxAppinfo == null){ return new ResultData(ErrorCode.APP_ID_NOT_FOUND); } diff --git a/mallinkBApi/src/main/java/com/iformall/controller/WxPayBillController.java b/mallinkBApi/src/main/java/com/iformall/controller/WxPayBillController.java index c6d306f05..70735cb63 100644 --- a/mallinkBApi/src/main/java/com/iformall/controller/WxPayBillController.java +++ b/mallinkBApi/src/main/java/com/iformall/controller/WxPayBillController.java @@ -103,7 +103,7 @@ public class WxPayBillController extends BaseController { //openid String openid = paramMap.get("openId"); //获取小程序配置信息 - WxAppinfo appInfo = getAppInfo(appid); + WxAppinfo appInfo = getAppInfo(appid,getTenantInfo().getTenantId()); //支付账单参数 WxPayBill record = new WxPayBill(); record.setBillId(billId); diff --git a/mallinkCApi/src/main/java/com/iformall/controller/BaseController.java b/mallinkCApi/src/main/java/com/iformall/controller/BaseController.java index f50a926e4..55664bcd5 100644 --- a/mallinkCApi/src/main/java/com/iformall/controller/BaseController.java +++ b/mallinkCApi/src/main/java/com/iformall/controller/BaseController.java @@ -1,6 +1,7 @@ package com.iformall.controller; import cn.binarywang.wx.miniapp.api.WxMaService; +import com.alibaba.fastjson.JSONObject; import com.iformall.common.ErrorCode; import com.iformall.common.IdWorker; import com.iformall.common.ResultData; @@ -38,6 +39,7 @@ import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; import java.util.List; +import java.util.Map; @RestController public class BaseController { @@ -243,10 +245,6 @@ public class BaseController { RedisCacheUtils.removeCache(objectCommonRedisTemplate, shortKey); } - public WxAppinfo getAppInfo(String appId) { - return wxAppinfoService.getByAppIdFromRedis(appId); - } - public WxMaService getWeappService(String appId) { if(isFmOpen) { return openService.getWxOpenComponentService().getWxMaServiceByAppid(appId); @@ -275,5 +273,23 @@ public class BaseController { return ipaddress; } + /** + * 根据扩展字段获取tenantId + */ + public String getTenantId(String attach){ + if(StringUtils.isNotBlank(attach)){ + try{ + Map map = JSONObject.parseObject(attach, Map.class); + String tenantId = map.get("tenantId").toString(); + if(StringUtils.isNotBlank(tenantId)){ + return tenantId; + } + }catch (Exception e){ + + } + } + return null; + } + } diff --git a/mallinkCApi/src/main/java/com/iformall/controller/WxCuserFloatingLayerController.java b/mallinkCApi/src/main/java/com/iformall/controller/WxCuserFloatingLayerController.java index 290d5349c..2a88f7d89 100755 --- a/mallinkCApi/src/main/java/com/iformall/controller/WxCuserFloatingLayerController.java +++ b/mallinkCApi/src/main/java/com/iformall/controller/WxCuserFloatingLayerController.java @@ -30,14 +30,13 @@ public class WxCuserFloatingLayerController extends BaseController { @Autowired WxCuserFloatingLayerService wxCuserFloatingLayerService; - @AuthIgnore @ApiOperation("获取浮层") @GetMapping("/getFloatingLayer") @ApiImplicitParams({ @ApiImplicitParam(name = "openId", value = "openId", dataType = "String", paramType = "query", required = true), @ApiImplicitParam(name = "appId", value = "appId", dataType = "String", paramType = "query", required = true)}) - public ResultData getAppIcon(String openId, String appId) { - WxFloatingLayer wxFloatingLayer = wxCuserFloatingLayerService.getFloatingLayer(openId, appId); + public ResultData getAppIcon(String openId) { + WxFloatingLayer wxFloatingLayer = wxCuserFloatingLayerService.getFloatingLayer(getTenantInfo(),openId); return new ResultData(Result.SUCCESS, "查询成功", wxFloatingLayer); } diff --git a/mallinkCApi/src/main/java/com/iformall/controller/WxOrderController.java b/mallinkCApi/src/main/java/com/iformall/controller/WxOrderController.java index 04e579b20..5d84c9747 100644 --- a/mallinkCApi/src/main/java/com/iformall/controller/WxOrderController.java +++ b/mallinkCApi/src/main/java/com/iformall/controller/WxOrderController.java @@ -187,6 +187,7 @@ public class WxOrderController extends BaseController { String open_id = msgObject.getString("open_id"); //透传字段 Long composeOrderId = null; + String tenantId = null; try{ String cp_extra = msgObject.getString("cp_extra"); if(StringUtils.isBlank(cp_extra)){ @@ -197,16 +198,17 @@ public class WxOrderController extends BaseController { Map couponMap = JSONObject.parseObject(cp_extra, Map.class); String idstr = couponMap.get("composeOrderId"); composeOrderId = Long.parseLong(idstr); + tenantId = couponMap.get("tenantId"); }catch(Exception e){ } - if(composeOrderId == null){ + if(composeOrderId == null || StringUtils.isBlank(tenantId)){ map.put("err_no",ErrorCode.SYS_PARAMETER_NOT_NULL.getCode()); map.put("err_tips","透传字段格式不正确"); return map; } //验证app - WxAppinfo appinfo = wxAppinfoService.getByAppIdFromRedis(app_id); + WxAppinfo appinfo = wxAppinfoService.getByAppIdFromRedis(app_id,tenantId); if(appinfo == null || !EnumAppPlat.TOUTIAO.getCode().equals(appinfo.getPlat()) || !EnumAppType.C.getCode().equals(appinfo.getType())){ map.put("err_no",ErrorCode.APP_ID_NOT_FOUND.getCode()); @@ -752,9 +754,10 @@ public class WxOrderController extends BaseController { JSONObject msgObject = JSONObject.parseObject(msg); String app_id = msgObject.getString("app_id"); String open_id = msgObject.getString("open_id"); + String cp_extra = msgObject.getString("cp_extra"); //验证app - WxAppinfo appinfo = wxAppinfoService.getByAppId(app_id); + WxAppinfo appinfo = wxAppinfoService.getByAppId(app_id,getTenantId(cp_extra)); if(appinfo == null || !EnumAppPlat.TOUTIAO.getCode().equals(appinfo.getPlat()) || !EnumAppType.C.getCode().equals(appinfo.getType())){ map.put("err_no",ErrorCode.APP_ID_NOT_FOUND.getCode()); diff --git a/mallinkCApi/src/main/java/com/iformall/controller/WxPayOrderController.java b/mallinkCApi/src/main/java/com/iformall/controller/WxPayOrderController.java index 8ae49592a..97ff599b0 100644 --- a/mallinkCApi/src/main/java/com/iformall/controller/WxPayOrderController.java +++ b/mallinkCApi/src/main/java/com/iformall/controller/WxPayOrderController.java @@ -113,7 +113,7 @@ public class WxPayOrderController extends BaseController { if (null != wxCUserBasicInfo && EnumCreditLockedStatus.CLOSE.getCode().equals(wxCUserBasicInfo.getStatus())) { return new ResultData(ErrorCode.MEMBER_IS_LOCKED); } - WxAppinfo appInfo = getAppInfo(appId); + WxAppinfo appInfo = wxAppinfoService.getByAppIdFromRedis(appId,getTenantInfo().getTenantId()); if(appInfo == null) { return new ResultData(ErrorCode.APP_ID_NOT_FOUND); } diff --git a/mallinkCallback/src/main/java/com/iformall/controller/base/BaseController.java b/mallinkCallback/src/main/java/com/iformall/controller/base/BaseController.java index 757299519..a1dfca5fb 100644 --- a/mallinkCallback/src/main/java/com/iformall/controller/base/BaseController.java +++ b/mallinkCallback/src/main/java/com/iformall/controller/base/BaseController.java @@ -1,7 +1,9 @@ package com.iformall.controller.base; +import com.alibaba.fastjson.JSONObject; import com.iformall.domain.po.base.TenantEntity; import com.iformall.utils.IPUtil; +import org.apache.commons.lang3.StringUtils; import org.springframework.web.bind.WebDataBinder; import org.springframework.web.bind.annotation.InitBinder; import org.springframework.web.bind.annotation.RestController; @@ -13,6 +15,7 @@ import java.beans.PropertyEditorSupport; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; +import java.util.Map; @RestController public class BaseController { @@ -44,4 +47,22 @@ public class BaseController { String ipaddress = IPUtil.getIpAddr(request); return ipaddress; } + + /** + * 根据扩展字段获取tenantId + */ + public String getTenantId(String attach){ + if(StringUtils.isNotBlank(attach)){ + try{ + Map map = JSONObject.parseObject(attach, Map.class); + String tenantId = map.get("tenantId").toString(); + if(StringUtils.isNotBlank(tenantId)){ + return tenantId; + } + }catch (Exception e){ + + } + } + return null; + } } diff --git a/mallinkCallback/src/main/java/com/iformall/controller/callback/TtPayController.java b/mallinkCallback/src/main/java/com/iformall/controller/callback/TtPayController.java index c4f38faba..6ede014bf 100644 --- a/mallinkCallback/src/main/java/com/iformall/controller/callback/TtPayController.java +++ b/mallinkCallback/src/main/java/com/iformall/controller/callback/TtPayController.java @@ -100,6 +100,7 @@ public class TtPayController extends BaseController { Map pMap = JSONObject.parseObject(msg, Map.class); String appid; + String tenantId; WxAppinfo appinfo; WxPayAccount payAccount; Boolean is2_0 = false; @@ -111,7 +112,9 @@ public class TtPayController extends BaseController { String nonce = request.getHeader("Byte-Nonce-Str"); appid = (String) pMap.get("app_id"); - appinfo = appinfoService.getByAppId(appid); + String cp_extra = (String) pMap.get("cp_extra"); + tenantId = getTenantId(cp_extra); + appinfo = appinfoService.getByAppId(appid,tenantId); payAccount = payAccountService.getById(appinfo.getPayId()); TtPayService ttPayService = maUtil.getTtPayService(appinfo, payAccount); @@ -134,7 +137,9 @@ public class TtPayController extends BaseController { String nonce = (String) parameterMap.get("nonce"); appid = (String) pMap.get("appid"); - appinfo = appinfoService.getByAppId(appid); + String cp_extra = (String) pMap.get("cp_extra"); + tenantId = getTenantId(cp_extra); + appinfo = appinfoService.getByAppId(appid,tenantId); payAccount = payAccountService.getById(appinfo.getPayId()); Map paramMap = new HashMap<>(); @@ -207,6 +212,7 @@ public class TtPayController extends BaseController { } Map map = new HashMap<>(); + map.put("tenantId",tenantId); map.put("appid",appid); map.put("cp_refundno",cp_refundno); map.put("status",status); @@ -216,6 +222,7 @@ public class TtPayController extends BaseController { String jsonMsg = JSON.toJSONString(map); FmInsideNotifyRefundSuccessMsg refundSuccessMsg = new FmInsideNotifyRefundSuccessMsg(); + refundSuccessMsg.setTenantId(tenantId); refundSuccessMsg.setMsgType(EnumMsgRecordType.INSIDE_NOTIFY_REFUND_SUCCESS.getCode()); refundSuccessMsg.setDelayTimeLevel(3); refundSuccessMsg.setPayWay(EnumPayWay.PAY_WAY_TT.getCode()); diff --git a/mallinkCallback/src/main/java/com/iformall/controller/callback/TtWebController.java b/mallinkCallback/src/main/java/com/iformall/controller/callback/TtWebController.java index 7f0c413d8..c5056a84b 100644 --- a/mallinkCallback/src/main/java/com/iformall/controller/callback/TtWebController.java +++ b/mallinkCallback/src/main/java/com/iformall/controller/callback/TtWebController.java @@ -109,7 +109,7 @@ public class TtWebController extends BaseController { // String status = (String) content.get("status"); TtCouponChannelPoi couponChannelPoi = new TtCouponChannelPoi(); - couponChannelPoi.updateTenantInfo(appInfo); +// couponChannelPoi.updateTenantInfo(appInfo); couponChannelPoi.setSpuId(product_id); if("FAIL".equals(status)){ couponChannelPoi.setLastStatus(EnumSpuSyncStatus.sync_audit_rejection.getCode()); diff --git a/mallinkCallback/src/main/java/com/iformall/controller/callback/WxPayBillController.java b/mallinkCallback/src/main/java/com/iformall/controller/callback/WxPayBillController.java index 0985dc963..8ed3504f5 100644 --- a/mallinkCallback/src/main/java/com/iformall/controller/callback/WxPayBillController.java +++ b/mallinkCallback/src/main/java/com/iformall/controller/callback/WxPayBillController.java @@ -1,13 +1,16 @@ package com.iformall.controller.callback; +import com.alibaba.fastjson.JSON; import com.iformall.controller.base.BaseController; import com.iformall.enums.EnumPayVersion; import com.iformall.enums.EnumPayWay; import com.iformall.exception.BizMessageException; import com.iformall.exception.MallinkException; import com.iformall.pay.WxPayment; +import com.iformall.service.MailService; import com.iformall.service.WxPayBillService; import com.iformall.service.WxRefundOrderService; +import com.iformall.utils.DateUtils; import com.iformall.utils.XmlUtil; import org.apache.commons.io.IOUtils; import org.jdom2.JDOMException; @@ -24,6 +27,7 @@ import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; import java.nio.charset.Charset; +import java.util.Date; import java.util.Map; import java.util.SortedMap; import java.util.TreeMap; @@ -37,6 +41,12 @@ public class WxPayBillController extends BaseController { private final Logger logger = LoggerFactory.getLogger(this.getClass()); + @Autowired + private String fmExceptionEmails; + + @Autowired + private MailService mailService; + @Autowired private WxPayBillService wxPayBillService; @@ -69,7 +79,8 @@ public class WxPayBillController extends BaseController { try { paramMap = WxPayment.xmlToMap(resultxml); logger.info("微信支付回调, notify, param: " + paramMap.toString() ); - String response = wxPayBillService.notify(paramMap, EnumPayWay.PAY_WAY_WECHAT); + String attach = paramMap.get("attach"); + String response = wxPayBillService.notify(getTenantId(attach),paramMap, EnumPayWay.PAY_WAY_WECHAT); logger.info("微信支付回调, notify success, req : " + resultxml + ", resp: " + response.toString()); return response; } catch (BizMessageException e) { @@ -121,6 +132,7 @@ public class WxPayBillController extends BaseController { xml = IOUtils.toString(request.getInputStream(), Charset.forName("UTF-8")); logger.info(xml); paramMap = WxPayment.xmlToMap(xml); + response = wxRefundOrderService.notify(paramMap, EnumPayWay.PAY_WAY_WECHAT,EnumPayVersion.WX_PAY_V2); logger.info("refund wxpay, notify success, req : " + xml + ", resp: " + response.toString()); return response; @@ -160,7 +172,17 @@ public class WxPayBillController extends BaseController { xml = IOUtils.toString(request.getInputStream(), Charset.forName("UTF-8")); paramMap = WxPayment.xmlToMap(xml); logger.info("share wxpay, notify, param: " + xml ); - response = wxPayBillService.notify(paramMap, EnumPayWay.PAY_WAY_WECHAT); + //发邮件 + String[] receivers = fmExceptionEmails.split(","); + StringBuilder sb = new StringBuilder(); + sb.append(DateUtils.date2String(new Date())); + sb.append("\n"); + sb.append("分账回调 :WxPayBillController"); + sb.append("\n"); + sb.append(JSON.toJSONString(paramMap)); + //发送邮件 + mailService.sendSimpleMail(receivers, "排查回调位置", sb.toString()); +// response = wxPayBillService.notify(paramMap, EnumPayWay.PAY_WAY_WECHAT); logger.info("share wxpay, notify success, req : " + xml + ", resp: " + response.toString()); return response; } catch (BizMessageException e) { diff --git a/mallinkCallback/src/main/java/com/iformall/controller/callback/WxPayController.java b/mallinkCallback/src/main/java/com/iformall/controller/callback/WxPayController.java index 192324f34..060905998 100644 --- a/mallinkCallback/src/main/java/com/iformall/controller/callback/WxPayController.java +++ b/mallinkCallback/src/main/java/com/iformall/controller/callback/WxPayController.java @@ -10,9 +10,11 @@ import com.iformall.exception.BizMessageException; import com.iformall.exception.MallinkException; import com.iformall.mq.MqBaseProducer; import com.iformall.pay.WxPayment; +import com.iformall.service.MailService; import com.iformall.service.WxPayOrderService; import com.iformall.service.WxRefundOrderService; import com.iformall.service.WxSubsidyService; +import com.iformall.utils.DateUtils; import com.iformall.utils.XmlUtil; import org.apache.commons.io.IOUtils; import org.jdom2.JDOMException; @@ -32,10 +34,7 @@ import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; import java.nio.charset.Charset; -import java.util.HashMap; -import java.util.Map; -import java.util.SortedMap; -import java.util.TreeMap; +import java.util.*; @RestController @RequestMapping("/wxPay/notify") @@ -51,14 +50,20 @@ public class WxPayController extends BaseController { @Autowired private MqBaseProducer mqBaseProducer; + + @Autowired + private String fmExceptionEmails; + + @Autowired + private MailService mailService; /** * * @return 接收微信异步通知 * @throws Exception 可能产生的任何异常 */ - @RequestMapping(value = "/pay", produces = MediaType.APPLICATION_JSON_UTF8_VALUE) + @RequestMapping(value = "/pay/{tenantId}", produces = MediaType.APPLICATION_JSON_UTF8_VALUE) @ResponseBody - public String _payNotify(HttpServletRequest request) throws IOException, JDOMException { + public String _payNotify(@PathVariable String tenantId,HttpServletRequest request) throws IOException, JDOMException { logger.info("[" +getIpAddr() + "]微信支付回调"); SortedMap resultMap = new TreeMap(); resultMap.put("return_code", "SUCCESS"); @@ -139,8 +144,8 @@ public class WxPayController extends BaseController { * @return 接收微信退款异步通知 * @throws Exception 可能产生的任何异常 */ - @RequestMapping(value = "/refund") - public String __refundNotify(HttpServletRequest request) throws Exception { + @RequestMapping(value = "/refund/{tenantId}") + public String __refundNotify(@PathVariable String tenantId,HttpServletRequest request) throws Exception { logger.info("[" +getIpAddr() + "]微信退款回调"); Map paramMap = null; String response = ""; @@ -152,6 +157,7 @@ public class WxPayController extends BaseController { String jsonMsg = JSON.toJSONString(paramMap); FmInsideNotifyRefundSuccessMsg refundSuccessMsg = new FmInsideNotifyRefundSuccessMsg(); + refundSuccessMsg.setTenantId(tenantId); refundSuccessMsg.setMsgType(EnumMsgRecordType.INSIDE_NOTIFY_REFUND_SUCCESS.getCode()); refundSuccessMsg.setDelayTimeLevel(3); refundSuccessMsg.setPayWay(EnumPayWay.PAY_WAY_WECHAT.getCode()); @@ -216,6 +222,7 @@ public class WxPayController extends BaseController { String jsonMsg = JSON.toJSONString(paramMap); FmInsideNotifyRefundSuccessMsg refundSuccessMsg = new FmInsideNotifyRefundSuccessMsg(); + refundSuccessMsg.setTenantId(tenantId); refundSuccessMsg.setMsgType(EnumMsgRecordType.INSIDE_NOTIFY_REFUND_SUCCESS.getCode()); refundSuccessMsg.setDelayTimeLevel(3); refundSuccessMsg.setPayWay(EnumPayWay.PAY_WAY_WECHAT.getCode()); @@ -262,8 +269,18 @@ public class WxPayController extends BaseController { try { xml = IOUtils.toString(request.getInputStream(), Charset.forName("UTF-8")); paramMap = WxPayment.xmlToMap(xml); + //发邮件 + String[] receivers = fmExceptionEmails.split(","); + StringBuilder sb = new StringBuilder(); + sb.append(DateUtils.date2String(new Date())); + sb.append("\n"); + sb.append("分账回调 WxPayController:"); + sb.append("\n"); + sb.append(JSON.toJSONString(paramMap)); + //发送邮件 + mailService.sendSimpleMail(receivers, "排查回调位置", sb.toString()); logger.info("share wxpay, notify, param: " + xml ); - response = wxPayOrderService.shareNotify(paramMap, EnumPayWay.PAY_WAY_WECHAT,EnumPayVersion.WX_PAY_V2); +// response = wxPayOrderService.shareNotify(paramMap, EnumPayWay.PAY_WAY_WECHAT,EnumPayVersion.WX_PAY_V2); logger.info("share wxpay, notify success, req : " + xml + ", resp: " + response.toString()); return response; } catch (BizMessageException e) { diff --git a/mallinkPosApi/src/main/java/com/iformall/controller/BaseController.java b/mallinkPosApi/src/main/java/com/iformall/controller/BaseController.java index 9de3e25f0..018a5b523 100644 --- a/mallinkPosApi/src/main/java/com/iformall/controller/BaseController.java +++ b/mallinkPosApi/src/main/java/com/iformall/controller/BaseController.java @@ -56,28 +56,6 @@ public class BaseController { }); } - public WxAppinfo getAppInfo(String appId) { - return wxAppinfoService.getByAppId(appId); - } - - public WxMaService getWeappService(String appId) { - if(isFmOpen) { - return openService.getWxOpenComponentService().getWxMaServiceByAppid(appId); - } else { - WxAppinfo appinfo = wxAppinfoService.getByAppId(appId); - WxMaService service = maUtil.getWeappService(appinfo); - return service; - } - } - - public WxMaService getWeappServiceByAppInfo(WxAppinfo appinfo) { - if(!isFmOpen) { - WxMaService service = maUtil.getWeappService(appinfo); - return service; - } - return null; - } - public String getIpAddr() { HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest(); String ipaddress = IPUtil.getIpAddr(request); diff --git a/mallinkSchedule/src/main/java/com/iformall/schedule/WeChatAccessTokenSchedule.java b/mallinkSchedule/src/main/java/com/iformall/schedule/WeChatAccessTokenSchedule.java index a8ab2ceb4..7f8317e2a 100644 --- a/mallinkSchedule/src/main/java/com/iformall/schedule/WeChatAccessTokenSchedule.java +++ b/mallinkSchedule/src/main/java/com/iformall/schedule/WeChatAccessTokenSchedule.java @@ -52,10 +52,11 @@ public class WeChatAccessTokenSchedule { try { String accessToken = wxMaService.getAccessToken(true); WxAppinfo updateAppInfo = new WxAppinfo(); + updateAppInfo.setAppId(appinfo.getAppId()); updateAppInfo.setAccessToken(accessToken); updateAppInfo.setLastTokenTime(new Date()); updateAppInfo.setExpiresIn(7200); - wxAppinfoMapper.updateById(updateAppInfo); + wxAppinfoMapper.updateAccessToken(updateAppInfo); } catch (WxErrorException e) { logger.error(e.getMessage()); } catch (Exception e) { diff --git a/mallinkService/src/main/java/com/iformall/domain/po/WxPayAccount.java b/mallinkService/src/main/java/com/iformall/domain/po/WxPayAccount.java index 9d18c0054..58a50fa3b 100644 --- a/mallinkService/src/main/java/com/iformall/domain/po/WxPayAccount.java +++ b/mallinkService/src/main/java/com/iformall/domain/po/WxPayAccount.java @@ -81,13 +81,13 @@ public class WxPayAccount extends TenantEntity { return notifyUrl + "/pay/v3/"+this.getTenantId(); } public String getPayNotifyUrl() { - return notifyUrl + "/pay"; + return notifyUrl + "/pay/"+this.getTenantId(); } public String getRefundNotifyV3Url() { return notifyUrl + "/refund/v3/"+this.getTenantId(); } public String getRefundNotifyUrl() { - return notifyUrl + "/refund"; + return notifyUrl + "/refund/"+this.getTenantId(); } public String getSubsidyNotifyV3Url() { return notifyUrl + "/subsidyPay/v3/"+this.getTenantId(); diff --git a/mallinkService/src/main/java/com/iformall/douyin/payv2/request/TtPayUnifiedOrderV2Request.java b/mallinkService/src/main/java/com/iformall/douyin/payv2/request/TtPayUnifiedOrderV2Request.java index c24e50a9f..295a7652c 100644 --- a/mallinkService/src/main/java/com/iformall/douyin/payv2/request/TtPayUnifiedOrderV2Request.java +++ b/mallinkService/src/main/java/com/iformall/douyin/payv2/request/TtPayUnifiedOrderV2Request.java @@ -97,7 +97,7 @@ public class TtPayUnifiedOrderV2Request implements Serializable { * 开发者自定义透传字段,不支持二进制,长度 <= 2048 byte */ @SerializedName(value = "cp_extra") - private PageEntry cpExtra; + private String cpExtra; /** * 否 diff --git a/mallinkService/src/main/java/com/iformall/mapper/WxAppinfoMapper.java b/mallinkService/src/main/java/com/iformall/mapper/WxAppinfoMapper.java index 75f538f44..414561c14 100644 --- a/mallinkService/src/main/java/com/iformall/mapper/WxAppinfoMapper.java +++ b/mallinkService/src/main/java/com/iformall/mapper/WxAppinfoMapper.java @@ -7,10 +7,10 @@ import com.iformall.domain.po.WxAppinfo; public interface WxAppinfoMapper extends CommonMapper { List findList(WxAppinfo wxAppinfo); - - + WxAppinfo findByAppId(String appId); - - - + + WxAppinfo findByAppId(String appId,String tenantId); + + int updateAccessToken(WxAppinfo updateApp); } diff --git a/mallinkService/src/main/java/com/iformall/pay/WxMicroPayOrderP.java b/mallinkService/src/main/java/com/iformall/pay/WxMicroPayOrderP.java index 79073d506..c00678fde 100644 --- a/mallinkService/src/main/java/com/iformall/pay/WxMicroPayOrderP.java +++ b/mallinkService/src/main/java/com/iformall/pay/WxMicroPayOrderP.java @@ -14,6 +14,7 @@ public class WxMicroPayOrderP { private String nonce_str; // 随机字符串 private String sign; // 签名 private String body; // 商品简单描述 128 + private String attach; // 附加数据 private String out_trade_no; // 商户订单号 private Integer total_fee; // 支付金额 private String spbill_create_ip; // 支付IP diff --git a/mallinkService/src/main/java/com/iformall/pay/WxMicroPayOrderSP.java b/mallinkService/src/main/java/com/iformall/pay/WxMicroPayOrderSP.java index 8e228b055..ae67d67b7 100644 --- a/mallinkService/src/main/java/com/iformall/pay/WxMicroPayOrderSP.java +++ b/mallinkService/src/main/java/com/iformall/pay/WxMicroPayOrderSP.java @@ -17,6 +17,7 @@ public class WxMicroPayOrderSP { private String sign; // 签名 private String sign_type; // 签名类型 private String body; // 商品简单描述 128 + private String attach; // 附加数据 private String out_trade_no; // 商户订单号 private Integer total_fee; // 支付金额 private String spbill_create_ip; // 支付IP diff --git a/mallinkService/src/main/java/com/iformall/pay/WxPayOrderP.java b/mallinkService/src/main/java/com/iformall/pay/WxPayOrderP.java index b491581da..7a64b1a8a 100644 --- a/mallinkService/src/main/java/com/iformall/pay/WxPayOrderP.java +++ b/mallinkService/src/main/java/com/iformall/pay/WxPayOrderP.java @@ -13,6 +13,7 @@ public class WxPayOrderP { private String nonce_str; // 随机字符串 private String sign; // 签名 private String body; // 商品简单描述 128 + private String attach; // 附加数据 private String out_trade_no; // 商户订单号 private Integer total_fee; // 支付金额 private String spbill_create_ip; // 支付IP diff --git a/mallinkService/src/main/java/com/iformall/pay/WxPayOrderSP.java b/mallinkService/src/main/java/com/iformall/pay/WxPayOrderSP.java index 72d238a9f..ad057a5ad 100644 --- a/mallinkService/src/main/java/com/iformall/pay/WxPayOrderSP.java +++ b/mallinkService/src/main/java/com/iformall/pay/WxPayOrderSP.java @@ -16,6 +16,7 @@ public class WxPayOrderSP { private String sign; // 签名 private String sign_type; // 签名类型 private String body; // 商品简单描述 128 + private String attach; // 附加数据 private String out_trade_no; // 商户订单号 private String total_fee; // 支付金额 private String spbill_create_ip; // 支付IP diff --git a/mallinkService/src/main/java/com/iformall/service/WxAppinfoService.java b/mallinkService/src/main/java/com/iformall/service/WxAppinfoService.java index 752c04d69..4f2b98aa9 100644 --- a/mallinkService/src/main/java/com/iformall/service/WxAppinfoService.java +++ b/mallinkService/src/main/java/com/iformall/service/WxAppinfoService.java @@ -52,12 +52,13 @@ public interface WxAppinfoService { WxAppinfo getById(Long id); /** - * 根据appId获得实体 + * 多个存在获取集团的。 * * @param appId * @return */ WxAppinfo getByAppId(String appId); + WxAppinfo getByAppId(String appId,String tenantId); /** * 获取c端小程序信息 @@ -83,7 +84,7 @@ public interface WxAppinfoService { */ void deleteById(Long id); - WxAppinfo getByAppIdFromRedis(String appId); + WxAppinfo getByAppIdFromRedis(String appId,String tenantId); WxAppinfo getByIdFromRedis(Long id); WxAppinfo getCAppInfoFromRedis(String tenantId, EnumAppPlat appPlat); diff --git a/mallinkService/src/main/java/com/iformall/service/WxCuserFloatingLayerService.java b/mallinkService/src/main/java/com/iformall/service/WxCuserFloatingLayerService.java index 96a29997a..91687f10b 100644 --- a/mallinkService/src/main/java/com/iformall/service/WxCuserFloatingLayerService.java +++ b/mallinkService/src/main/java/com/iformall/service/WxCuserFloatingLayerService.java @@ -8,6 +8,6 @@ import com.iformall.domain.po.base.TenantEntity; */ public interface WxCuserFloatingLayerService { - WxFloatingLayer getFloatingLayer(String openId, String appId); + WxFloatingLayer getFloatingLayer(TenantEntity tenantEntity,String openId); } diff --git a/mallinkService/src/main/java/com/iformall/service/WxMerchantBUserService.java b/mallinkService/src/main/java/com/iformall/service/WxMerchantBUserService.java index 1f3d0f2b7..00c58f123 100644 --- a/mallinkService/src/main/java/com/iformall/service/WxMerchantBUserService.java +++ b/mallinkService/src/main/java/com/iformall/service/WxMerchantBUserService.java @@ -64,6 +64,6 @@ public interface WxMerchantBUserService { boolean hasPhone(TenantEntity tenantEntity, String phone); - ResultData updatePwd(String appId, String phone, String code, String pwd); + ResultData updatePwd(TenantEntity tenantEntity, String phone, String code, String pwd); } diff --git a/mallinkService/src/main/java/com/iformall/service/WxPayBillService.java b/mallinkService/src/main/java/com/iformall/service/WxPayBillService.java index a2d7e13a4..97a48a3e9 100644 --- a/mallinkService/src/main/java/com/iformall/service/WxPayBillService.java +++ b/mallinkService/src/main/java/com/iformall/service/WxPayBillService.java @@ -43,7 +43,7 @@ public interface WxPayBillService { * @param payWay 支付方式 * @return */ - String notify(Map paramMap, EnumPayWay payWay); + String notify(String tenantId,Map paramMap, EnumPayWay payWay); /** * 支付成功处理 diff --git a/mallinkService/src/main/java/com/iformall/service/cuser/wx/WxBUserServiceAdapter.java b/mallinkService/src/main/java/com/iformall/service/cuser/wx/WxBUserServiceAdapter.java index 88401b201..d66696dcc 100644 --- a/mallinkService/src/main/java/com/iformall/service/cuser/wx/WxBUserServiceAdapter.java +++ b/mallinkService/src/main/java/com/iformall/service/cuser/wx/WxBUserServiceAdapter.java @@ -14,6 +14,7 @@ import com.iformall.domain.vo.UserCountVo; import com.iformall.domain.vo.UserStructureVo; import com.iformall.enums.EnumAppPlat; import com.iformall.exception.MallinkException; +import com.iformall.mapper.WxAppinfoMapper; import com.iformall.mapper.WxBuserMapper; import com.iformall.service.WxAppinfoService; import com.iformall.service.cuser.BasicCUserService; @@ -40,6 +41,9 @@ public class WxBUserServiceAdapter extends BasicCUserService implements CUserSer @Autowired private WxAppinfoService wxAppinfoService; + @Autowired + private WxAppinfoMapper wxAppinfoMapper; + @Autowired private FmOpenService openService; @@ -300,14 +304,14 @@ public class WxBUserServiceAdapter extends BasicCUserService implements CUserSer try { String accessToken = wxMaService.getAccessToken(true); WxAppinfo updateApp = new WxAppinfo(); - updateApp.setId(wxAppinfo.getId()); + updateApp.setAppId(wxAppinfo.getAppId()); updateApp.setAccessToken(accessToken); updateApp.setLastTokenTime(new Date()); updateApp.setExpiresIn(7200); wxAppinfo.setAccessToken(updateApp.getAccessToken()); wxAppinfo.setLastTokenTime(updateApp.getLastTokenTime()); wxAppinfo.setExpiresIn(updateApp.getExpiresIn()); - wxAppinfoService.saveOrUpdate(updateApp); + wxAppinfoMapper.updateAccessToken(updateApp); } catch (WxErrorException e) { logger.error(e.getMessage()); diff --git a/mallinkService/src/main/java/com/iformall/service/cuser/wx/WxCUserServiceAdapter.java b/mallinkService/src/main/java/com/iformall/service/cuser/wx/WxCUserServiceAdapter.java index 3d2080092..b2ecbeb59 100644 --- a/mallinkService/src/main/java/com/iformall/service/cuser/wx/WxCUserServiceAdapter.java +++ b/mallinkService/src/main/java/com/iformall/service/cuser/wx/WxCUserServiceAdapter.java @@ -16,6 +16,7 @@ import com.iformall.enums.EnumAppPlat; import com.iformall.enums.EnumAssignTagsTrigger; import com.iformall.enums.EnumPayVersion; import com.iformall.enums.EnumYesOrNo; +import com.iformall.mapper.WxAppinfoMapper; import com.iformall.mapper.WxMallMapper; import com.iformall.service.WxAppinfoService; import com.iformall.service.WxCUserBasicInfoService; @@ -58,6 +59,9 @@ public class WxCUserServiceAdapter extends BasicCUserService implements CUserSer @Autowired private WxAppinfoService wxAppinfoService; + @Autowired + private WxAppinfoMapper wxAppinfoMapper; + @Autowired private FmOpenService openService; @@ -405,14 +409,14 @@ public class WxCUserServiceAdapter extends BasicCUserService implements CUserSer try { String accessToken = wxMaService.getAccessToken(true); WxAppinfo updateApp = new WxAppinfo(); - updateApp.setId(wxAppinfo.getId()); + updateApp.setAppId(wxAppinfo.getAppId()); updateApp.setAccessToken(accessToken); updateApp.setLastTokenTime(new Date()); updateApp.setExpiresIn(7200); wxAppinfo.setAccessToken(updateApp.getAccessToken()); wxAppinfo.setLastTokenTime(updateApp.getLastTokenTime()); wxAppinfo.setExpiresIn(updateApp.getExpiresIn()); - wxAppinfoService.saveOrUpdate(updateApp); + wxAppinfoMapper.updateAccessToken(updateApp); } catch (WxErrorException e) { logger.error(e.getMessage()); diff --git a/mallinkService/src/main/java/com/iformall/service/impl/TtMerchantPoiServiceImpl.java b/mallinkService/src/main/java/com/iformall/service/impl/TtMerchantPoiServiceImpl.java index 4437ca024..8b10e046f 100644 --- a/mallinkService/src/main/java/com/iformall/service/impl/TtMerchantPoiServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/impl/TtMerchantPoiServiceImpl.java @@ -605,14 +605,14 @@ public class TtMerchantPoiServiceImpl implements TtMerchantPoiService { try { String accessToken = ttWebService.getAccessToken(true); WxAppinfo updateApp = new WxAppinfo(); - updateApp.setId(appinfo.getId()); + updateApp.setAppId(appinfo.getAppId()); updateApp.setAccessToken(accessToken); updateApp.setLastTokenTime(new Date()); updateApp.setExpiresIn(7200); appinfo.setAccessToken(updateApp.getAccessToken()); appinfo.setLastTokenTime(updateApp.getLastTokenTime()); appinfo.setExpiresIn(updateApp.getExpiresIn()); - wxAppinfoMapper.updateById(updateApp); + wxAppinfoMapper.updateAccessToken(updateApp); } catch (WxErrorException e) { logger.error(e.getMessage()); diff --git a/mallinkService/src/main/java/com/iformall/service/impl/WxAppinfoServiceImpl.java b/mallinkService/src/main/java/com/iformall/service/impl/WxAppinfoServiceImpl.java index 1f319ce51..45bc0c49d 100644 --- a/mallinkService/src/main/java/com/iformall/service/impl/WxAppinfoServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/impl/WxAppinfoServiceImpl.java @@ -14,6 +14,7 @@ import com.iformall.enums.EnumCouponType; import com.iformall.enums.EnumPayWay; import com.iformall.mapper.WxAppinfoMapper; import com.iformall.service.WxAppinfoService; +import com.iformall.service.WxMallService; import com.iformall.utils.Constant; import com.iformall.utils.RedisCacheUtils; @@ -36,6 +37,9 @@ public class WxAppinfoServiceImpl implements WxAppinfoService { @Autowired WxAppinfoMapper wxAppinfoMapper; + @Autowired + WxMallService wxMallService; + @Autowired @Qualifier("objectCommonRedisTemplate") RedisTemplate wxAppinfoRedisTemplate; @@ -95,7 +99,26 @@ public class WxAppinfoServiceImpl implements WxAppinfoService { @Override public WxAppinfo getByAppId(String appId) { - return wxAppinfoMapper.findByAppId(appId); + WxAppinfo appinfoQ = new WxAppinfo(); + appinfoQ.setAppId(appId); + List list = wxAppinfoMapper.findList(appinfoQ); + if(list.size() == 1){ + return list.get(0); + }else if(list.size() > 0){ + for (WxAppinfo appinfo:list) { + TenantEntity tenantEntity = new TenantEntity(); + tenantEntity.setTenantId(appinfo.getTenantId()); + if(wxMallService.isgroupSupport(tenantEntity)){ + return appinfo; + } + } + } + return null; + } + + @Override + public WxAppinfo getByAppId(String appId, String tenantId) { + return wxAppinfoMapper.findByAppId(appId,tenantId); } @Override @@ -155,9 +178,9 @@ public class WxAppinfoServiceImpl implements WxAppinfoService { } @Override - public WxAppinfo getByAppIdFromRedis(String appId) { + public WxAppinfo getByAppIdFromRedis(String appId,String tenantId) { WxAppinfo record = null; - String key = Constant.appinfoPrev + appId; + String key = Constant.appinfoPrev + tenantId + ":" + appId; record = RedisCacheUtils.getCacheObject(wxAppinfoRedisTemplate, key, WxAppinfo.class); if (null == record) { record = this.getByAppId(appId); diff --git a/mallinkService/src/main/java/com/iformall/service/impl/WxAuthorizerInfoServiceImpl.java b/mallinkService/src/main/java/com/iformall/service/impl/WxAuthorizerInfoServiceImpl.java index 72e259c70..870b344bb 100644 --- a/mallinkService/src/main/java/com/iformall/service/impl/WxAuthorizerInfoServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/impl/WxAuthorizerInfoServiceImpl.java @@ -162,34 +162,23 @@ public class WxAuthorizerInfoServiceImpl implements WxAuthorizerInfoService { logger.error(e.getMessage()); } if (authorizerInfo == null) { - WxAppinfo appinfo = appinfoMapper.findByAppId(record.getAuthorizerAppid()); - if(appinfo != null) { - record.setId(appinfo.getId()); -// record.updateTenantInfo(appinfo.getTenantInfo()); - record.setTenantId(appinfo.getTenantId()); - record.setType(appinfo.getType()); - } else { - //record.setId(UUID.randomUUID().toString().replaceAll("-", "")); - final IdWorker idWorker = IdWorker.get(); - record.setId(idWorker.nextId()); - } + final IdWorker idWorker = IdWorker.get(); + record.setId(idWorker.nextId()); record.setCreateTime(curDate); record.setUpdateTime(curDate); // 授权表 添加 authorizerInfoMapper.insert(record); - if(appinfo.getType() != null) { - if (appinfo.getType().equals(EnumAppType.C.getCode()) || - appinfo.getType().equals(EnumAppType.B.getCode())) { + if(record.getType() != null) { + if (record.getType().equals(EnumAppType.C.getCode()) || + record.getType().equals(EnumAppType.B.getCode())) { // C/B 扩展配置表添加 WxWeappExtSet weappExtSet = new WxWeappExtSet(); weappExtSet.setId(record.getId()); weappExtSet.setAppId(record.getAuthorizerAppid()); - if (appinfo.getType().equals(EnumAppType.C.getCode())) { + if (record.getType().equals(EnumAppType.C.getCode())) { weappExtSet.setCarSupport(EnumCarSupport.NOCAR.getCode()); } - if (appinfo != null) { - weappExtSet.setType(appinfo.getType()); - } + weappExtSet.setType(record.getType()); weappExtSet.setCreateDate(curDate); weappExtSet.setUpdateDate(curDate); weappExtSetMapper.insert(weappExtSet); diff --git a/mallinkService/src/main/java/com/iformall/service/impl/WxCouponOrderServiceImpl.java b/mallinkService/src/main/java/com/iformall/service/impl/WxCouponOrderServiceImpl.java index 66ef72f57..e12dd6122 100644 --- a/mallinkService/src/main/java/com/iformall/service/impl/WxCouponOrderServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/impl/WxCouponOrderServiceImpl.java @@ -2076,6 +2076,7 @@ public class WxCouponOrderServiceImpl implements WxCouponOrderService { WxAuthorizerInfo weappInfo = authorizerInfoMapper.findMp(authQ); if (weappInfo != null) { AppUniformMsg appUniformMsg = new AppUniformMsg(); + appUniformMsg.setTenantId(coupon.getTenantId()); appUniformMsg.setMsgType(EnumMsgRecordType.SMART_APP_UNIFORM.getCode()); appUniformMsg.setAppId(user.getAppId()); appUniformMsg.setTo(user.getOpenId()); diff --git a/mallinkService/src/main/java/com/iformall/service/impl/WxCuserFloatingLayerServiceImpl.java b/mallinkService/src/main/java/com/iformall/service/impl/WxCuserFloatingLayerServiceImpl.java index 7fb655ae8..9120097a2 100644 --- a/mallinkService/src/main/java/com/iformall/service/impl/WxCuserFloatingLayerServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/impl/WxCuserFloatingLayerServiceImpl.java @@ -43,19 +43,14 @@ public class WxCuserFloatingLayerServiceImpl implements WxCuserFloatingLayerServ @Override - public WxFloatingLayer getFloatingLayer(String openId, String appId) { - WxAppinfo appinfo = appinfoMapper.findByAppId(appId); - if (StringUtils.isBlank(openId)) { - return getWxFloatingLayer(appinfo.getTenantId()); - } + public WxFloatingLayer getFloatingLayer(TenantEntity tenantEntity,String openId) { //1 查看是否存在用户,用户不存在 直接返回浮层信息 WxCUser user = new WxCUser(); user.setOpenId(openId); - user.setAppId(appId); - user.setTenantId(appinfo.getTenantId()); + user.setTenantId(tenantEntity.getTenantId()); WxCUser byOpenId = wxCUserMapper.findByOpenId(user); if (byOpenId == null) { - return getWxFloatingLayer(appinfo.getTenantId()); + return getWxFloatingLayer(tenantEntity.getTenantId()); } //2 用户存在 查看是否已有弹出记录 没有 保存记录后返回浮层信息 WxCuserFloatingLayer wxCuserFloatingLayerQuery = new WxCuserFloatingLayer(); diff --git a/mallinkService/src/main/java/com/iformall/service/impl/WxMerchantBUserServiceImpl.java b/mallinkService/src/main/java/com/iformall/service/impl/WxMerchantBUserServiceImpl.java index 53b884613..f4a3f0300 100644 --- a/mallinkService/src/main/java/com/iformall/service/impl/WxMerchantBUserServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/impl/WxMerchantBUserServiceImpl.java @@ -19,6 +19,7 @@ import com.iformall.mapper.WxAppinfoMapper; import com.iformall.mapper.WxMerchantBUserMapper; import com.iformall.mapper.WxMerchantMapper; import com.iformall.mapper.WxMsgValidationcodeMapper; +import com.iformall.service.WxMallService; import com.iformall.service.WxMerchantBUserService; import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; @@ -36,6 +37,9 @@ import java.util.stream.Collectors; public class WxMerchantBUserServiceImpl implements WxMerchantBUserService { private final Logger logger = LoggerFactory.getLogger(this.getClass()); + @Autowired + WxMallService wxMallService; + @Autowired WxAppinfoMapper wxAppinfoMapper; @@ -144,10 +148,10 @@ public class WxMerchantBUserServiceImpl implements WxMerchantBUserService { } @Override - public ResultData updatePwd(String appId, String phone, String code, String pwd) { - WxAppinfo appinfo = wxAppinfoMapper.findByAppId(appId); + public ResultData updatePwd(TenantEntity tenantEntity, String phone, String code, String pwd) { + WxMsgValidationcode wxMsgValidationcode = new WxMsgValidationcode(); - wxMsgValidationcode.setTenantId(appinfo.getTenantId()); + wxMsgValidationcode.setTenantId(tenantEntity.getTenantId()); wxMsgValidationcode.setPhone(phone); wxMsgValidationcode.setCode(code); List msgValidationCodeList = wxMsgValidationcodeMapper.findList(wxMsgValidationcode); @@ -157,22 +161,30 @@ public class WxMerchantBUserServiceImpl implements WxMerchantBUserService { if (msgValidationCodeList.size() > 0) { //更新 WxMerchantBUser bUser = new WxMerchantBUser(); - bUser.setTenantId(appinfo.getTenantId()); + bUser.setTenantId(tenantEntity.getTenantId()); bUser.setPhone(phone); - bUser.setAppId(appId); bUser.setStatus(EnumMerchantBUserStatus.VALID.getCode()); List list = wxMerchantBUserMapper.findList(bUser); + if(wxMallService.isgroupSupport(tenantEntity)){ + bUser.setTenantId(null); + bUser.setParentTenantId(tenantEntity.getTenantId()); + List list1 = wxMerchantBUserMapper.findList(bUser); + if(list1.size() > 0){ + list.addAll(list1); + } + } if (list.size() > 0) { - bUser = list.get(0); - bUser.setUserPwd(pwd); - try { - wxMerchantBUserMapper.updateById(bUser); - } catch (Exception e) { - logger.error("db failed: 商户-" + bUser.getId() + ", e:" + e.getMessage()); - throw new MallinkException(ErrorCode.DB_FAIL.getCode(), "DB FAILD " + e.getMessage()); + for (WxMerchantBUser merchantBUser:list) { + merchantBUser.setUserPwd(pwd); + try { + wxMerchantBUserMapper.updateById(bUser); + } catch (Exception e) { + logger.error("db failed: 商户-" + bUser.getId() + ", e:" + e.getMessage()); + throw new MallinkException(ErrorCode.DB_FAIL.getCode(), "DB FAILD " + e.getMessage()); + } } } else { - logger.error("B端用户不是这个app的用户:" + appId); + logger.error("未找到用户:"); throw new MallinkException(ErrorCode.BUSER_NOT_IN_APP); } } diff --git a/mallinkService/src/main/java/com/iformall/service/impl/WxOrderServiceImpl.java b/mallinkService/src/main/java/com/iformall/service/impl/WxOrderServiceImpl.java index 2f8355dec..1aef31fd1 100644 --- a/mallinkService/src/main/java/com/iformall/service/impl/WxOrderServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/impl/WxOrderServiceImpl.java @@ -1798,6 +1798,7 @@ public class WxOrderServiceImpl implements WxOrderService { WxAuthorizerInfo weappInfo = authorizerInfoMapper.findMp(authQ); if (weappInfo != null) { AppUniformMsg appUniformMsg = new AppUniformMsg(); + appUniformMsg.setTenantId(coupon.getTenantId()); appUniformMsg.setMsgType(EnumMsgRecordType.SMART_APP_UNIFORM.getCode()); appUniformMsg.setAppId(user.getAppId()); appUniformMsg.setTo(user.getOpenId()); diff --git a/mallinkService/src/main/java/com/iformall/service/impl/WxPayBillServiceImpl.java b/mallinkService/src/main/java/com/iformall/service/impl/WxPayBillServiceImpl.java index 4d3e55546..86416b0ca 100644 --- a/mallinkService/src/main/java/com/iformall/service/impl/WxPayBillServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/impl/WxPayBillServiceImpl.java @@ -576,7 +576,7 @@ public class WxPayBillServiceImpl implements WxPayBillService { * @return */ @Override - public String notify(Map paramMap, EnumPayWay payWay) { + public String notify(String tenantId,Map paramMap, EnumPayWay payWay) { // how to get wechatAppId, wechatMchId, partnerKey logger.info("-------------"); logger.info("微信回调返回值:" + JSONObject.toJSONString(paramMap)); @@ -585,18 +585,19 @@ public class WxPayBillServiceImpl implements WxPayBillService { String subAppId = paramMap.get("sub_appid"); String mchId = paramMap.get("mch_id"); String subMchId = paramMap.get("sub_mch_id"); + String attach = paramMap.get("attach"); WxAppinfo appinfo; boolean isNormal = true; if (StringUtils.isBlank(subAppId) && StringUtils.isBlank(subMchId)) { // 普通商户号 - appinfo = wxAppinfoMapper.findByAppId(appId); + appinfo = wxAppinfoMapper.findByAppId(appId,tenantId); if (appinfo == null) { throw new MallinkException(ErrorCode.APP_ID_NOT_FOUND); } isNormal = true; } else { // 服务号 现在用hmac-sha256 - appinfo = wxAppinfoMapper.findByAppId(subAppId); + appinfo = wxAppinfoMapper.findByAppId(subAppId,tenantId); if (appinfo == null) { throw new MallinkException(ErrorCode.APP_ID_NOT_FOUND); } diff --git a/mallinkService/src/main/java/com/iformall/service/impl/WxTemplateMsgServiceImpl.java b/mallinkService/src/main/java/com/iformall/service/impl/WxTemplateMsgServiceImpl.java index 95b60e3f0..4d4f79ec4 100644 --- a/mallinkService/src/main/java/com/iformall/service/impl/WxTemplateMsgServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/impl/WxTemplateMsgServiceImpl.java @@ -124,8 +124,7 @@ public class WxTemplateMsgServiceImpl implements WxTemplateMsgService { if(isFmOpen) { wxMaService = openService.getWxOpenComponentService().getWxMaServiceByAppid(appinfo.getAppId()); } else { - WxAppinfo appInfo = wxAppinfoService.getByAppId(appinfo.getAppId()); - wxMaService = maUtil.getWeappService(appInfo); + wxMaService = maUtil.getWeappService(appinfo); } String s = ""; if(byId.getType() == EnumTemplateType.ACTIVITY_REMIND.getCode()){ diff --git a/mallinkService/src/main/java/com/iformall/service/msg/impl/SendSmartAppMsgServiceImpl.java b/mallinkService/src/main/java/com/iformall/service/msg/impl/SendSmartAppMsgServiceImpl.java index 92e7b4cb6..7b51fba43 100644 --- a/mallinkService/src/main/java/com/iformall/service/msg/impl/SendSmartAppMsgServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/msg/impl/SendSmartAppMsgServiceImpl.java @@ -76,7 +76,7 @@ public class SendSmartAppMsgServiceImpl implements MsgSendService { return; } if(0 == msg.getOnOff().intValue()){ - WxAppinfo appInfo = wxAppinfoService.getByAppId(smartAppMsg.getAppId()); + WxAppinfo appInfo = wxAppinfoService.getByAppId(smartAppMsg.getAppId(),tenantEntity.getTenantId()); if(EnumTemplateType.TT_SEND_COUPON_REMIND.getCode().equals(msg.getType())){ //发抖音 TtMaService ttappService = maUtil.getTtMaService(appInfo); diff --git a/mallinkService/src/main/java/com/iformall/service/msg/impl/SendWeappUniformMsgServiceImpl.java b/mallinkService/src/main/java/com/iformall/service/msg/impl/SendWeappUniformMsgServiceImpl.java index e3ae39ed4..6a7a9f307 100644 --- a/mallinkService/src/main/java/com/iformall/service/msg/impl/SendWeappUniformMsgServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/msg/impl/SendWeappUniformMsgServiceImpl.java @@ -48,10 +48,7 @@ public class SendWeappUniformMsgServiceImpl implements MsgSendService { AppUniformMsg appUniformMsg = (AppUniformMsg)baseMsg; String tenantId = appUniformMsg.getTenantId(); - if (StringUtils.isBlank(tenantId)) { - WxAppinfo appinfo = appinfoMapper.findByAppId(appUniformMsg.getAppId()); - tenantId = appinfo.getTenantId(); - } + WxTemplateMsg msg = null; WxMaService wxMaService = openService.getWxOpenComponentService().getWxMaServiceByAppid(appUniformMsg.getAppId()); diff --git a/mallinkService/src/main/java/com/iformall/service/pay/service/pay/douyin/v1/BaseTtPayAdapterService.java b/mallinkService/src/main/java/com/iformall/service/pay/service/pay/douyin/v1/BaseTtPayAdapterService.java index a4a2d1e63..7445ca7c1 100644 --- a/mallinkService/src/main/java/com/iformall/service/pay/service/pay/douyin/v1/BaseTtPayAdapterService.java +++ b/mallinkService/src/main/java/com/iformall/service/pay/service/pay/douyin/v1/BaseTtPayAdapterService.java @@ -1,5 +1,6 @@ package com.iformall.service.pay.service.pay.douyin.v1; +import com.alibaba.fastjson.JSON; import com.iformall.common.ErrorCode; import com.iformall.domain.po.WxAppinfo; import com.iformall.domain.po.WxPayAccount; @@ -21,6 +22,8 @@ import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import java.io.File; +import java.util.HashMap; +import java.util.Map; @Slf4j public class BaseTtPayAdapterService { @@ -28,6 +31,17 @@ public class BaseTtPayAdapterService { @Autowired protected MaUtil maUtil; + /** + * 做为支付的扩展数据 + * @param payOrder + * @return + */ + protected String getCpExtra(WxPayOrder payOrder) { + Map map = new HashMap<>(); + map.put("tenantId",payOrder.getTenantId()); + return JSON.toJSONString(map); + } + protected PayQueryAdapterResult queryPayStatus(WxPayOrder oldRecord, WxAppinfo appInfo, WxPayAccount payAccount) throws Exception { TtPayService ttPayService = maUtil.getTtPayService(appInfo, payAccount); diff --git a/mallinkService/src/main/java/com/iformall/service/pay/service/pay/douyin/v1/miniApp/TtMiniAppPayAdapterService.java b/mallinkService/src/main/java/com/iformall/service/pay/service/pay/douyin/v1/miniApp/TtMiniAppPayAdapterService.java index 3e1005bde..6fb2f5038 100644 --- a/mallinkService/src/main/java/com/iformall/service/pay/service/pay/douyin/v1/miniApp/TtMiniAppPayAdapterService.java +++ b/mallinkService/src/main/java/com/iformall/service/pay/service/pay/douyin/v1/miniApp/TtMiniAppPayAdapterService.java @@ -138,6 +138,8 @@ public class TtMiniAppPayAdapterService extends BaseTtPayAdapterService implemen pageEntry.setParams(JSON.toJSONString(paramMap)); request.setOrderEntrySchema(pageEntry); + request.setCpExtra(getCpExtra(record)); + TtPayUnifiedOrderV2Result orderV2 = ttPayService.createOrderV2(request); JSONObject allExtParam = new JSONObject(); @@ -452,6 +454,7 @@ public class TtMiniAppPayAdapterService extends BaseTtPayAdapterService implemen map.put("outOrderNo",record.getOrderId()); map.put("createPay",record.isCreatPay()); if(record.isCreatPay()){ + map.put("callbackData",JSONObject.parseObject(getCpExtra(record),Map.class)); Map payment = new HashMap(); payment.put("totalAmount",composeOrder.getPayment()); map.put("payment",payment); diff --git a/mallinkService/src/main/java/com/iformall/service/pay/service/pay/wx/BaseWxPayAdapterService.java b/mallinkService/src/main/java/com/iformall/service/pay/service/pay/wx/BaseWxPayAdapterService.java index 50ed78f5f..7a9c1e834 100644 --- a/mallinkService/src/main/java/com/iformall/service/pay/service/pay/wx/BaseWxPayAdapterService.java +++ b/mallinkService/src/main/java/com/iformall/service/pay/service/pay/wx/BaseWxPayAdapterService.java @@ -59,6 +59,17 @@ public class BaseWxPayAdapterService { @Autowired MaUtil maUtil; + + /** + * 做为支付的扩展数据 + * @param payOrder + * @return + */ + protected String getAttach(WxPayOrder payOrder) { + Map map = new HashMap<>(); + map.put("tenantId",payOrder.getTenantId()); + return JSON.toJSONString(map); + } protected String getMerchantUid(WxPayOrder payOrder,WxOrder order) { WxComposeChildOrderShare share = payOrder.getChildOrderShare(order.getId()); diff --git a/mallinkService/src/main/java/com/iformall/service/pay/service/pay/wx/sft/entity/SFTPayCommonMiniAppReq.java b/mallinkService/src/main/java/com/iformall/service/pay/service/pay/wx/sft/entity/SFTPayCommonMiniAppReq.java index 9d547cd58..3900e412e 100644 --- a/mallinkService/src/main/java/com/iformall/service/pay/service/pay/wx/sft/entity/SFTPayCommonMiniAppReq.java +++ b/mallinkService/src/main/java/com/iformall/service/pay/service/pay/wx/sft/entity/SFTPayCommonMiniAppReq.java @@ -9,6 +9,7 @@ public class SFTPayCommonMiniAppReq { private String sp_mchid;//服务商户号 private String sub_mchid;//二级商户号 private String description;//商品描述 + private String attach;// 附加数据 private String out_trade_no;//商户订单号 private String notify_url;//通知地址,不允许携带查询串 private SFTPaySettleReq settle_info;//结算信息 diff --git a/mallinkService/src/main/java/com/iformall/service/pay/service/pay/wx/sft/miniApp/appPay/WxMiniAppPaySFTAdapterService.java b/mallinkService/src/main/java/com/iformall/service/pay/service/pay/wx/sft/miniApp/appPay/WxMiniAppPaySFTAdapterService.java index 1aae1f8c6..d23d65cb4 100644 --- a/mallinkService/src/main/java/com/iformall/service/pay/service/pay/wx/sft/miniApp/appPay/WxMiniAppPaySFTAdapterService.java +++ b/mallinkService/src/main/java/com/iformall/service/pay/service/pay/wx/sft/miniApp/appPay/WxMiniAppPaySFTAdapterService.java @@ -75,6 +75,7 @@ public class WxMiniAppPaySFTAdapterService extends BaseWxPaySFTAdapterService i }catch(Exception e) { req.setDescription("weixin miniApp product"); } + req.setAttach(getAttach(record)); req.setOut_trade_no(String.valueOf(composeOrder.getMainOrderId())); req.setNotify_url(payAccount.getPayNotifyV3Url()); @@ -104,6 +105,8 @@ public class WxMiniAppPaySFTAdapterService extends BaseWxPaySFTAdapterService i List suborders = new ArrayList(); for (WxOrder order : childOrders) { SFTCombineItemOrder so = new SFTCombineItemOrder(); + + String subMchId = getMerchantUid(record,order); so.initByWxOrder(payAccount, order, subMchId, appInfo, productName, String.valueOf(record.getId())); suborders.add(so); diff --git a/mallinkService/src/main/java/com/iformall/service/pay/service/pay/wx/v2/miniApp/appPay/WxMiniAppPayAdapterService.java b/mallinkService/src/main/java/com/iformall/service/pay/service/pay/wx/v2/miniApp/appPay/WxMiniAppPayAdapterService.java index 6d1a6f101..0438b5b62 100644 --- a/mallinkService/src/main/java/com/iformall/service/pay/service/pay/wx/v2/miniApp/appPay/WxMiniAppPayAdapterService.java +++ b/mallinkService/src/main/java/com/iformall/service/pay/service/pay/wx/v2/miniApp/appPay/WxMiniAppPayAdapterService.java @@ -68,6 +68,7 @@ public class WxMiniAppPayAdapterService extends BaseWxPayV2AdapterService implem wxPayOrderP.setMch_id(payAccount.getMchId()); wxPayOrderP.setNonce_str(noncestr); wxPayOrderP.setBody(productName); + wxPayOrderP.setAttach(getAttach(record)); wxPayOrderP.setOut_trade_no(record.getPayOrderNo()); wxPayOrderP.setTotal_fee(composeOrder.getPayment()); wxPayOrderP.setSpbill_create_ip(record.getIp()); // 终端IP @@ -143,6 +144,7 @@ public class WxMiniAppPayAdapterService extends BaseWxPayV2AdapterService implem wxPayOrderSP.setSub_mch_id(payAccount.getSubMchId()); wxPayOrderSP.setNonce_str(noncestr); wxPayOrderSP.setBody(productName); + wxPayOrderSP.setAttach(getAttach(record)); wxPayOrderSP.setOut_trade_no(record.getPayOrderNo()); wxPayOrderSP.setTotal_fee(composeOrder.getPayment().toString()); wxPayOrderSP.setSpbill_create_ip(record.getIp()); // 终端IP diff --git a/mallinkService/src/main/java/com/iformall/service/pay/service/pay/wx/v2/miniApp/maPay/WxMiniMaPayAdapterService.java b/mallinkService/src/main/java/com/iformall/service/pay/service/pay/wx/v2/miniApp/maPay/WxMiniMaPayAdapterService.java index 9d7f35ebb..2969397e6 100644 --- a/mallinkService/src/main/java/com/iformall/service/pay/service/pay/wx/v2/miniApp/maPay/WxMiniMaPayAdapterService.java +++ b/mallinkService/src/main/java/com/iformall/service/pay/service/pay/wx/v2/miniApp/maPay/WxMiniMaPayAdapterService.java @@ -58,6 +58,7 @@ public class WxMiniMaPayAdapterService extends BaseWxPayV2AdapterService impleme wxPayOrderP.setDevice_info(bUserPhone); wxPayOrderP.setNonce_str(noncestr); wxPayOrderP.setBody(productName); + wxPayOrderP.setAttach(getAttach(record)); wxPayOrderP.setOut_trade_no(record.getPayOrderNo()); wxPayOrderP.setTotal_fee(record.getPayAmount()); wxPayOrderP.setSpbill_create_ip(record.getIp()); // 终端IP @@ -121,6 +122,7 @@ public class WxMiniMaPayAdapterService extends BaseWxPayV2AdapterService impleme wxPayOrderSP.setDevice_info(bUserPhone); wxPayOrderSP.setNonce_str(noncestr); wxPayOrderSP.setBody(productName); + wxPayOrderSP.setAttach(getAttach(record)); wxPayOrderSP.setOut_trade_no(record.getPayOrderNo()); wxPayOrderSP.setTotal_fee(record.getPayAmount()); wxPayOrderSP.setSpbill_create_ip(record.getIp()); diff --git a/mallinkService/src/main/java/com/iformall/service/pay/service/pay/wx/v3/entity/V3PayCommonMiniAppReq.java b/mallinkService/src/main/java/com/iformall/service/pay/service/pay/wx/v3/entity/V3PayCommonMiniAppReq.java index e4b38a30f..a36ee504a 100644 --- a/mallinkService/src/main/java/com/iformall/service/pay/service/pay/wx/v3/entity/V3PayCommonMiniAppReq.java +++ b/mallinkService/src/main/java/com/iformall/service/pay/service/pay/wx/v3/entity/V3PayCommonMiniAppReq.java @@ -11,6 +11,7 @@ public class V3PayCommonMiniAppReq { private String sub_mchid;//二级商户号 private String description;//商品描述 private String out_trade_no;//商户订单号 + private String attach;//附加数据,在查询API和支付通知中原样返回,可作为自定义参数使用,实际情况下只有支付完成状态才会返回该字段。 private String notify_url;//通知地址,不允许携带查询串 private V3PaySettleReq settle_info;//结算信息 private V3PayAmountReq amount;//订单金额 diff --git a/mallinkService/src/main/java/com/iformall/service/pay/service/pay/wx/v3/miniApp/appPay/WxMiniAppPayV3AdapterService.java b/mallinkService/src/main/java/com/iformall/service/pay/service/pay/wx/v3/miniApp/appPay/WxMiniAppPayV3AdapterService.java index a073ffbc6..0cb39b026 100644 --- a/mallinkService/src/main/java/com/iformall/service/pay/service/pay/wx/v3/miniApp/appPay/WxMiniAppPayV3AdapterService.java +++ b/mallinkService/src/main/java/com/iformall/service/pay/service/pay/wx/v3/miniApp/appPay/WxMiniAppPayV3AdapterService.java @@ -92,6 +92,7 @@ public class WxMiniAppPayV3AdapterService extends BaseWxPayV3AdapterService impl req.setDescription("weixin miniApp product"); } req.setOut_trade_no(record.getPayOrderNo()); + req.setAttach(getAttach(record)); req.setNotify_url(payAccount.getPayNotifyV3Url()); V3PaySettleReq settle = new V3PaySettleReq(); diff --git a/mallinkService/src/main/java/com/iformall/service/pay/service/refund/douyin/TtRefundAdapterService.java b/mallinkService/src/main/java/com/iformall/service/pay/service/refund/douyin/TtRefundAdapterService.java index 265e06759..88daf18d1 100644 --- a/mallinkService/src/main/java/com/iformall/service/pay/service/refund/douyin/TtRefundAdapterService.java +++ b/mallinkService/src/main/java/com/iformall/service/pay/service/refund/douyin/TtRefundAdapterService.java @@ -45,6 +45,17 @@ public class TtRefundAdapterService implements RefundPayAdapterService{ @Autowired WxOrderService wxOrderService; + + /** + * 做为分账的扩展数据 + * @param + * @return + */ + protected String getCpExtra(WxRefundOrder record) { + Map map = new HashMap<>(); + map.put("tenantId",record.getTenantId()); + return JSON.toJSONString(map); + } @Override public RefundAdapterResult refund(WxPayAccount payAccount,WxAppinfo appInfo,WxRefundOrder record,WxPayOrder payOrder,Long orderId,EnumPayType payType) { @@ -54,6 +65,7 @@ public class TtRefundAdapterService implements RefundPayAdapterService{ TtPayRefundV2Request request = new TtPayRefundV2Request(); request.setOutOrderNo(payOrder.getPayOrderNo()); request.setOutRefundNo(record.getId().toString()); + request.setCpExtra(getCpExtra(record)); TtPayRefundV2Request.PageEntry pageEntry = new TtPayRefundV2Request.PageEntry(); pageEntry.setPath(Constant.mainPageUrl); Map paramMap = new HashMap<>(); @@ -173,9 +185,16 @@ public class TtRefundAdapterService implements RefundPayAdapterService{ @Override public RefundNotifyAdapterResult notify(Map paramMap, EnumPayWay payWay) { log.info("TtRefundAdapterService notify{}"+paramMap); + String tenantId = paramMap.get("tenantId"); + /** + * + */ + String refundno = paramMap.get("cp_refundno"); + Long refundOrderId = Long.valueOf(refundno); + WxRefundOrder refundOrder = wxRefundOrderMapper.selectById(refundOrderId); String appId = paramMap.get("appid"); - WxAppinfo appinfo = wxAppinfoMapper.findByAppId(appId); + WxAppinfo appinfo = wxAppinfoMapper.findByAppId(appId,tenantId); if (appinfo == null) { log.error("未找到appid信息:" + appId); throw new MallinkException(ErrorCode.APP_ID_NOT_FOUND); @@ -189,9 +208,7 @@ public class TtRefundAdapterService implements RefundPayAdapterService{ log.error("notify refund, wxpay status not success, paramMap: " + paramMap.toString() + ", payWay:" + payWay.toString()); return notifyErrorResult("订单状态码非SUCCESS"); } - String refundno = paramMap.get("cp_refundno"); - Long refundOrderId = Long.valueOf(refundno); - WxRefundOrder refundOrder = wxRefundOrderMapper.selectById(refundOrderId); + // 验证退款金额 if (!paramMap.get("refund_amount").equals(refundOrder.getRefundFee().toString())) { log.error("notify refund, wxpay check refund_fee is invalid, paramMap: " + paramMap.toString() + ", payWay:" + payWay.toString()); diff --git a/mallinkService/src/main/java/com/iformall/service/pay/service/refund/wx/v2/WxRefundAdapterService.java b/mallinkService/src/main/java/com/iformall/service/pay/service/refund/wx/v2/WxRefundAdapterService.java index 7511414c7..b047c3a5b 100644 --- a/mallinkService/src/main/java/com/iformall/service/pay/service/refund/wx/v2/WxRefundAdapterService.java +++ b/mallinkService/src/main/java/com/iformall/service/pay/service/refund/wx/v2/WxRefundAdapterService.java @@ -563,35 +563,38 @@ public class WxRefundAdapterService implements RefundPayAdapterService{ String req_info = CipherUtil.decryptReqInfo(paramMap.get("req_info"), partnerKey); Map reqMap = WxPayment.xmlToMap(req_info); - String payOrderNo = reqMap.get("out_trade_no"); - Long payOrderId = Long.valueOf(payOrderNo); - WxPayOrder payOrder = wxPayOrderMapper.selectById(payOrderId,payAccount.getTenantId()); - if (payOrder == null) { - log.warn("notify refund, wxpay check pay order not exists, paramMap: " + paramMap.toString() + ", payWay:" + payWay.toString()); - return notifyErrorResult("支付订单不存在"); - } - // 验证支付金额 - if (!reqMap.get("total_fee").equals(payOrder.getPayAmount().toString())) { - log.warn("notify refund, wxpay check total_fee is invalid, paramMap: " + paramMap.toString() + ", payWay:" + payWay.toString()); - return notifyErrorResult("支付订单总金额不一致"); - } String refundIdStr = reqMap.get("out_refund_no"); Long refundOrderId = Long.valueOf(refundIdStr); WxRefundOrder refundOrder = wxRefundOrderMapper.selectById(refundOrderId); if (refundOrder == null) { - log.warn("notify refund, wxpay check pay order not exists, paramMap: " + paramMap.toString() + ", payWay:" + payWay.toString()); - return notifyErrorResult("退款订单不存在"); + log.warn("notify refund, wxpay check pay order not exists, paramMap: " + paramMap.toString() + ", payWay:" + payWay.toString()); + return notifyErrorResult("退款订单不存在"); } // 验证支付金额 if (!reqMap.get("total_fee").equals(refundOrder.getTotalFee().toString())) { - log.warn("notify refund, wxpay check total_fee is invalid, paramMap: " + paramMap.toString() + ", payWay:" + payWay.toString()); - return notifyErrorResult("订单总金额不一致"); + log.warn("notify refund, wxpay check total_fee is invalid, paramMap: " + paramMap.toString() + ", payWay:" + payWay.toString()); + return notifyErrorResult("订单总金额不一致"); } // 验证退款金额 if (!reqMap.get("refund_fee").equals(refundOrder.getRefundFee().toString())) { - log.warn("notify refund, wxpay check refund_fee is invalid, paramMap: " + paramMap.toString() + ", payWay:" + payWay.toString()); - return notifyErrorResult("退款总金额不一致"); + log.warn("notify refund, wxpay check refund_fee is invalid, paramMap: " + paramMap.toString() + ", payWay:" + payWay.toString()); + return notifyErrorResult("退款总金额不一致"); + } + + + String payOrderNo = reqMap.get("out_trade_no"); + Long payOrderId = Long.valueOf(payOrderNo); + WxPayOrder payOrder = wxPayOrderMapper.selectById(payOrderId,refundOrder.getTenantId()); + if (payOrder == null) { + log.warn("notify refund, wxpay check pay order not exists, paramMap: " + paramMap.toString() + ", payWay:" + payWay.toString()); + return notifyErrorResult("支付订单不存在"); + } + // 验证支付金额 + if (!reqMap.get("total_fee").equals(payOrder.getPayAmount().toString())) { + log.warn("notify refund, wxpay check total_fee is invalid, paramMap: " + paramMap.toString() + ", payWay:" + payWay.toString()); + return notifyErrorResult("支付订单总金额不一致"); } + // 处理支付成功 //handleRefundSuccess(refundOrder, reqMap.get("transaction_id"), reqMap.get("refund_id")); @@ -634,21 +637,6 @@ public class WxRefundAdapterService implements RefundPayAdapterService{ log.info(req_info); Map reqMap = WxPayment.xmlToMap(req_info); - String payOrderNo = reqMap.get("out_trade_no"); - if (payOrderNo == null) { - return notifySuccessResult(reqMap.get("transaction_id"), reqMap.get("refund_id"), null); - } - Long payOrderId = Long.valueOf(payOrderNo); - WxPayOrder payOrder = wxPayOrderMapper.selectById(payOrderId,payAccount.getTenantId()); - if (payOrder == null) { - log.warn("notify refund, wxpay check pay order not exists, paramMap: " + paramMap.toString() + ", payWay:" + payWay.toString()); - return notifyErrorResult("支付订单不存在"); - } - // 验证支付金额 - if (!reqMap.get("total_fee").equals(payOrder.getPayAmount().toString())) { - log.warn("notify refund, wxpay check total_fee is invalid, paramMap: " + paramMap.toString() + ", payWay:" + payWay.toString()); - return notifyErrorResult("支付订单总金额不一致"); - } String refundIdStr = reqMap.get("out_refund_no"); Long refundOrderId = Long.valueOf(refundIdStr); WxRefundOrder refundOrder = wxRefundOrderMapper.selectById(refundOrderId); @@ -667,6 +655,23 @@ public class WxRefundAdapterService implements RefundPayAdapterService{ return notifyErrorResult("退款总金额不一致"); } + String payOrderNo = reqMap.get("out_trade_no"); + if (payOrderNo == null) { + return notifySuccessResult(reqMap.get("transaction_id"), reqMap.get("refund_id"), null); + } + Long payOrderId = Long.valueOf(payOrderNo); + WxPayOrder payOrder = wxPayOrderMapper.selectById(payOrderId,refundOrder.getTenantId()); + if (payOrder == null) { + log.warn("notify refund, wxpay check pay order not exists, paramMap: " + paramMap.toString() + ", payWay:" + payWay.toString()); + return notifyErrorResult("支付订单不存在"); + } + // 验证支付金额 + if (!reqMap.get("total_fee").equals(payOrder.getPayAmount().toString())) { + log.warn("notify refund, wxpay check total_fee is invalid, paramMap: " + paramMap.toString() + ", payWay:" + payWay.toString()); + return notifyErrorResult("支付订单总金额不一致"); + } + + log.info("notify refund, wxpay checksign success, paramMap:{}, paramMap: " + reqMap.toString() + ", payWay:" + payWay.toString()); return notifySuccessResult(reqMap.get("transaction_id"), reqMap.get("refund_id"), refundOrder); } diff --git a/mallinkService/src/main/java/com/iformall/service/pay/service/share/PayShareBaseAdapterService.java b/mallinkService/src/main/java/com/iformall/service/pay/service/share/PayShareBaseAdapterService.java index c767e1582..66dd0cb8a 100644 --- a/mallinkService/src/main/java/com/iformall/service/pay/service/share/PayShareBaseAdapterService.java +++ b/mallinkService/src/main/java/com/iformall/service/pay/service/share/PayShareBaseAdapterService.java @@ -1,6 +1,7 @@ package com.iformall.service.pay.service.share; import java.util.Date; +import java.util.HashMap; import java.util.List; import java.util.Map; @@ -12,6 +13,7 @@ import com.iformall.common.ErrorCode; import com.iformall.domain.dto.WxSharingOrderDto; import com.iformall.domain.po.WxAppinfo; import com.iformall.domain.po.WxPayAccount; +import com.iformall.domain.po.WxProfitSharingOrder; import com.iformall.domain.po.WxProfitSharingReceiver; import com.iformall.enums.EnumProfitSharingReceiverStatus; import com.iformall.enums.EnumProfitSharingReceiverType; diff --git a/mallinkService/src/main/java/com/iformall/service/pay/service/share/douyin/TtPayShareService.java b/mallinkService/src/main/java/com/iformall/service/pay/service/share/douyin/TtPayShareService.java index f999dd01c..15d0f912e 100644 --- a/mallinkService/src/main/java/com/iformall/service/pay/service/share/douyin/TtPayShareService.java +++ b/mallinkService/src/main/java/com/iformall/service/pay/service/share/douyin/TtPayShareService.java @@ -77,7 +77,17 @@ public class TtPayShareService extends PayShareBaseAdapterService{ @Lazy @Autowired WxProfitSharingReceiverService wxProfitSharingReceiverService; - + + /** + * 做为分账的扩展数据 + * @param payOrder + * @return + */ + protected String getCpExtra(WxProfitSharingOrder record) { + Map map = new HashMap<>(); + map.put("tenantId",record.getTenantId()); + return JSON.toJSONString(map); + } @Override public Integer getSubsidyType() { @@ -109,6 +119,7 @@ public class TtPayShareService extends PayShareBaseAdapterService{ TtPayService ttPayService = maUtil.getTtPayService(appInfo, payAccount); ProfitSharingRequest request = new ProfitSharingRequest(); request.setOutOrderNo(record.getOrderId().toString()); + request.setCpExtra(getCpExtra(record)); if(record.getOutSettleNo() == null){ record.setOutSettleNo(record.getId()); }else{ @@ -160,6 +171,7 @@ public class TtPayShareService extends PayShareBaseAdapterService{ TtPayService ttPayService = maUtil.getTtPayService(appInfo, payAccount); ProfitSharingRequest request = new ProfitSharingRequest(); request.setOutOrderNo(record.getOrderId().toString()); + request.setCpExtra(getCpExtra(record)); if(record.getOutSettleNo() == null){ record.setOutSettleNo(record.getId()); }else{ diff --git a/mallinkService/src/main/java/com/iformall/utils/MaUtil.java b/mallinkService/src/main/java/com/iformall/utils/MaUtil.java index 8b71fcfe8..599e1b1ec 100644 --- a/mallinkService/src/main/java/com/iformall/utils/MaUtil.java +++ b/mallinkService/src/main/java/com/iformall/utils/MaUtil.java @@ -23,6 +23,7 @@ import com.iformall.douyin.web.api.TtWebService; import com.iformall.douyin.web.api.impl.TtWebServiceImpl; import com.iformall.douyin.web.config.TtWebDefaultConfigImpl; import com.iformall.douyin.web.enums.TtWebApiBeginEnum; +import com.iformall.mapper.WxAppinfoMapper; import com.iformall.service.WxAppinfoService; import lombok.extern.flogger.Flogger; import me.chanjar.weixin.common.error.WxErrorException; @@ -40,6 +41,9 @@ public class MaUtil { @Autowired private WxAppinfoService wxAppinfoService; + @Autowired + private WxAppinfoMapper wxAppinfoMapper; + private static Map serviceMap = new ConcurrentHashMap(); private static Map appServiceKeyMap = new ConcurrentHashMap(); @@ -230,14 +234,14 @@ public class MaUtil { try { String accessToken = ttMaService.getAccessToken(true); WxAppinfo updateApp = new WxAppinfo(); - updateApp.setId(wxAppinfo.getId()); + updateApp.setAppId(wxAppinfo.getAppId()); updateApp.setAccessToken(accessToken); updateApp.setLastTokenTime(new Date()); updateApp.setExpiresIn(7200); wxAppinfo.setAccessToken(updateApp.getAccessToken()); wxAppinfo.setLastTokenTime(updateApp.getLastTokenTime()); wxAppinfo.setExpiresIn(updateApp.getExpiresIn()); - wxAppinfoService.saveOrUpdate(updateApp); + wxAppinfoMapper.updateAccessToken(updateApp); } catch (WxErrorException e) { logger.error(e.getMessage()); diff --git a/mallinkService/src/main/resources/mapper/WxAppinfoMapper.xml b/mallinkService/src/main/resources/mapper/WxAppinfoMapper.xml index 1cd3622fe..b896b433b 100644 --- a/mallinkService/src/main/resources/mapper/WxAppinfoMapper.xml +++ b/mallinkService/src/main/resources/mapper/WxAppinfoMapper.xml @@ -112,5 +112,15 @@ SELECT * FROM wx_appinfo WHERE `app_id` = #{appId} + + and `tenant_id` = #{tenantId} + + limit 1 + + + update wx_appinfo set + `access_token` = #{accessToken}, `last_token_time` = #{lastTokenTime}, `expires_in` = #{expiresIn} + where `app_id` = #{appId} +