| @@ -1,21 +1,25 @@ | |||
| package com.iformall.controller.callback; | |||
| import com.github.binarywang.wxpay.bean.businesscircle.BusinessCircleNotifyData; | |||
| import com.github.binarywang.wxpay.bean.businesscircle.MemberCardAuthorizeNotifyResult; | |||
| import com.github.binarywang.wxpay.bean.businesscircle.PaidResult; | |||
| import com.github.binarywang.wxpay.bean.businesscircle.RefundResult; | |||
| import com.github.binarywang.wxpay.bean.ecommerce.SignatureHeader; | |||
| import com.github.binarywang.wxpay.bean.membercard.MemberCardActivateResult; | |||
| import com.github.binarywang.wxpay.bean.membercard.MemberCardNotifyData; | |||
| import com.github.binarywang.wxpay.exception.WxPayException; | |||
| import com.github.binarywang.wxpay.service.WxPayService; | |||
| import com.iformall.controller.base.BaseController; | |||
| import com.iformall.domain.po.WxAppinfo; | |||
| import com.iformall.domain.po.WxBusinessCircleOrder; | |||
| import com.iformall.domain.po.WxMemberCard; | |||
| import com.iformall.domain.po.WxPayAccount; | |||
| import com.iformall.domain.po.base.TenantEntity; | |||
| import com.iformall.enums.EnumThirdPartyConfigType; | |||
| import com.iformall.enums.*; | |||
| import com.iformall.exception.MallinkException; | |||
| import com.iformall.interceptor.BodyReaderHttpServletRequestWrapper; | |||
| import com.iformall.pay.WxPayConstant; | |||
| import com.iformall.service.WxBusinessCircleOrderService; | |||
| import com.iformall.service.WxMallService; | |||
| import com.iformall.service.WxPayAccountService; | |||
| import com.iformall.service.*; | |||
| import com.iformall.utils.MaUtil; | |||
| import org.apache.commons.lang3.StringUtils; | |||
| import org.apache.shiro.web.servlet.ShiroHttpServletRequest; | |||
| @@ -46,12 +50,109 @@ public class WxBusinessOrderController extends BaseController { | |||
| @Autowired | |||
| WxMallService wxMallService; | |||
| @Autowired | |||
| WxAppinfoService wxAppinfoService; | |||
| @Autowired | |||
| WxPayAccountService wxPayAccountService; | |||
| @Autowired | |||
| WxBusinessCircleOrderService wxBusinessCircleOrderService; | |||
| @Autowired | |||
| WxMemberCardService wxMemberCardService; | |||
| @Autowired | |||
| MaUtil maUtil; | |||
| /** | |||
| * | |||
| * @return 商圈授权通知 | |||
| */ | |||
| @PostMapping(value = "/membercard/{tenantId}") | |||
| @ResponseBody | |||
| public Map<String,String> notify(@PathVariable String tenantId, HttpServletRequest request){ | |||
| logger.info("[" +getIpAddr() + "]商圈授权通知-----"+tenantId); | |||
| Map<String,String> resultMap = new HashMap<>(); | |||
| if(StringUtils.isBlank(tenantId)){ | |||
| logger.error("tenantId为空"); | |||
| resultMap.put("code","FAIL"); | |||
| return resultMap; | |||
| } | |||
| TenantEntity tenantEntity = wxMallService.getByTenantId(tenantId); | |||
| if(tenantEntity == null){ | |||
| logger.error("获取tenantEntity为null"); | |||
| resultMap.put("code","FAIL"); | |||
| return resultMap; | |||
| } | |||
| SignatureHeader header = new SignatureHeader(); | |||
| header.setSerialNo(request.getHeader("Wechatpay-Serial")); | |||
| header.setTimeStamp(request.getHeader("Wechatpay-Timestamp")); | |||
| header.setNonce(request.getHeader("Wechatpay-Nonce")); | |||
| header.setSigned(request.getHeader("Wechatpay-Signature")); | |||
| logger.info("商圈授权通知---header{}"+header.toString()); | |||
| try { | |||
| String body = this.getBody(request); | |||
| logger.info("商圈授权通知---body{}"+body); | |||
| WxAppinfo cAppInfo = wxAppinfoService.getCAppInfoFromRedis(tenantId, EnumAppPlat.WX); | |||
| WxPayAccount payAccount = wxPayAccountService.getByIdFromRedis(cAppInfo.getPayId()); | |||
| if(cAppInfo == null || payAccount == null){ | |||
| resultMap.put("code","FAIL"); | |||
| return resultMap; | |||
| } | |||
| WxPayService wxPayService = maUtil.getWxPayService(cAppInfo, payAccount); | |||
| //----------------签名验证----------- | |||
| // BusinessCircleNotifyData notifyData = verifySignature(request,wxPayService); | |||
| BusinessCircleNotifyData notifyData = wxPayService.getBusinessCircleService().parseNotifyData(body, header); | |||
| logger.info("商圈授权通知---回调通知对象{}"+notifyData.toString()); | |||
| MemberCardAuthorizeNotifyResult result = wxPayService.getBusinessCircleService().decryptMemberCardAuthorizeNotifyDataResource(notifyData); | |||
| logger.info("商圈授权通知---解密结果{}"+result.toString()); | |||
| WxMemberCard memberCard = new WxMemberCard(); | |||
| memberCard.updateTenantInfo(tenantEntity); | |||
| memberCard.setAppId(cAppInfo.getAppId()); | |||
| memberCard.setCardId(payAccount.getCardId()); | |||
| memberCard.setCardCode(result.getCode()); | |||
| memberCard.setOpenId(result.getOpenid()); | |||
| if(WxPayConstant.REGISTERED_MODE.equals(result.getAuthType())){ | |||
| memberCard.setUserCardStatus(EnumMemberCardStatus.EFFECTIVE.getCode()); | |||
| memberCard.setAuthorizeState(EnumMemberCardAuthorizeState.UNAUTHORIZED.getCode()); | |||
| wxMemberCardService.saveorupdateByCode(memberCard); | |||
| resultMap.put("code","SUCCESS"); | |||
| return resultMap; | |||
| }else if(WxPayConstant.REGISTERED_AND_AUTHORIZATION_MODE.equals(result.getAuthType())){ | |||
| memberCard.setUserCardStatus(EnumMemberCardStatus.EFFECTIVE.getCode()); | |||
| memberCard.setAuthorizeState(EnumMemberCardAuthorizeState.AUTHORIZED.getCode()); | |||
| wxMemberCardService.saveorupdateByCode(memberCard); | |||
| resultMap.put("code","SUCCESS"); | |||
| return resultMap; | |||
| } | |||
| resultMap.put("code","FAIL"); | |||
| return resultMap; | |||
| } catch (WxPayException e) { | |||
| e.printStackTrace(); | |||
| logger.error("商圈授权通知---"+e.getCustomErrorMsg()); | |||
| resultMap.put("code","FAIL"); | |||
| return resultMap; | |||
| } catch(MallinkException e){ | |||
| logger.error("商圈授权通知---"+e.getMessage()); | |||
| resultMap.put("code","FAIL"); | |||
| return resultMap; | |||
| }catch (Exception e){ | |||
| e.printStackTrace(); | |||
| logger.error("商圈授权通知---其他异常"); | |||
| resultMap.put("code","FAIL"); | |||
| return resultMap; | |||
| } | |||
| } | |||
| /** | |||
| * | |||
| * @return 微信商圈支付通知 | |||
| @@ -0,0 +1,290 @@ | |||
| package com.iformall.controller.callback; | |||
| import com.github.binarywang.wxpay.bean.businesscircle.BusinessCircleNotifyData; | |||
| import com.github.binarywang.wxpay.bean.businesscircle.PaidResult; | |||
| import com.github.binarywang.wxpay.bean.businesscircle.RefundResult; | |||
| import com.github.binarywang.wxpay.bean.ecommerce.SignatureHeader; | |||
| import com.github.binarywang.wxpay.bean.membercard.MemberCardActivateResult; | |||
| import com.github.binarywang.wxpay.bean.membercard.MemberCardNotifyData; | |||
| import com.github.binarywang.wxpay.exception.WxPayException; | |||
| import com.github.binarywang.wxpay.service.WxPayService; | |||
| import com.iformall.controller.base.BaseController; | |||
| import com.iformall.domain.po.WxAppinfo; | |||
| import com.iformall.domain.po.WxBusinessCircleOrder; | |||
| import com.iformall.domain.po.WxMemberCard; | |||
| import com.iformall.domain.po.WxPayAccount; | |||
| import com.iformall.domain.po.base.TenantEntity; | |||
| import com.iformall.enums.EnumAppPlat; | |||
| import com.iformall.enums.EnumMemberCardActivateScene; | |||
| import com.iformall.enums.EnumMemberCardStatus; | |||
| import com.iformall.exception.MallinkException; | |||
| import com.iformall.pay.WxPayConstant; | |||
| import com.iformall.service.*; | |||
| import com.iformall.utils.MaUtil; | |||
| import org.apache.commons.lang3.StringUtils; | |||
| import org.slf4j.Logger; | |||
| import org.slf4j.LoggerFactory; | |||
| import org.springframework.beans.factory.annotation.Autowired; | |||
| import org.springframework.web.bind.annotation.*; | |||
| import javax.servlet.http.HttpServletRequest; | |||
| import java.io.BufferedReader; | |||
| import java.io.IOException; | |||
| import java.io.InputStream; | |||
| import java.io.InputStreamReader; | |||
| import java.text.ParseException; | |||
| import java.text.SimpleDateFormat; | |||
| import java.util.HashMap; | |||
| import java.util.Locale; | |||
| import java.util.Map; | |||
| @RestController | |||
| @RequestMapping("/member/card") | |||
| public class WxMemberCardController extends BaseController { | |||
| private final Logger logger = LoggerFactory.getLogger(this.getClass()); | |||
| private final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'+'mm:ss", Locale.CHINA); | |||
| @Autowired | |||
| WxMallService wxMallService; | |||
| @Autowired | |||
| WxAppinfoService wxAppinfoService; | |||
| @Autowired | |||
| WxPayAccountService wxPayAccountService; | |||
| @Autowired | |||
| WxMemberCardService wxMemberCardService; | |||
| @Autowired | |||
| MaUtil maUtil; | |||
| /** | |||
| * | |||
| * @return 微信会员卡通知 | |||
| */ | |||
| @PostMapping(value = "/notify/{tenantId}") | |||
| @ResponseBody | |||
| public Map<String,String> notify(@PathVariable String tenantId, HttpServletRequest request){ | |||
| logger.info("[" +getIpAddr() + "]微信会员卡通知-----"+tenantId); | |||
| Map<String,String> resultMap = new HashMap<>(); | |||
| if(StringUtils.isBlank(tenantId)){ | |||
| logger.error("tenantId为空"); | |||
| resultMap.put("code","FAIL"); | |||
| return resultMap; | |||
| } | |||
| TenantEntity tenantEntity = wxMallService.getByTenantId(tenantId); | |||
| if(tenantEntity == null){ | |||
| logger.error("获取tenantEntity为null"); | |||
| resultMap.put("code","FAIL"); | |||
| return resultMap; | |||
| } | |||
| SignatureHeader header = new SignatureHeader(); | |||
| header.setSerialNo(request.getHeader("Wechatpay-Serial")); | |||
| header.setTimeStamp(request.getHeader("Wechatpay-Timestamp")); | |||
| header.setNonce(request.getHeader("Wechatpay-Nonce")); | |||
| header.setSigned(request.getHeader("Wechatpay-Signature")); | |||
| logger.info("微信会员卡通知---header{}"+header.toString()); | |||
| try { | |||
| String body = this.getBody(request); | |||
| logger.info("微信会员卡通知---body{}"+body); | |||
| WxAppinfo cAppInfo = wxAppinfoService.getCAppInfoFromRedis(tenantId, EnumAppPlat.WX); | |||
| WxPayAccount payAccount = wxPayAccountService.getByIdFromRedis(cAppInfo.getPayId()); | |||
| if(cAppInfo == null || payAccount == null){ | |||
| resultMap.put("code","FAIL"); | |||
| return resultMap; | |||
| } | |||
| WxPayService wxPayService = maUtil.getWxPayService(cAppInfo, payAccount); | |||
| //----------------签名验证----------- | |||
| // BusinessCircleNotifyData notifyData = verifySignature(request,wxPayService); | |||
| MemberCardNotifyData notifyData = wxPayService.getMemberCardService().parseNotifyData(body, header); | |||
| logger.info("微信会员卡通知---回调通知对象{}"+notifyData.toString()); | |||
| MemberCardActivateResult result = wxPayService.getMemberCardService().decryptActivateNotifyDataResource(notifyData); | |||
| logger.info("微信会员卡通知---解密结果{}"+result.toString()); | |||
| WxMemberCard memberCard = new WxMemberCard(); | |||
| memberCard.updateTenantInfo(tenantEntity); | |||
| memberCard.setAppId(cAppInfo.getAppId()); | |||
| memberCard.setCardId(result.getCardId()); | |||
| memberCard.setCardCode(result.getCode()); | |||
| memberCard.setOpenId(result.getOpenid()); | |||
| memberCard.setUnionId(result.getUnionid()); | |||
| if(WxPayConstant.MEMBER_CARD_ACTIVATE.equals(result.getEventType())){ | |||
| memberCard.setUserCardStatus(EnumMemberCardStatus.EFFECTIVE.getCode()); | |||
| memberCard.setCreateDate(sdf.parse(result.getEventTime())); | |||
| memberCard.setActivateScene(EnumMemberCardActivateScene.getEnum(result.getActivateScene()).getCode()); | |||
| // memberCard.setOuterStr(result.getOuterStr()); | |||
| wxMemberCardService.saveorupdateByCode(memberCard); | |||
| resultMap.put("code","SUCCESS"); | |||
| return resultMap; | |||
| }else if(WxPayConstant.USER_VIEW_MEMBERCARD.equals(result.getEventType())){ | |||
| resultMap.put("code","SUCCESS"); | |||
| return resultMap; | |||
| }else if(WxPayConstant.USER_DELETE_MEMBERCARD.equals(result.getEventType())){ | |||
| memberCard.setUpdateDate(sdf.parse(result.getEventTime())); | |||
| memberCard.setUserCardStatus(EnumMemberCardStatus.DELETE.getCode()); | |||
| wxMemberCardService.delUserCardStatusByCode(memberCard); | |||
| resultMap.put("code","SUCCESS"); | |||
| return resultMap; | |||
| }else if(WxPayConstant.USER_MODIFY_INFORMATION.equals(result.getEventType())){//todo 暂未同步会员卡信息 | |||
| resultMap.put("code","SUCCESS"); | |||
| return resultMap; | |||
| } | |||
| resultMap.put("code","FAIL"); | |||
| return resultMap; | |||
| } catch (WxPayException e) { | |||
| e.printStackTrace(); | |||
| logger.error("微信会员卡通知---"+e.getCustomErrorMsg()); | |||
| resultMap.put("code","FAIL"); | |||
| return resultMap; | |||
| } catch (ParseException e) { | |||
| e.printStackTrace(); | |||
| logger.error("微信会员卡通知---时间转换异常"); | |||
| resultMap.put("code","FAIL"); | |||
| return resultMap; | |||
| } catch(MallinkException e){ | |||
| logger.error("微信会员卡通知---"+e.getMessage()); | |||
| resultMap.put("code","FAIL"); | |||
| return resultMap; | |||
| }catch (Exception e){ | |||
| e.printStackTrace(); | |||
| logger.error("微信会员卡通知---其他异常"); | |||
| resultMap.put("code","FAIL"); | |||
| return resultMap; | |||
| } | |||
| } | |||
| private String getBody(HttpServletRequest request) throws IOException { | |||
| StringBuilder stringBuilder = new StringBuilder(); | |||
| BufferedReader bufferedReader = null; | |||
| try { | |||
| InputStream inputStream = request.getInputStream(); | |||
| if (inputStream != null) { | |||
| bufferedReader = new BufferedReader(new InputStreamReader(inputStream,"utf-8")); | |||
| char[] charBuffer = new char[1024]; | |||
| int bytesRead = -1; | |||
| while ((bytesRead = bufferedReader.read(charBuffer)) > 0) { | |||
| stringBuilder.append(charBuffer, 0, bytesRead); | |||
| } | |||
| } else { | |||
| stringBuilder.append(""); | |||
| } | |||
| } catch ( | |||
| IOException ex) { | |||
| throw ex; | |||
| } finally { | |||
| if (bufferedReader != null) { | |||
| try { | |||
| bufferedReader.close(); | |||
| } catch (IOException ex) { | |||
| throw ex; | |||
| } | |||
| } | |||
| } | |||
| return stringBuilder.toString(); | |||
| } | |||
| // @PostMapping(value = "/test") | |||
| // @ResponseBody | |||
| // public void createOrdertests(){ | |||
| // | |||
| //// SignatureHeader(timeStamp=1627973486, nonce=pKGTNqxLaljN9jB5DprFagpmggWIhyBA, signed=gDmv1WDCGdlIyyW9bGDJuztWNritufRsiYt5bPfudpwvPA9hHWM47eFeZYzHpgxttnxyAL10XYbPK8SngtCHSeOghS4gXHuAQoWv3RlEkTHhIcf1eg+uD4zd4PsNqJ35YlW6RyYkjv/Y8didERnkvXZPvDrzP5DKsurLXvMJBs7mzVzt6QIgZa2DuVjnhmSk4aC3wPs7lqm8ElWsEblCr8k9RSrP92PFGSTnU5owAUrTMTL1kqfwzavzwVJxafAGkXxrHbybpP5qZ5DjttAhDkRI3L2xQfPvHAFyibnwk2N9KYC9H6AOuZIuku/9eRlan+ZMDln63gaPFfvl1OB7hg==, serialNo=76EEF0C28D079D9CED85C67237F173FF825CFAE7) | |||
| // | |||
| // SignatureHeader header = new SignatureHeader(); | |||
| // header.setSerialNo("76EEF0C28D079D9CED85C67237F173FF825CFAE7"); | |||
| // header.setTimeStamp("1627973486"); | |||
| // header.setNonce("pKGTNqxLaljN9jB5DprFagpmggWIhyBA"); | |||
| // header.setSigned("gDmv1WDCGdlIyyW9bGDJuztWNritufRsiYt5bPfudpwvPA9hHWM47eFeZYzHpgxttnxyAL10XYbPK8SngtCHSeOghS4gXHuAQoWv3RlEkTHhIcf1eg+uD4zd4PsNqJ35YlW6RyYkjv/Y8didERnkvXZPvDrzP5DKsurLXvMJBs7mzVzt6QIgZa2DuVjnhmSk4aC3wPs7lqm8ElWsEblCr8k9RSrP92PFGSTnU5owAUrTMTL1kqfwzavzwVJxafAGkXxrHbybpP5qZ5DjttAhDkRI3L2xQfPvHAFyibnwk2N9KYC9H6AOuZIuku/9eRlan+ZMDln63gaPFfvl1OB7hg=="); | |||
| // | |||
| // | |||
| // logger.info("微信商圈支付通知---header{}"+header.toString()); | |||
| // String tenantId = "1019"; | |||
| // TenantEntity tenantEntity = wxMallService.getByTenantId(tenantId); | |||
| // | |||
| // try { | |||
| // // {"id":"fe9f7590-89d3-588a-a5a3-f3ca5cb6e806","create_time":"2021-08-03T14:51:23+08:00","resource_type":"encrypt-resource","event_type":"MALL_TRANSACTION.SUCCESS","summary":"支付成功","resource":{"original_type":"mall_transaction","algorithm":"AEAD_AES_256_GCM","ciphertext":"T9VctVJB+7Zs0dhZnejwXNOvxHM/CfPt4S4C4cAtvSYsO2++8eVMN3dZky1/TLVg/mJtFBVHU4IiPavZMV+tULw3yKBs/JomTBHblb8De8GKU2/m03/wD3rxufdYejTnxXQWsdAEaWduM/zWCCtNIblayVE8Bz6p0cZtutk6jknYaDQk13sNGh1U12lpcElGf3i8LxLG0jWp+DBp2seOizBsjB8Cky/xEMjmd9OzbtrCd7K22ZtGv7gyA2C/9NY5gFT9tlcGFaD+BvOx69o7Sw1uHZ5IaXHTpI9SQlHCWCs8tGZtMZrlzgFLa/DI+TFkh//WYNcZRomhBydAbE4xQJqSWB5/81Rqa4gYT85YJPhgXRKGl+F0S/6jCYuL5cJpqUCojNz+g16znI8=","associated_data":"mall_transaction","nonce":"0GqZRhyTkcHG"}} | |||
| // | |||
| // String body = "{\"id\":\"fe9f7590-89d3-588a-a5a3-f3ca5cb6e806\",\"create_time\":\"2021-08-03T14:51:23+08:00\",\"resource_type\":\"encrypt-resource\",\"event_type\":\"MALL_TRANSACTION.SUCCESS\",\"summary\":\"支付成功\",\"resource\":{\"original_type\":\"mall_transaction\",\"algorithm\":\"AEAD_AES_256_GCM\",\"ciphertext\":\"T9VctVJB+7Zs0dhZnejwXNOvxHM/CfPt4S4C4cAtvSYsO2++8eVMN3dZky1/TLVg/mJtFBVHU4IiPavZMV+tULw3yKBs/JomTBHblb8De8GKU2/m03/wD3rxufdYejTnxXQWsdAEaWduM/zWCCtNIblayVE8Bz6p0cZtutk6jknYaDQk13sNGh1U12lpcElGf3i8LxLG0jWp+DBp2seOizBsjB8Cky/xEMjmd9OzbtrCd7K22ZtGv7gyA2C/9NY5gFT9tlcGFaD+BvOx69o7Sw1uHZ5IaXHTpI9SQlHCWCs8tGZtMZrlzgFLa/DI+TFkh//WYNcZRomhBydAbE4xQJqSWB5/81Rqa4gYT85YJPhgXRKGl+F0S/6jCYuL5cJpqUCojNz+g16znI8=\",\"associated_data\":\"mall_transaction\",\"nonce\":\"0GqZRhyTkcHG\"}}"; | |||
| // logger.info("微信商圈支付通知---body{}"+body); | |||
| // WxPayService wxPayService = wxPayAccountService.getWxPayService(tenantId); | |||
| // | |||
| // //----------------签名验证----------- | |||
| //// BusinessCircleNotifyData notifyData = verifySignature(request,wxPayService); | |||
| // BusinessCircleNotifyData notifyData = wxPayService.getBusinessCircleService().parseNotifyData(body, header); | |||
| // logger.info("微信商圈通知---回调通知对象{}"+notifyData.toString()); | |||
| // | |||
| // WxBusinessCircleOrder wxBusinessCircleOrder = new WxBusinessCircleOrder(); | |||
| // wxBusinessCircleOrder.updateTenantInfo(tenantEntity); | |||
| // wxBusinessCircleOrder.setNoticeId(notifyData.getId()); | |||
| // wxBusinessCircleOrder.setNoticeCreateTime(sdf.parse(notifyData.getCreateTime())); | |||
| // wxBusinessCircleOrder.setNoticeEventType(notifyData.getEventType()); | |||
| // wxBusinessCircleOrder.setSummary(notifyData.getSummary()); | |||
| // | |||
| // //解密 | |||
| // if(WxPayConstant.NOTICE_EVENT_TYPE.equals(notifyData.getEventType())){ | |||
| // PaidResult result = wxPayService.getBusinessCircleService().decryptPaidNotifyDataResource(notifyData); | |||
| // logger.info("微信商圈支付成功通知---解密结果{}"+result.toString()); | |||
| // | |||
| // wxBusinessCircleOrder.setWxMchid(result.getMchid()); | |||
| // wxBusinessCircleOrder.setWxMerchantName(result.getMerchantName()); | |||
| // wxBusinessCircleOrder.setWxShopName(result.getShopName()); | |||
| // wxBusinessCircleOrder.setWxShopNumber(result.getShopNumber()); | |||
| // wxBusinessCircleOrder.setAppid(result.getAppid()); | |||
| // wxBusinessCircleOrder.setOpenid(result.getOpenid()); | |||
| // wxBusinessCircleOrder.setTimeEnd(sdf.parse(result.getTimeEnd())); | |||
| // wxBusinessCircleOrder.setAmount(result.getAmount()); | |||
| // wxBusinessCircleOrder.setPayAmount(result.getAmount()); | |||
| // wxBusinessCircleOrder.setTransactionId(result.getTransactionId()); | |||
| // wxBusinessCircleOrder.setCommitTag(result.getCommitTag()); | |||
| // | |||
| // | |||
| // | |||
| // }else if(WxPayConstant.REFUND_EVENT_TYPE.equals(notifyData.getEventType())){ | |||
| // RefundResult result = wxPayService.getBusinessCircleService().decryptRefundNotifyDataResource(notifyData); | |||
| // logger.info("微信商圈退款成功通知---解密结果{}"+result.toString()); | |||
| // | |||
| // wxBusinessCircleOrder.setWxMchid(result.getMchid()); | |||
| // wxBusinessCircleOrder.setWxMerchantName(result.getMerchantName()); | |||
| // wxBusinessCircleOrder.setWxShopName(result.getShopName()); | |||
| // wxBusinessCircleOrder.setWxShopNumber(result.getShopNumber()); | |||
| // wxBusinessCircleOrder.setAppid(result.getAppid()); | |||
| // wxBusinessCircleOrder.setOpenid(result.getOpenid()); | |||
| // wxBusinessCircleOrder.setTimeEnd(sdf.parse(result.getRefundTime())); | |||
| // wxBusinessCircleOrder.setAmount(result.getPayAmount()); | |||
| // wxBusinessCircleOrder.setPayAmount(result.getPayAmount()); | |||
| // wxBusinessCircleOrder.setTransactionId(result.getTransactionId()); | |||
| // | |||
| // wxBusinessCircleOrder.setRefundAmount(result.getRefundAmount()); | |||
| // wxBusinessCircleOrder.setRefundId(result.getRefundId()); | |||
| // | |||
| // | |||
| // } | |||
| // | |||
| // } catch (WxPayException e) { | |||
| // e.printStackTrace(); | |||
| // logger.error("微信商圈通知---"+e.getCustomErrorMsg()); | |||
| // | |||
| // } catch (ParseException e) { | |||
| // e.printStackTrace(); | |||
| // logger.error("微信商圈通知---时间转换异常"); | |||
| // | |||
| // } catch(MallinkException e){ | |||
| // logger.error("微信商圈通知---"+e.getMessage()); | |||
| // | |||
| // }catch (Exception e){ | |||
| // e.printStackTrace(); | |||
| // logger.error("微信商圈通知---其他异常"); | |||
| // | |||
| // } | |||
| // } | |||
| } | |||
| @@ -88,6 +88,13 @@ public class BaseMyBatisConfiguration { | |||
| ttCUserSharding.setCount(100); | |||
| ttCUserSharding.setRule(EnumShardingRule.HASH.getCode()); | |||
| shardingList.add(ttCUserSharding); | |||
| ShardingSphere wxMemberCardSharding = new ShardingSphere(); | |||
| wxMemberCardSharding.setColumn("tenant_id"); | |||
| wxMemberCardSharding.setTableName("wx_member_card"); | |||
| wxMemberCardSharding.setCount(100); | |||
| wxMemberCardSharding.setRule(EnumShardingRule.HASH.getCode()); | |||
| shardingList.add(wxMemberCardSharding); | |||
| ShardingSphere basicInfoSharding = new ShardingSphere(); | |||
| basicInfoSharding.setColumn("final_tenant_id"); | |||
| @@ -0,0 +1,94 @@ | |||
| package com.iformall.domain.po; | |||
| import com.baomidou.mybatisplus.annotation.TableName; | |||
| import com.iformall.domain.po.base.TenantEntity; | |||
| import lombok.Data; | |||
| import lombok.EqualsAndHashCode; | |||
| import lombok.ToString; | |||
| import java.util.Date; | |||
| @TableName(value = "wx_member_card") | |||
| @Data | |||
| @ToString(callSuper = true) | |||
| @EqualsAndHashCode(callSuper = true) | |||
| public class WxMemberCard extends TenantEntity { | |||
| protected Long id; | |||
| @io.swagger.annotations.ApiModelProperty(value="会员卡ID",name="cardId") | |||
| private String cardId; | |||
| @io.swagger.annotations.ApiModelProperty(value="会员卡code",name="cardCode") | |||
| private String cardCode; | |||
| @io.swagger.annotations.ApiModelProperty(value="EnumMemberCardActivateScene 开卡场景",name="activateScene") | |||
| private Integer activateScene; | |||
| @io.swagger.annotations.ApiModelProperty(value="自定义场景",name="outerStr") | |||
| private Integer outerStr; | |||
| @io.swagger.annotations.ApiModelProperty(value="",name="openId") | |||
| private String openId; | |||
| @io.swagger.annotations.ApiModelProperty(value="",name="unionId") | |||
| private String unionId; | |||
| @io.swagger.annotations.ApiModelProperty(value="展示会员编号",name="membershipNumber") | |||
| private String membershipNumber; | |||
| @io.swagger.annotations.ApiModelProperty(value="会员等级",name="level") | |||
| private String level; | |||
| @io.swagger.annotations.ApiModelProperty(value="用户昵称",name="nickname") | |||
| private String nickname; | |||
| @io.swagger.annotations.ApiModelProperty(value="头像",name="headImageUrl") | |||
| private String headImageUrl; | |||
| @io.swagger.annotations.ApiModelProperty(value="会员卡背景",name="backgroundPictureUrl") | |||
| private String backgroundPictureUrl; | |||
| @io.swagger.annotations.ApiModelProperty(value="用户储值的最新余额,单位分",name="balance") | |||
| private Integer balance; | |||
| @io.swagger.annotations.ApiModelProperty(value="EnumMemberCardStatus 用户会员卡状态",name="userCardStatus") | |||
| private Integer userCardStatus; | |||
| @io.swagger.annotations.ApiModelProperty(value="用户开卡时填写的个人信息{}",name="userInformation") | |||
| private String userInformation; | |||
| @io.swagger.annotations.ApiModelProperty(value="用户当前的积分值",name="bonusValue") | |||
| private Integer bonusValue; | |||
| @io.swagger.annotations.ApiModelProperty(value="用户当前的会员服务项内容[]",name="serviceModules") | |||
| private String serviceModules; | |||
| @io.swagger.annotations.ApiModelProperty(value="用户会员卡详情页会员优惠栏目中的会员专享价文案",name="memberPriceWord") | |||
| private String memberPriceWord; | |||
| @io.swagger.annotations.ApiModelProperty(value="发票栏跳转小程序的引导文案",name="fapiaoJumpWord") | |||
| private String fapiaoJumpWord; | |||
| @io.swagger.annotations.ApiModelProperty(value="设置商家联系人员的名字、头像和联系方式[]",name="guide") | |||
| private String guide; | |||
| @io.swagger.annotations.ApiModelProperty(value="更新时间",name="updateDate") | |||
| private Date updateDate; | |||
| @io.swagger.annotations.ApiModelProperty(value="创建时间",name="createDate") | |||
| private Date createDate; | |||
| @io.swagger.annotations.ApiModelProperty(value="",name="appId") | |||
| private String appId; | |||
| @io.swagger.annotations.ApiModelProperty(value="EnumMemberCardAuthorizeState 授权商圈快速积分状态",name="authorizeState") | |||
| private Integer authorizeState; | |||
| @io.swagger.annotations.ApiModelProperty(value="授权时间",name="authorizeTime") | |||
| private Date authorizeTime; | |||
| @io.swagger.annotations.ApiModelProperty(value="取消授权时间",name="deauthorizeTime") | |||
| private Date deauthorizeTime; | |||
| } | |||
| @@ -97,6 +97,16 @@ public class WxPayAccount extends TenantEntity { | |||
| @io.swagger.annotations.ApiModelProperty(value="平台证书密钥文件",name="privateCertPemPath") | |||
| private String privateCertPemPath; | |||
| @io.swagger.annotations.ApiModelProperty(value="商圈版本",name="businessType") | |||
| private Integer businessType; | |||
| @io.swagger.annotations.ApiModelProperty(value="品牌ID",name="brandid") | |||
| private String brandid; | |||
| @io.swagger.annotations.ApiModelProperty(value="商圈会员卡ID",name="cardId") | |||
| private String cardId; | |||
| // @io.swagger.annotations.ApiModelProperty(value="app平台 EnumAppPlat ",name="plat") | |||
| // private Integer plat; | |||
| @@ -0,0 +1,37 @@ | |||
| package com.iformall.enums; | |||
| /** | |||
| * Created by Stormeye on 2018/08/09. | |||
| */ | |||
| public enum EnumBusinessType { | |||
| BUSINESS_0(0, "暂未开通"), | |||
| BUSINESS_1(1, "1.0"), | |||
| BUSINESS_2(2, "2.0"), | |||
| BUSINESS_3(3, "3.0"); | |||
| public static EnumBusinessType getEnum(Integer code) { | |||
| for (EnumBusinessType value : values()) { | |||
| if (value.getCode().equals(code)) { | |||
| return value; | |||
| } | |||
| } | |||
| return null; | |||
| } | |||
| private Integer code; | |||
| private String message; | |||
| EnumBusinessType(Integer code, String message) { | |||
| this.code = code; | |||
| this.message = message; | |||
| } | |||
| public Integer getCode() { | |||
| return code; | |||
| } | |||
| public String getMessage() { | |||
| return message; | |||
| } | |||
| } | |||
| @@ -0,0 +1,48 @@ | |||
| package com.iformall.enums; | |||
| /** | |||
| * . | |||
| */ | |||
| public enum EnumMemberCardActivateScene { | |||
| //NEW_ACTIVATE 新开卡激活 | |||
| //RECOVER 删卡后重新领取激活 | |||
| NEW_ACTIVATE(0, "NEW_ACTIVATE"), | |||
| RECOVER(1, "RECOVER") | |||
| ; | |||
| public static EnumMemberCardActivateScene getEnum(Integer code) { | |||
| for (EnumMemberCardActivateScene value : values()) { | |||
| if (value.getCode().equals(code)) { | |||
| return value; | |||
| } | |||
| } | |||
| return null; | |||
| } | |||
| public static EnumMemberCardActivateScene getEnum(String message) { | |||
| for (EnumMemberCardActivateScene value : values()) { | |||
| if (value.getMessage().equals(message)) { | |||
| return value; | |||
| } | |||
| } | |||
| return null; | |||
| } | |||
| private Integer code; | |||
| private String message; | |||
| EnumMemberCardActivateScene(Integer code, String message) { | |||
| this.code = code; | |||
| this.message = message; | |||
| } | |||
| public Integer getCode() { | |||
| return code; | |||
| } | |||
| public String getMessage() { | |||
| return message; | |||
| } | |||
| } | |||
| @@ -0,0 +1,48 @@ | |||
| package com.iformall.enums; | |||
| /** | |||
| * . | |||
| */ | |||
| public enum EnumMemberCardAuthorizeState { | |||
| //UNAUTHORIZED:未授权 | |||
| //AUTHORIZED:已授权 | |||
| //DEAUTHORIZED:已取消授权 | |||
| UNAUTHORIZED(0, "UNAUTHORIZED"), | |||
| AUTHORIZED(1, "AUTHORIZED"), | |||
| DEAUTHORIZED(2, "DEAUTHORIZED"), | |||
| ; | |||
| public static EnumMemberCardAuthorizeState getEnum(Integer code) { | |||
| for (EnumMemberCardAuthorizeState value : values()) { | |||
| if (value.getCode().equals(code)) { | |||
| return value; | |||
| } | |||
| } | |||
| return null; | |||
| } | |||
| public static EnumMemberCardAuthorizeState getEnum(String message) { | |||
| for (EnumMemberCardAuthorizeState value : values()) { | |||
| if (value.getMessage().equals(message)) { | |||
| return value; | |||
| } | |||
| } | |||
| return null; | |||
| } | |||
| private Integer code; | |||
| private String message; | |||
| EnumMemberCardAuthorizeState(Integer code, String message) { | |||
| this.code = code; | |||
| this.message = message; | |||
| } | |||
| public Integer getCode() { | |||
| return code; | |||
| } | |||
| public String getMessage() { | |||
| return message; | |||
| } | |||
| } | |||
| @@ -0,0 +1,54 @@ | |||
| package com.iformall.enums; | |||
| /** | |||
| * . | |||
| */ | |||
| public enum EnumMemberCardStatus { | |||
| //NOT_ACTIVATE:未激活 | |||
| //EFFECTIVE:生效中 | |||
| //EXPIRE:已过期 | |||
| //UNAVAILABLE:已失效 | |||
| //DELETE:已删除 | |||
| //IMPORTED:已导入 | |||
| NOT_ACTIVATE(0, "NOT_ACTIVATE"), | |||
| EFFECTIVE(1, "EFFECTIVE"), | |||
| EXPIRE(2, "EFFECTIVE"), | |||
| UNAVAILABLE(3, "EFFECTIVE"), | |||
| DELETE(4, "EFFECTIVE"), | |||
| IMPORTED(5, "EFFECTIVE"), | |||
| ; | |||
| public static EnumMemberCardStatus getEnum(Integer code) { | |||
| for (EnumMemberCardStatus value : values()) { | |||
| if (value.getCode().equals(code)) { | |||
| return value; | |||
| } | |||
| } | |||
| return null; | |||
| } | |||
| public static EnumMemberCardStatus getEnum(String message) { | |||
| for (EnumMemberCardStatus value : values()) { | |||
| if (value.getMessage().equals(message)) { | |||
| return value; | |||
| } | |||
| } | |||
| return null; | |||
| } | |||
| private Integer code; | |||
| private String message; | |||
| EnumMemberCardStatus(Integer code, String message) { | |||
| this.code = code; | |||
| this.message = message; | |||
| } | |||
| public Integer getCode() { | |||
| return code; | |||
| } | |||
| public String getMessage() { | |||
| return message; | |||
| } | |||
| } | |||
| @@ -0,0 +1,17 @@ | |||
| package com.iformall.mapper; | |||
| import com.iformall.common.CommonMapper; | |||
| import com.iformall.domain.po.WxMemberCard; | |||
| import java.util.List; | |||
| public interface WxMemberCardMapper extends CommonMapper<WxMemberCard, Long> { | |||
| List<WxMemberCard> findList(WxMemberCard record); | |||
| int deleteByCode(WxMemberCard record); | |||
| Long getIdByCode(WxMemberCard record); | |||
| int updateByOpenId(WxMemberCard record); | |||
| } | |||
| @@ -5,6 +5,17 @@ public class WxPayConstant { | |||
| public static final String NOTICE_EVENT_TYPE = "MALL_TRANSACTION.SUCCESS"; | |||
| public static final String REFUND_EVENT_TYPE = "MALL_REFUND.SUCCESS"; | |||
| //微信会员卡 | |||
| public static final String MEMBER_CARD_ACTIVATE = "MEMBER_CARD_ACTIVATE";//激活会员卡 | |||
| public static final String USER_VIEW_MEMBERCARD = "USER_VIEW_MEMBERCARD";//用户查看会员卡详情 | |||
| public static final String USER_DELETE_MEMBERCARD = "USER_DELETE_MEMBERCARD";//用户删除会员卡 | |||
| public static final String USER_MODIFY_INFORMATION = "USER_MODIFY_INFORMATION";//用户修改个人信息 | |||
| //微信商圈授权 | |||
| public static final String REGISTERED_MODE = "REGISTERED_MODE";//会员开卡(进卡包) + 未授权会员积分服务 | |||
| public static final String REGISTERED_AND_AUTHORIZATION_MODE = "REGISTERED_AND_AUTHORIZATION_MODE";//会员开卡(进卡包)+授权会员积分服务 | |||
| public final static String REQ_KEY = "reqKey"; | |||
| public final static String RES_KEY = "resKey"; | |||
| @@ -167,4 +178,7 @@ public class WxPayConstant { | |||
| public final static String NEU_ORDER_PAY = "0"; // 有效, 优惠券从预核销处理为核销, 卡从预支付->支付 | |||
| public final static String NEU_ORDER_REFUND = "1"; // 取消 | |||
| public final static String CAR_IN = "IN"; // 入场,用户开车进入商圈 | |||
| public final static String CAR_OUT = "OUT"; // 离场,用户开车离开商圈 | |||
| } | |||
| @@ -61,4 +61,18 @@ public interface WxBusinessCircleOrderService { | |||
| Integer sumCirclePayment(BusinessCircleBase circleOrder); | |||
| Integer sumCircleRefundAmount(BusinessCircleBase circleOrder); | |||
| /** | |||
| * 查询待积分状态 | |||
| */ | |||
| ResultData getPointsCommitStatus(TenantEntity tenantEntity,String openId); | |||
| /** | |||
| * 商圈同步停车状态 | |||
| * state | |||
| * IN:入场,用户开车进入商圈 | |||
| * OUT:离场,用户开车离开商圈 | |||
| */ | |||
| ResultData syncParkings(TenantEntity tenantEntity,String openId,String plate_number,String state,Date time); | |||
| } | |||
| @@ -0,0 +1,47 @@ | |||
| package com.iformall.service; | |||
| import com.github.pagehelper.PageInfo; | |||
| import com.iformall.common.ResultData; | |||
| import com.iformall.domain.po.WxMemberCard; | |||
| import com.iformall.domain.po.base.TenantEntity; | |||
| public interface WxMemberCardService { | |||
| /** | |||
| * 根据实体查询分页列表 | |||
| * | |||
| * @param record | |||
| * @param pageIndex | |||
| * @param pageSize | |||
| * @return | |||
| */ | |||
| PageInfo<WxMemberCard> listAsPage(WxMemberCard record, Integer pageIndex, Integer pageSize); | |||
| ResultData saveorupdateByCode(WxMemberCard record); | |||
| ResultData delUserCardStatusByCode(WxMemberCard record); | |||
| /** | |||
| * 同步会员卡卡信息 | |||
| */ | |||
| ResultData syncMemberCard(TenantEntity tenantEntity,String card_id,String code); | |||
| /** | |||
| * 同步会员卡等级 | |||
| * need_inform_level 是否发送等级变更通知 | |||
| */ | |||
| ResultData syncMemberCardLevel(TenantEntity tenantEntity,String card_id,String code, | |||
| String level,Boolean need_inform_level); | |||
| /** | |||
| * 更新会员卡积分 | |||
| */ | |||
| ResultData syncMemberCardBonus(TenantEntity tenantEntity,String card_id,String code, | |||
| Integer bonus_value,Boolean need_inform_bonus); | |||
| /** | |||
| * 同步授权快速积分 | |||
| */ | |||
| ResultData syncauthorizeState(TenantEntity tenantEntity,String openid); | |||
| } | |||
| @@ -1,5 +1,9 @@ | |||
| package com.iformall.service.impl; | |||
| import com.github.binarywang.wxpay.bean.businesscircle.ParkingNotifyRequest; | |||
| import com.github.binarywang.wxpay.bean.businesscircle.PointsCommitStatusResult; | |||
| import com.github.binarywang.wxpay.exception.WxPayException; | |||
| import com.github.binarywang.wxpay.service.WxPayService; | |||
| import com.github.pagehelper.PageHelper; | |||
| import com.github.pagehelper.PageInfo; | |||
| import com.iformall.common.ErrorCode; | |||
| @@ -11,6 +15,8 @@ import com.iformall.enums.*; | |||
| import com.iformall.exception.MallinkException; | |||
| import com.iformall.mapper.WxBusinessCircleOrderMapper; | |||
| import com.iformall.service.*; | |||
| import com.iformall.utils.DateUtils; | |||
| import com.iformall.utils.MaUtil; | |||
| import com.iformall.utils.RedisLock; | |||
| import org.apache.commons.lang3.StringUtils; | |||
| import org.slf4j.Logger; | |||
| @@ -60,6 +66,15 @@ public class WxBusinessCircleOrderServiceImpl implements WxBusinessCircleOrderSe | |||
| @Autowired | |||
| WxCouponSendService wxCouponSendService; | |||
| @Autowired | |||
| WxAppinfoService wxAppinfoService; | |||
| @Autowired | |||
| WxPayAccountService wxPayAccountService; | |||
| @Autowired | |||
| MaUtil maUtil; | |||
| @Override | |||
| public PageInfo<WxBusinessCircleOrder> listAsPage(WxBusinessCircleOrder record, Integer pageIndex, Integer pageSize) { | |||
| @@ -390,5 +405,54 @@ public class WxBusinessCircleOrderServiceImpl implements WxBusinessCircleOrderSe | |||
| return sumCircleRefundAmount==null?0:sumCircleRefundAmount; | |||
| } | |||
| @Override | |||
| public ResultData getPointsCommitStatus(TenantEntity tenantEntity, String openId) { | |||
| WxAppinfo cAppInfo = wxAppinfoService.getCAppInfoFromRedis(tenantEntity.getTenantId(), EnumAppPlat.WX); | |||
| WxPayAccount payAccount = wxPayAccountService.getByIdFromRedis(cAppInfo.getPayId()); | |||
| if(cAppInfo == null || payAccount == null){ | |||
| return new ResultData(ErrorCode.APP_ID_NOT_FOUND); | |||
| } | |||
| if(!EnumBusinessType.BUSINESS_3.getCode().equals(payAccount.getBusinessType())){ | |||
| return new ResultData(ErrorCode.SYS_SERVER_ERROR.getCode(),"未开通商圈或不支持此项操作"); | |||
| } | |||
| try { | |||
| WxPayService wxPayService = maUtil.getWxPayService(cAppInfo, payAccount); | |||
| PointsCommitStatusResult pointsCommitStatus = wxPayService.getBusinessCircleService().getPointsCommitStatus(payAccount.getBrandid(), openId); | |||
| return new ResultData(pointsCommitStatus); | |||
| } catch (WxPayException e) { | |||
| e.printStackTrace(); | |||
| return new ResultData(ErrorCode.SYS_SERVER_ERROR.getCode(),e.getMessage()); | |||
| } | |||
| } | |||
| @Override | |||
| public ResultData syncParkings(TenantEntity tenantEntity, String openId, String plate_number, String state, Date time) { | |||
| WxAppinfo cAppInfo = wxAppinfoService.getCAppInfoFromRedis(tenantEntity.getTenantId(), EnumAppPlat.WX); | |||
| WxPayAccount payAccount = wxPayAccountService.getByIdFromRedis(cAppInfo.getPayId()); | |||
| if(cAppInfo == null || payAccount == null){ | |||
| return new ResultData(ErrorCode.APP_ID_NOT_FOUND); | |||
| } | |||
| if(!EnumBusinessType.BUSINESS_3.getCode().equals(payAccount.getBusinessType())){ | |||
| return new ResultData(ErrorCode.SYS_SERVER_ERROR.getCode(),"未开通商圈或不支持此项操作"); | |||
| } | |||
| try { | |||
| WxPayService wxPayService = maUtil.getWxPayService(cAppInfo, payAccount); | |||
| ParkingNotifyRequest request = new ParkingNotifyRequest(); | |||
| request.setBrandid(payAccount.getBrandid()); | |||
| request.setOpenid(openId); | |||
| request.setPlateNumber(plate_number); | |||
| request.setState(state); | |||
| String formaStr = "yyyy-MM-dd'T'HH:mm:ss'+'mm:ss"; | |||
| request.setTime(DateUtils.date2String(time,formaStr)); | |||
| wxPayService.getBusinessCircleService().notifyParkings(request); | |||
| return new ResultData(); | |||
| } catch (WxPayException e) { | |||
| e.printStackTrace(); | |||
| return new ResultData(ErrorCode.SYS_SERVER_ERROR.getCode(),e.getMessage()); | |||
| } | |||
| } | |||
| } | |||
| @@ -0,0 +1,218 @@ | |||
| package com.iformall.service.impl; | |||
| import com.alibaba.fastjson.JSON; | |||
| import com.github.binarywang.wxpay.bean.businesscircle.MemberCardAuthorizeResult; | |||
| import com.github.binarywang.wxpay.bean.membercard.MemberCardResult; | |||
| import com.github.binarywang.wxpay.bean.membercard.MemberCardRightsRequest; | |||
| import com.github.binarywang.wxpay.bean.membercard.MemberCardUpdRequest; | |||
| import com.github.binarywang.wxpay.exception.WxPayException; | |||
| import com.github.binarywang.wxpay.service.WxPayService; | |||
| import com.github.pagehelper.PageHelper; | |||
| import com.github.pagehelper.PageInfo; | |||
| import com.iformall.common.ErrorCode; | |||
| import com.iformall.common.IdWorker; | |||
| import com.iformall.common.ResultData; | |||
| import com.iformall.domain.po.*; | |||
| import com.iformall.domain.po.base.TenantEntity; | |||
| import com.iformall.enums.*; | |||
| import com.iformall.mapper.WxMemberCardMapper; | |||
| import com.iformall.service.*; | |||
| import com.iformall.utils.DateUtils; | |||
| import com.iformall.utils.MaUtil; | |||
| import org.slf4j.Logger; | |||
| import org.slf4j.LoggerFactory; | |||
| import org.springframework.beans.factory.annotation.Autowired; | |||
| import org.springframework.stereotype.Service; | |||
| import java.util.Date; | |||
| @Service | |||
| public class WxMemberCardServiceImpl implements WxMemberCardService { | |||
| private final Logger logger = LoggerFactory.getLogger(this.getClass()); | |||
| @Autowired | |||
| WxMemberCardMapper wxMemberCardMapper; | |||
| @Autowired | |||
| WxAppinfoService wxAppinfoService; | |||
| @Autowired | |||
| WxPayAccountService wxPayAccountService; | |||
| @Autowired | |||
| MaUtil maUtil; | |||
| @Override | |||
| public PageInfo<WxMemberCard> listAsPage(WxMemberCard record, Integer pageIndex, Integer pageSize) { | |||
| return PageHelper.startPage(pageIndex, pageSize).doSelectPageInfo(() -> wxMemberCardMapper.findList(record)); | |||
| } | |||
| @Override | |||
| public ResultData saveorupdateByCode(WxMemberCard record) { | |||
| Long id = wxMemberCardMapper.getIdByCode(record); | |||
| Date now = new Date(); | |||
| if(id == null){ | |||
| final IdWorker idWorker = IdWorker.get(); | |||
| id = idWorker.nextId(); | |||
| record.setId(id); | |||
| if(record.getCreateDate() == null){ | |||
| record.setCreateDate(now); | |||
| } | |||
| record.setUpdateDate(record.getCreateDate()); | |||
| wxMemberCardMapper.insert(record); | |||
| }else{ | |||
| record.setId(id); | |||
| if(record.getUpdateDate() == null){ | |||
| record.setUpdateDate(now); | |||
| } | |||
| wxMemberCardMapper.updateById(record); | |||
| } | |||
| return new ResultData(); | |||
| } | |||
| @Override | |||
| public ResultData delUserCardStatusByCode(WxMemberCard record) { | |||
| record.setUserCardStatus(EnumMemberCardStatus.DELETE.getCode()); | |||
| if(record.getUpdateDate() == null){ | |||
| record.setUpdateDate(new Date()); | |||
| } | |||
| wxMemberCardMapper.deleteByCode(record); | |||
| return new ResultData(); | |||
| } | |||
| @Override | |||
| public ResultData syncMemberCard(TenantEntity tenantEntity, String card_id, String code) { | |||
| WxAppinfo cAppInfo = wxAppinfoService.getCAppInfoFromRedis(tenantEntity.getTenantId(), EnumAppPlat.WX); | |||
| WxPayAccount payAccount = wxPayAccountService.getByIdFromRedis(cAppInfo.getPayId()); | |||
| if(cAppInfo == null || payAccount == null){ | |||
| return new ResultData(ErrorCode.APP_ID_NOT_FOUND); | |||
| } | |||
| if(!EnumBusinessType.BUSINESS_3.getCode().equals(payAccount.getBusinessType())){ | |||
| return new ResultData(ErrorCode.SYS_SERVER_ERROR.getCode(),"未开通商圈或不支持此项操作"); | |||
| } | |||
| try { | |||
| WxPayService wxPayService = maUtil.getWxPayService(cAppInfo, payAccount); | |||
| MemberCardResult memberCard = wxPayService.getMemberCardService().getMemberCard(card_id, code); | |||
| WxMemberCard record = new WxMemberCard(); | |||
| record.updateTenantInfo(tenantEntity); | |||
| record.setCardId(card_id); | |||
| record.setCardCode(code); | |||
| record.setOpenId(memberCard.getOpenid()); | |||
| record.setMembershipNumber(memberCard.getMembershipNumber()); | |||
| record.setLevel(memberCard.getLevel()); | |||
| record.setNickname(memberCard.getNickname()); | |||
| record.setHeadImageUrl(memberCard.getHeadImageUrl()); | |||
| record.setBackgroundPictureUrl(memberCard.getBackgroundPictureUrl()); | |||
| record.setBalance(memberCard.getBalance()); | |||
| EnumMemberCardStatus enumMemberCardStatus = EnumMemberCardStatus.getEnum(memberCard.getUserCardStatus()); | |||
| if(enumMemberCardStatus != null){ | |||
| record.setUserCardStatus(enumMemberCardStatus.getCode()); | |||
| } | |||
| if(memberCard.getUserInformation() != null){ | |||
| record.setUserInformation(JSON.toJSONString(memberCard.getUserInformation())); | |||
| } | |||
| record.setBonusValue(memberCard.getBonusValue()); | |||
| if(memberCard.getServiceModules() != null){ | |||
| record.setServiceModules(JSON.toJSONString(memberCard.getServiceModules())); | |||
| } | |||
| record.setMemberPriceWord(memberCard.getMemberPriceWord()); | |||
| record.setFapiaoJumpWord(memberCard.getFapiaoJumpWord()); | |||
| if(memberCard.getGuide() != null){ | |||
| record.setGuide(JSON.toJSONString(memberCard.getGuide())); | |||
| } | |||
| this.saveorupdateByCode(record); | |||
| return new ResultData(); | |||
| } catch (WxPayException e) { | |||
| e.printStackTrace(); | |||
| return new ResultData(ErrorCode.SYS_SERVER_ERROR.getCode(),e.getMessage()); | |||
| } | |||
| } | |||
| @Override | |||
| public ResultData syncMemberCardLevel(TenantEntity tenantEntity, String card_id, String code, | |||
| String level, Boolean need_inform_level) { | |||
| WxAppinfo cAppInfo = wxAppinfoService.getCAppInfoFromRedis(tenantEntity.getTenantId(), EnumAppPlat.WX); | |||
| WxPayAccount payAccount = wxPayAccountService.getByIdFromRedis(cAppInfo.getPayId()); | |||
| if(cAppInfo == null || payAccount == null){ | |||
| return new ResultData(ErrorCode.APP_ID_NOT_FOUND); | |||
| } | |||
| if(!EnumBusinessType.BUSINESS_3.getCode().equals(payAccount.getBusinessType())){ | |||
| return new ResultData(ErrorCode.SYS_SERVER_ERROR.getCode(),"未开通商圈或不支持此项操作"); | |||
| } | |||
| try { | |||
| WxPayService wxPayService = maUtil.getWxPayService(cAppInfo, payAccount); | |||
| MemberCardUpdRequest request = new MemberCardUpdRequest(); | |||
| request.setLevel(level); | |||
| request.setOutRequestNo(getOutRequestNo()); | |||
| request.setNeedInformLevel(need_inform_level); | |||
| wxPayService.getMemberCardService().updMemberCard(card_id,code,request); | |||
| return new ResultData(); | |||
| } catch (WxPayException e) { | |||
| e.printStackTrace(); | |||
| return new ResultData(ErrorCode.SYS_SERVER_ERROR.getCode(),e.getMessage()); | |||
| } | |||
| } | |||
| @Override | |||
| public ResultData syncMemberCardBonus(TenantEntity tenantEntity, String card_id, String code, | |||
| Integer bonus_value, Boolean need_inform_bonus) { | |||
| WxAppinfo cAppInfo = wxAppinfoService.getCAppInfoFromRedis(tenantEntity.getTenantId(), EnumAppPlat.WX); | |||
| WxPayAccount payAccount = wxPayAccountService.getByIdFromRedis(cAppInfo.getPayId()); | |||
| if(cAppInfo == null || payAccount == null){ | |||
| return new ResultData(ErrorCode.APP_ID_NOT_FOUND); | |||
| } | |||
| if(!EnumBusinessType.BUSINESS_3.getCode().equals(payAccount.getBusinessType())){ | |||
| return new ResultData(ErrorCode.SYS_SERVER_ERROR.getCode(),"未开通商圈或不支持此项操作"); | |||
| } | |||
| try { | |||
| WxPayService wxPayService = maUtil.getWxPayService(cAppInfo, payAccount); | |||
| MemberCardRightsRequest request = new MemberCardRightsRequest(); | |||
| request.setBonusValue(bonus_value); | |||
| request.setOutRequestNo(getOutRequestNo()); | |||
| request.setNeedInformBonus(need_inform_bonus); | |||
| wxPayService.getMemberCardService().setMemberCardRights(card_id,code,request); | |||
| return new ResultData(); | |||
| } catch (WxPayException e) { | |||
| e.printStackTrace(); | |||
| return new ResultData(ErrorCode.SYS_SERVER_ERROR.getCode(),e.getMessage()); | |||
| } | |||
| } | |||
| private String getOutRequestNo(){ | |||
| final IdWorker idWorker = IdWorker.get(); | |||
| String dateStr = DateUtils.date2String(new Date(), "yyyyMMddHHmmss"); | |||
| String id = Long.toString(idWorker.nextId()); | |||
| return dateStr+"_"+id; | |||
| } | |||
| @Override | |||
| public ResultData syncauthorizeState(TenantEntity tenantEntity, String openid) { | |||
| WxAppinfo cAppInfo = wxAppinfoService.getCAppInfoFromRedis(tenantEntity.getTenantId(), EnumAppPlat.WX); | |||
| WxPayAccount payAccount = wxPayAccountService.getByIdFromRedis(cAppInfo.getPayId()); | |||
| if(cAppInfo == null || payAccount == null){ | |||
| return new ResultData(ErrorCode.APP_ID_NOT_FOUND); | |||
| } | |||
| if(!EnumBusinessType.BUSINESS_3.getCode().equals(payAccount.getBusinessType())){ | |||
| return new ResultData(ErrorCode.SYS_SERVER_ERROR.getCode(),"未开通商圈或不支持此项操作"); | |||
| } | |||
| try { | |||
| WxPayService wxPayService = maUtil.getWxPayService(cAppInfo, payAccount); | |||
| MemberCardAuthorizeResult authorizations = wxPayService.getBusinessCircleService().getAuthorizations(openid); | |||
| WxMemberCard record = new WxMemberCard(); | |||
| record.updateTenantInfo(tenantEntity); | |||
| record.setOpenId(authorizations.getOpenid()); | |||
| record.setAuthorizeState(EnumMemberCardAuthorizeState.getEnum(authorizations.getAuthorizeState()).getCode()); | |||
| String formaStr = "yyyy-MM-dd'T'HH:mm:ss'+'mm:ss"; | |||
| record.setAuthorizeTime(DateUtils.stringToDate(authorizations.getAuthorizeTime(),formaStr)); | |||
| record.setDeauthorizeTime(DateUtils.stringToDate(authorizations.getDeauthorizeTime(),formaStr)); | |||
| wxMemberCardMapper.updateByOpenId(record); | |||
| return new ResultData(record); | |||
| } catch (WxPayException e) { | |||
| e.printStackTrace(); | |||
| return new ResultData(ErrorCode.SYS_SERVER_ERROR.getCode(),e.getMessage()); | |||
| } | |||
| } | |||
| } | |||
| @@ -101,10 +101,10 @@ public class WxPayAccountServiceImpl implements WxPayAccountService { | |||
| @Override | |||
| public WxPayService getWxPayService(String tenantId) { | |||
| TenantEntity tenantEntity = new TenantEntity(); | |||
| tenantEntity.setTenantId(tenantId); | |||
| WxAppinfo cAppInfo = wxAppinfoService.getCAppInfo(tenantEntity, EnumAppPlat.WX); | |||
| WxPayAccount payAccount = this.getById(cAppInfo.getPayId()); | |||
| // TenantEntity tenantEntity = new TenantEntity(); | |||
| // tenantEntity.setTenantId(tenantId); | |||
| WxAppinfo cAppInfo = wxAppinfoService.getCAppInfoFromRedis(tenantId, EnumAppPlat.WX); | |||
| WxPayAccount payAccount = this.getByIdFromRedis(cAppInfo.getPayId()); | |||
| if(cAppInfo != null && payAccount != null){ | |||
| return maUtil.getWxPayService(cAppInfo,payAccount); | |||
| }else{ | |||
| @@ -0,0 +1,133 @@ | |||
| <?xml version="1.0" encoding="UTF-8"?> | |||
| <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> | |||
| <mapper namespace="com.iformall.mapper.WxMemberCardMapper"> | |||
| <resultMap id="BaseResultMap" type="com.iformall.domain.po.WxMemberCard"> | |||
| <id column="id" jdbcType="BIGINT" property="id"/> | |||
| <result column="tenant_id" jdbcType="VARCHAR" property="tenantId"/> | |||
| <result column="parent_tenant_id" jdbcType="VARCHAR" property="parentTenantId"/> | |||
| <result column="card_id" jdbcType="VARCHAR" property="cardId"/> | |||
| <result column="card_code" jdbcType="VARCHAR" property="cardCode"/> | |||
| <result column="activate_scene" jdbcType="INTEGER" property="activateScene"/> | |||
| <result column="outer_str" jdbcType="INTEGER" property="outerStr"/> | |||
| <result column="open_id" jdbcType="VARCHAR" property="openId"/> | |||
| <result column="union_id" jdbcType="VARCHAR" property="unionId"/> | |||
| <result column="membership_number" jdbcType="VARCHAR" property="membershipNumber"/> | |||
| <result column="level" jdbcType="VARCHAR" property="level"/> | |||
| <result column="nickname" jdbcType="VARCHAR" property="nickname"/> | |||
| <result column="head_image_url" jdbcType="VARCHAR" property="headImageUrl"/> | |||
| <result column="background_picture_url" jdbcType="VARCHAR" property="backgroundPictureUrl"/> | |||
| <result column="balance" jdbcType="INTEGER" property="balance"/> | |||
| <result column="user_card_status" jdbcType="INTEGER" property="userCardStatus"/> | |||
| <result column="user_information" jdbcType="VARCHAR" property="userInformation"/> | |||
| <result column="bonus_value" jdbcType="INTEGER" property="bonusValue"/> | |||
| <result column="service_modules" jdbcType="VARCHAR" property="serviceModules"/> | |||
| <result column="member_price_word" jdbcType="VARCHAR" property="memberPriceWord"/> | |||
| <result column="fapiao_jump_word" jdbcType="VARCHAR" property="fapiaoJumpWord"/> | |||
| <result column="guide" jdbcType="VARCHAR" property="guide"/> | |||
| <result column="update_date" jdbcType="TIMESTAMP" property="updateDate"/> | |||
| <result column="create_date" jdbcType="TIMESTAMP" property="createDate"/> | |||
| <result column="app_id" jdbcType="VARCHAR" property="appId"/> | |||
| <result column="authorize_state" jdbcType="INTEGER" property="authorizeState"/> | |||
| <result column="authorize_time" jdbcType="TIMESTAMP" property="authorizeTime"/> | |||
| <result column="deauthorize_time" jdbcType="TIMESTAMP" property="deauthorizeTime"/> | |||
| </resultMap> | |||
| <sql id="allColumns"> | |||
| `id`,`tenant_id`,`parent_tenant_id`,`card_id`,`card_code`,`activate_scene`,`outer_str`,`open_id`,`union_id`, | |||
| `membership_number`,`level`,`nickname`,`head_image_url`,`background_picture_url`,`balance`, | |||
| `user_card_status`,`user_information`,`bonus_value`,`service_modules`,`member_price_word`,`fapiao_jump_word`, | |||
| `guide`,`update_date`,`create_date`,`app_id`,`authorize_state`,`authorize_time`, `deauthorize_time` | |||
| </sql> | |||
| <sql id="dynamicWhereConditions"> | |||
| where 1 = 1 | |||
| <if test=" null != id "> | |||
| and `id` = #{id} | |||
| </if> | |||
| <if test=" null != tenantId and '' != tenantId"> | |||
| and `tenant_id` = #{tenantId} | |||
| </if> | |||
| <if test=" null != parentTenantId and '' != parentTenantId"> | |||
| and `parent_tenant_id` = #{parentTenantId} | |||
| </if> | |||
| <if test=" null != cardId and '' != cardId"> | |||
| and `card_id` = #{cardId} | |||
| </if> | |||
| <if test=" null != cardCode and '' != cardCode"> | |||
| and `card_code` = #{cardCode} | |||
| </if> | |||
| <if test=" null != activateScene "> | |||
| and `activate_scene` = #{activateScene} | |||
| </if> | |||
| <if test=" null != outerStr "> | |||
| and `outer_str` = #{outerStr} | |||
| </if> | |||
| <if test=" null != openId and '' != openId"> | |||
| and `open_id` = #{openId} | |||
| </if> | |||
| <if test=" null != unionId and '' != unionId"> | |||
| and `union_id` = #{unionId} | |||
| </if> | |||
| <if test=" null != membershipnNumber and '' != membershipnNumber"> | |||
| and `membership_number` = #{membershipnNumber} | |||
| </if> | |||
| <if test=" null != userCardStatus "> | |||
| and `user_card_status` = #{userCardStatus} | |||
| </if> | |||
| <if test=" null != appId and '' != appId"> | |||
| and `app_id` = #{appId} | |||
| </if> | |||
| <if test=" null != authorizeState "> | |||
| and `authorize_state` = #{authorizeState} | |||
| </if> | |||
| <if test=" null != ids "> | |||
| and id in | |||
| <foreach collection="ids" index="index" item="idItem" open="(" separator="," close=")"> | |||
| #{idItem} | |||
| </foreach> | |||
| </if> | |||
| <if test=" null != sortColumns">order by ${sortColumns}</if> | |||
| </sql> | |||
| <select id="findList" parameterType="com.iformall.domain.po.WxMemberCard" resultMap="BaseResultMap"> | |||
| select | |||
| <include refid="allColumns"/> | |||
| from wx_member_card | |||
| <include refid="dynamicWhereConditions"/> | |||
| </select> | |||
| <select id="getIdByCode" parameterType="com.iformall.domain.po.WxMemberCard" resultType="Long"> | |||
| select id from wx_member_card | |||
| where `tenant_id` = #{tenantId} | |||
| and `card_id` = #{cardId} | |||
| and `card_code` = #{cardCode} | |||
| </select> | |||
| <update id="deleteByCode" parameterType="com.iformall.domain.po.WxMemberCard"> | |||
| update wx_member_card set `user_card_status` = #{userCardStatus},`update_date` = #{updateDate} | |||
| WHERE `tenant_id` = #{tenantId} | |||
| and `card_id` = #{cardId} | |||
| and `card_code` = #{cardCode} | |||
| and `open_id` = #{openId} | |||
| </update> | |||
| <update id="updateByOpenId" parameterType="com.iformall.domain.po.WxMemberCard"> | |||
| update wx_member_card set `authorize_state` = #{authorizeState},`authorize_time` = #{authorizeTime},`deauthorize_time` = #{deauthorizeTime} | |||
| WHERE `tenant_id` = #{tenantId} | |||
| and `open_id` = #{openId} | |||
| </update> | |||
| </mapper> | |||
| @@ -34,13 +34,17 @@ | |||
| <result column="cert_serial_no" jdbcType="VARCHAR" property="certSerialNo"/> | |||
| <result column="private_key_path" jdbcType="VARCHAR" property="privateKeyPath"/> | |||
| <result column="private_cert_pem_path" jdbcType="VARCHAR" property="privateCertPemPath"/> | |||
| <result column="business_type" jdbcType="INTEGER" property="businessType"/> | |||
| <result column="brandid" jdbcType="VARCHAR" property="brandid"/> | |||
| <result column="card_id" jdbcType="VARCHAR" property="cardId"/> | |||
| </resultMap> | |||
| <sql id="allColumns"> | |||
| `id`,`tenant_id`,`parent_tenant_id`,`mch_id`,`sub_mch_id`,`sub_app_id`,`api_key`,`merchant_api_key`,`notify_url`,`notify_token`,`cert_path`, | |||
| `merchant_cert_path`,`type`,`mch_type`,`open_pay`,`share`,`rate`,`real_rate`,`is_commission`,`system_rate`,`sell_rate`, | |||
| `service_id`,`pay_score_notify_url`,`api_v3_key`,`cert_serial_no`,`private_key_path`,`private_cert_pem_path`, | |||
| `merchant_key_path`,`merchant_apiv3_key`,`merchant_cert_pem_path` | |||
| `merchant_key_path`,`merchant_apiv3_key`,`merchant_cert_pem_path`,`business_type`,`brandid`,`card_id` | |||
| </sql> | |||
| <sql id="dynamicWhereConditions"> | |||