|
|
|
@@ -2,6 +2,7 @@ package com.simple.service.impl; |
|
|
|
|
|
|
|
import java.util.*; |
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSON; |
|
|
|
import com.alibaba.fastjson.JSONObject; |
|
|
|
import com.github.pagehelper.PageHelper; |
|
|
|
import com.github.pagehelper.PageInfo; |
|
|
|
@@ -29,10 +30,23 @@ import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
import com.simple.common.IdWorker; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Service |
|
|
|
public class WxProfitSharingReceiverServiceImpl implements WxProfitSharingReceiverService { |
|
|
|
|
|
|
|
@Autowired |
|
|
|
|
|
|
|
final JSONObject errorMap = JSON.parseObject("{" + |
|
|
|
"\"SYSTEMERROR\":{\"detail\":\"接口返回错误\",\"reason\":\"系统超时\",\"resolution\":\"系统异常,请用相同参数重新调用\"}," + |
|
|
|
"\"PARAM_ERROR\":{\"detail\":\"参数错误\\t\",\"reason\":\"请求参数未按指引进行填写\",\"resolution\":\"请求参数错误,请重新检查再调用分账接口\"}," + |
|
|
|
"\"INVALID_REQUEST\":{\"detail\":\"请求不合法\",\"reason\":\"参数中APPID或MCHID不存在等 \",\"resolution\":\"请重新检查再调用分账接口\"}," + |
|
|
|
"\"OPENID_MISMATCH \":{\"detail\":\"OPENID错误\",\"reason\":\"OPENID与APPID不匹配\",\"resolution\":\"请检查OPENID是否正确\"}," + |
|
|
|
"\"FREQUENCY_LIMITED \":{\"detail\":\"频率限制\",\"reason\":\"请求过多被频率限制\",\"resolution\":\"该笔请求未受理,请降低频率后原单重试\"}," + |
|
|
|
"\"NOAUTH \":{\"detail\":\"无分账权限\",\"reason\":\"未开通分账权限\",\"resolution\":\"请先开通分账\"}," + |
|
|
|
"\"USER_NOTEXIST\":{\"detail\":\"分账接受方不存在\",\"reason\":\"分账接受方不存在\",\"resolution\":\"请确认分账接收方类型或者账号无误后重试\"}}"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired |
|
|
|
WxProfitSharingReceiverMapper wxProfitSharingReceiverMapper; |
|
|
|
@Autowired |
|
|
|
WxAppinfoMapper wxAppinfoMapper; |
|
|
|
@@ -83,7 +97,7 @@ public class WxProfitSharingReceiverServiceImpl implements WxProfitSharingReceiv |
|
|
|
|
|
|
|
WxProfitSharingReceiver receiver = new WxProfitSharingReceiver(); |
|
|
|
receiver.setMerchantId(merchant.getId().toString()); |
|
|
|
receiver.setSharingType(EnumProfitSharingType.PROFIT_SHARING_TYPE_WEICHAT.getCode()); |
|
|
|
receiver.setSharingType(EnumProfitSharingType.PROFIT_SHARING_TYPE_WECHAT.getCode()); |
|
|
|
receiver.setId(IdWorker.get().nextId()); |
|
|
|
receiver.setCreateTime(new Date()); |
|
|
|
receiver.setUpdateTime(new Date()); |
|
|
|
@@ -92,7 +106,7 @@ public class WxProfitSharingReceiverServiceImpl implements WxProfitSharingReceiv |
|
|
|
receiver.setReceiverType(EnumProfitSharingReceiverType.PROFIT_SHARING_RECEIVER_MERCHANT_ID.getCode()); |
|
|
|
receiver.setTrueName(merchant.getName()); |
|
|
|
|
|
|
|
//分账提交 |
|
|
|
//添加分账账户 |
|
|
|
WxProfitSharingReceiverP wxProfitSharingReceiverP = new WxProfitSharingReceiverP(); |
|
|
|
//wxProfitSharingP.setAppid(mainAppInfo.getAppId()); |
|
|
|
//wxProfitSharingP.setMch_id(mainPayAccount.getMchId()); |
|
|
|
@@ -105,7 +119,7 @@ public class WxProfitSharingReceiverServiceImpl implements WxProfitSharingReceiv |
|
|
|
|
|
|
|
JSONObject receiverJSON = new JSONObject(); |
|
|
|
receiverJSON.put("type",EnumProfitSharingReceiverType.PROFIT_SHARING_RECEIVER_MERCHANT_ID.getMessage()); |
|
|
|
receiverJSON.put("acount",merchant.getReceiverAccount()); |
|
|
|
receiverJSON.put("account",merchant.getReceiverAccount()); |
|
|
|
receiverJSON.put("name",merchant.getName()); |
|
|
|
|
|
|
|
wxProfitSharingReceiverP.setReceiver(receiverJSON.toJSONString()); |
|
|
|
@@ -123,7 +137,7 @@ public class WxProfitSharingReceiverServiceImpl implements WxProfitSharingReceiv |
|
|
|
} |
|
|
|
|
|
|
|
if (!WxPayment.verifyNotify(returnMap,payAccount.getApiKey())){ |
|
|
|
return new ResultData(ErrorCode.PROFIT_SHARING_RECEIVER_ADD_FAILED.getCode(), ErrorCode.PROFIT_SHARING_RETURN_INVALID.getMessage()); |
|
|
|
return new ResultData(ErrorCode.PROFIT_SHARING_RECEIVER_ADD_FAILED.getCode(), ErrorCode.PROFIT_SHARING_RECEIVER_ADD_FAILED.getMessage()); |
|
|
|
} |
|
|
|
|
|
|
|
String result_code = returnMap.get("result_code"); |
|
|
|
@@ -137,7 +151,67 @@ public class WxProfitSharingReceiverServiceImpl implements WxProfitSharingReceiv |
|
|
|
|
|
|
|
@Override |
|
|
|
public ResultData delReceiver(WxMerchant merchant) { |
|
|
|
return new ResultData(); |
|
|
|
WxAppinfo subAppInfo = new WxAppinfo(); |
|
|
|
subAppInfo.setTenantId(merchant.getTenantId()); |
|
|
|
subAppInfo.setType(EnumAppType.C.getCode()); |
|
|
|
|
|
|
|
subAppInfo = wxAppinfoMapper.findList(subAppInfo).get(0); |
|
|
|
WxPayAccount payAccount = wxPayAccountMapper.selectByPrimaryKey(subAppInfo.getPayId()); |
|
|
|
//WxPayAccount mainPayAccount = wxPayAccountMapper.selectByPrimaryKey(new Long(EnumPayDomain.PAY_DOMAIN_MASTER_ACCOUNT_ID.getCode())); |
|
|
|
//WxAppinfo mainAppInfo = wxAppinfoMapper.selectByPrimaryKey(new Long(EnumPayDomain.PAY_DOMAIN_MASTER_APPINFO_ID.getCode())); |
|
|
|
|
|
|
|
|
|
|
|
WxProfitSharingReceiver receiver = new WxProfitSharingReceiver(); |
|
|
|
receiver.setMerchantId(merchant.getId().toString()); |
|
|
|
receiver.setSharingType(EnumProfitSharingType.PROFIT_SHARING_TYPE_WECHAT.getCode()); |
|
|
|
receiver.setReceiverAccount(merchant.getReceiverAccount().toString()); |
|
|
|
receiver.setReceiverType(EnumProfitSharingReceiverType.PROFIT_SHARING_RECEIVER_MERCHANT_ID.getCode()); |
|
|
|
|
|
|
|
receiver = wxProfitSharingReceiverMapper.selectOne(receiver); |
|
|
|
|
|
|
|
if (receiver == null) |
|
|
|
return new ResultData(ErrorCode.PROFIT_SHARING_RECEIVER_DEL_FAILED.getCode(), ErrorCode.PROFIT_SHARING_RECEIVER_DEL_FAILED.getMessage()); |
|
|
|
|
|
|
|
//删除分账账户 |
|
|
|
WxProfitSharingReceiverP wxProfitSharingReceiverP = new WxProfitSharingReceiverP(); |
|
|
|
//wxProfitSharingP.setAppid(mainAppInfo.getAppId()); |
|
|
|
//wxProfitSharingP.setMch_id(mainPayAccount.getMchId()); |
|
|
|
wxProfitSharingReceiverP.setAppid(subAppInfo.getAppId()); |
|
|
|
wxProfitSharingReceiverP.setMch_id(payAccount.getMchId()); |
|
|
|
wxProfitSharingReceiverP.setSub_appid(subAppInfo.getAppId()); |
|
|
|
wxProfitSharingReceiverP.setSub_mch_id(payAccount.getMchId()); |
|
|
|
wxProfitSharingReceiverP.setNonce_str(Utility.generate32UUID()); |
|
|
|
|
|
|
|
|
|
|
|
JSONObject receiverJSON = new JSONObject(); |
|
|
|
receiverJSON.put("type",EnumProfitSharingReceiverType.PROFIT_SHARING_RECEIVER_MERCHANT_ID.getMessage()); |
|
|
|
receiverJSON.put("account",merchant.getReceiverAccount()); |
|
|
|
|
|
|
|
wxProfitSharingReceiverP.setReceiver(receiverJSON.toJSONString()); |
|
|
|
String response; |
|
|
|
try { |
|
|
|
wxProfitSharingReceiverP.setSign(WxPayment.createSign(BeanUtils.toStringMap(wxProfitSharingReceiverP), payAccount.getApiKey())); |
|
|
|
response = WxProfitSharing.addReceiver(BeanUtils.toStringMap(wxProfitSharingReceiverP)); |
|
|
|
}catch (Exception e) { |
|
|
|
return new ResultData(ErrorCode.PROFIT_SHARING_RECEIVER_DEL_FAILED, e.getMessage()); |
|
|
|
} |
|
|
|
Map<String, String> returnMap = WxPayment.xmlToMap(response); |
|
|
|
String return_code = returnMap.get("return_code"); |
|
|
|
if (!"SUCCESS".equals(return_code)) { |
|
|
|
return new ResultData(ErrorCode.PROFIT_SHARING_RECEIVER_DEL_FAILED.getCode(), returnMap.get("return_msg")); |
|
|
|
} |
|
|
|
|
|
|
|
if (!WxPayment.verifyNotify(returnMap,payAccount.getApiKey())){ |
|
|
|
return new ResultData(ErrorCode.PROFIT_SHARING_RECEIVER_DEL_FAILED.getCode(), ErrorCode.PROFIT_SHARING_RECEIVER_DEL_FAILED.getMessage()); |
|
|
|
} |
|
|
|
|
|
|
|
String result_code = returnMap.get("result_code"); |
|
|
|
if (!"SUCCESS".equals(result_code)) { |
|
|
|
return new ResultData(ErrorCode.PROFIT_SHARING_RECEIVER_DEL_FAILED.getCode(), returnMap.get("result_msg")); |
|
|
|
} |
|
|
|
|
|
|
|
wxProfitSharingReceiverMapper.deleteByPrimaryKey(receiver); |
|
|
|
return new ResultData(returnMap); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|