|
|
|
@@ -23,6 +23,7 @@ import com.simple.pay.WxProfitSharingReceiverP; |
|
|
|
import com.simple.service.WxProfitSharingReceiverService; |
|
|
|
import com.simple.utils.BeanUtils; |
|
|
|
import com.simple.utils.Utility; |
|
|
|
import org.apache.log4j.Logger; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
import com.simple.common.IdWorker; |
|
|
|
@@ -32,6 +33,8 @@ import com.simple.common.IdWorker; |
|
|
|
@Service |
|
|
|
public class WxProfitSharingReceiverServiceImpl implements WxProfitSharingReceiverService { |
|
|
|
|
|
|
|
private Logger logger = Logger.getLogger(WxCouponOrderServiceImpl.class); |
|
|
|
|
|
|
|
final JSONObject errorMap = JSON.parseObject("{" + |
|
|
|
"\"SYSTEMERROR\":{\"detail\":\"接口返回错误\",\"reason\":\"系统超时\",\"resolution\":\"系统异常,请用相同参数重新调用\"}," + |
|
|
|
"\"PARAM_ERROR\":{\"detail\":\"参数错误\\t\",\"reason\":\"请求参数未按指引进行填写\",\"resolution\":\"请求参数错误,请重新检查再调用分账接口\"}," + |
|
|
|
@@ -78,6 +81,16 @@ public class WxProfitSharingReceiverServiceImpl implements WxProfitSharingReceiv |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
public WxProfitSharingReceiver findReceiver(WxMerchant merchant) { |
|
|
|
WxProfitSharingReceiver receiver = new WxProfitSharingReceiver(); |
|
|
|
receiver.setMerchantId(merchant.getId()); |
|
|
|
receiver.setSharingType(EnumProfitSharingType.PROFIT_SHARING_TYPE_WECHAT.getCode()); |
|
|
|
receiver.setStatus(EnumProfitSharingReceiverStatus.PROFIT_SHARING_RECEIVER_STATUS_VALID.getCode()); |
|
|
|
|
|
|
|
return wxProfitSharingReceiverMapper.selectOne(receiver); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
public ResultData addReceiver(WxMerchant merchant, WxProfitSharingReceiver receiver) { |
|
|
|
@@ -123,20 +136,24 @@ public class WxProfitSharingReceiverServiceImpl implements WxProfitSharingReceiv |
|
|
|
wxProfitSharingReceiverP.setSign(WxPayment.createSignHMAC(BeanUtils.toStringMap(wxProfitSharingReceiverP), payAccount.getApiKey())); |
|
|
|
response = WxProfitSharing.addReceiver(BeanUtils.toStringMap(wxProfitSharingReceiverP)); |
|
|
|
}catch (Exception e) { |
|
|
|
logger.error(ErrorCode.PROFIT_SHARING_RECEIVER_ADD_FAILED.getMessage() + e.getMessage()); |
|
|
|
return new ResultData(ErrorCode.PROFIT_SHARING_RECEIVER_ADD_FAILED, e.getMessage()); |
|
|
|
} |
|
|
|
Map<String, String> returnMap = WxPayment.xmlToMap(response); |
|
|
|
String return_code = returnMap.get("return_code"); |
|
|
|
if (!"SUCCESS".equals(return_code)) { |
|
|
|
logger.error(ErrorCode.PROFIT_SHARING_RECEIVER_ADD_FAILED.getMessage() + returnMap.get("return_msg")); |
|
|
|
return new ResultData(ErrorCode.PROFIT_SHARING_RECEIVER_ADD_FAILED.getCode(), returnMap.get("return_msg")); |
|
|
|
} |
|
|
|
|
|
|
|
String result_code = returnMap.get("result_code"); |
|
|
|
if (!"SUCCESS".equals(result_code)) { |
|
|
|
logger.error(ErrorCode.PROFIT_SHARING_RECEIVER_ADD_FAILED.getMessage() + returnMap.get("err_code_des")); |
|
|
|
return new ResultData(ErrorCode.PROFIT_SHARING_RECEIVER_ADD_FAILED.getCode(), returnMap.get("err_code_des")); |
|
|
|
} |
|
|
|
|
|
|
|
if (!WxPayment.verifyNotifyHMAC(returnMap,payAccount.getApiKey())){ |
|
|
|
logger.error(ErrorCode.PROFIT_SHARING_RECEIVER_ADD_FAILED.getMessage() + "verifyNotifyHMAC"); |
|
|
|
return new ResultData(ErrorCode.PROFIT_SHARING_RECEIVER_ADD_FAILED.getCode(), ErrorCode.PROFIT_SHARING_RECEIVER_ADD_FAILED.getMessage()); |
|
|
|
} |
|
|
|
|
|
|
|
@@ -145,7 +162,7 @@ public class WxProfitSharingReceiverServiceImpl implements WxProfitSharingReceiv |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public ResultData delReceiver(WxMerchant merchant, WxProfitSharingReceiver receiver) { |
|
|
|
public ResultData delReceiver(WxMerchant merchant) { |
|
|
|
WxAppinfo appInfo = new WxAppinfo(); |
|
|
|
appInfo.setTenantId(merchant.getTenantId()); |
|
|
|
appInfo.setType(EnumAppType.C.getCode()); |
|
|
|
@@ -153,6 +170,7 @@ public class WxProfitSharingReceiverServiceImpl implements WxProfitSharingReceiv |
|
|
|
appInfo = wxAppinfoMapper.findList(appInfo).get(0); |
|
|
|
WxPayAccount payAccount = wxPayAccountMapper.selectByPrimaryKey(appInfo.getPayId()); |
|
|
|
|
|
|
|
WxProfitSharingReceiver receiver = new WxProfitSharingReceiver(); |
|
|
|
receiver.setMerchantId(merchant.getId()); |
|
|
|
receiver.setSharingType(EnumProfitSharingType.PROFIT_SHARING_TYPE_WECHAT.getCode()); |
|
|
|
receiver.setStatus(EnumProfitSharingReceiverStatus.PROFIT_SHARING_RECEIVER_STATUS_VALID.getCode()); |
|
|
|
@@ -181,28 +199,56 @@ public class WxProfitSharingReceiverServiceImpl implements WxProfitSharingReceiv |
|
|
|
String response; |
|
|
|
try { |
|
|
|
wxProfitSharingReceiverP.setSign(WxPayment.createSignHMAC(BeanUtils.toStringMap(wxProfitSharingReceiverP), payAccount.getApiKey())); |
|
|
|
response = WxProfitSharing.addReceiver(BeanUtils.toStringMap(wxProfitSharingReceiverP)); |
|
|
|
response = WxProfitSharing.delReceiver(BeanUtils.toStringMap(wxProfitSharingReceiverP)); |
|
|
|
}catch (Exception e) { |
|
|
|
logger.error(ErrorCode.PROFIT_SHARING_RECEIVER_DEL_FAILED.getMessage() + e.getMessage()); |
|
|
|
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)) { |
|
|
|
logger.error(ErrorCode.PROFIT_SHARING_RECEIVER_DEL_FAILED.getMessage() + returnMap.get("return_msg")); |
|
|
|
return new ResultData(ErrorCode.PROFIT_SHARING_RECEIVER_DEL_FAILED.getCode(), returnMap.get("return_msg")); |
|
|
|
} |
|
|
|
|
|
|
|
String result_code = returnMap.get("result_code"); |
|
|
|
if (!"SUCCESS".equals(result_code)) { |
|
|
|
|
|
|
|
if (returnMap.get("err_code").contains("USER_NOT_EXIST")) { |
|
|
|
receiver.setStatus(EnumProfitSharingReceiverStatus.PROFIT_SHARING_RECEIVER_STATUS_INVALID.getCode()); |
|
|
|
wxProfitSharingReceiverMapper.updateByPrimaryKeySelective(receiver); |
|
|
|
} |
|
|
|
logger.error(ErrorCode.PROFIT_SHARING_RECEIVER_DEL_FAILED.getMessage() + returnMap.get("result_msg")); |
|
|
|
return new ResultData(ErrorCode.PROFIT_SHARING_RECEIVER_DEL_FAILED.getCode(), returnMap.get("result_msg")); |
|
|
|
} |
|
|
|
|
|
|
|
if (!WxPayment.verifyNotifyHMAC(returnMap,payAccount.getApiKey())){ |
|
|
|
return new ResultData(ErrorCode.PROFIT_SHARING_RECEIVER_DEL_FAILED.getCode(), ErrorCode.PROFIT_SHARING_RECEIVER_DEL_FAILED.getMessage()); |
|
|
|
logger.error(ErrorCode.PROFIT_SHARING_RECEIVER_DEL_FAILED.getMessage()); |
|
|
|
return new ResultData(ErrorCode.PROFIT_SHARING_RECEIVER_DEL_FAILED.getCode(), "verifyNotifyHMAC"); |
|
|
|
} |
|
|
|
receiver.setStatus(EnumProfitSharingReceiverStatus.PROFIT_SHARING_RECEIVER_STATUS_INVALID.getCode()); |
|
|
|
wxProfitSharingReceiverMapper.updateByPrimaryKeySelective(receiver); |
|
|
|
return new ResultData(returnMap); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
public ResultData updateReceiver(WxMerchant merchant, WxProfitSharingReceiver receiver) { |
|
|
|
|
|
|
|
WxProfitSharingReceiver oldReceiver = new WxProfitSharingReceiver(); |
|
|
|
oldReceiver.setMerchantId(merchant.getId()); |
|
|
|
oldReceiver.setSharingType(EnumProfitSharingType.PROFIT_SHARING_TYPE_WECHAT.getCode()); |
|
|
|
oldReceiver.setStatus(EnumProfitSharingReceiverStatus.PROFIT_SHARING_RECEIVER_STATUS_VALID.getCode()); |
|
|
|
oldReceiver.setReceiverAccount(receiver.getReceiverAccount()); |
|
|
|
oldReceiver.setReceiverType(receiver.getReceiverType()); |
|
|
|
oldReceiver.setTrueName(receiver.getTrueName()); |
|
|
|
|
|
|
|
oldReceiver = wxProfitSharingReceiverMapper.selectOne(oldReceiver); |
|
|
|
|
|
|
|
if (oldReceiver == null) { |
|
|
|
delReceiver(merchant); |
|
|
|
return addReceiver(merchant, receiver); |
|
|
|
} |
|
|
|
|
|
|
|
return new ResultData(); |
|
|
|
} |
|
|
|
} |