package com.dsh.guns.modular.system.api; import cn.hutool.core.io.FileUtil; import com.alibaba.fastjson.JSONObject; import com.alipay.api.msg.AlipayMsgClient; import com.alipay.api.msg.MsgHandler; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.dsh.guns.modular.system.model.OperatorAuthAlipay; import com.dsh.guns.modular.system.model.OperatorUser; import com.dsh.guns.modular.system.service.IOperatorAuthService; import com.dsh.guns.modular.system.service.IOperatorUserService; import com.dsh.guns.modular.system.service.IUserService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.stereotype.Component; @Component @Configuration @EnableConfigurationProperties({AliPayProperties.class}) public class AliPayMsgConfig { @Autowired private IOperatorAuthService operatorAuthService; @Autowired private IOperatorUserService operatorUserService; @Autowired private IUserService userService; private AliPayProperties aliPay; public AliPayMsgConfig(AliPayProperties aliPay) { this.aliPay = aliPay; } @Bean public AlipayMsgClient alipayMsgClient() throws Exception { AlipayMsgClient alipayMsgClient = AlipayMsgClient.getInstance(aliPay.getAppId()); alipayMsgClient.setConnector("openchannel.alipay.com"); alipayMsgClient.setSecurityConfig(aliPay.getSignType(), aliPay.getAppPrivateKey(), aliPay.getAlipay_public_key()); alipayMsgClient.setCharset(aliPay.getChartSet()); alipayMsgClient.setMessageHandler(new MsgHandler() { /** * 客户端接收到消息后回调此方法 * @param msgApi 接收到的消息的消息api名 * @param msgId 接收到的消息的消息id * @param bizContent 接收到的消息的内容,json格式 */ @Override public void onMessage (String msgApi, String msgId, String bizContent) { System.err.println(" 消息对象"+msgApi); System.err.println("id"+msgId); System.err.println("内容"+bizContent); if (msgApi.equals("ant.merchant.expand.indirect.zft.passed")){ // 审核通过 JSONObject json = JSONObject.parseObject(bizContent); String smid = json.getString("smid"); String order_id = json.getString("order_id"); OperatorAuthAlipay orderNo = operatorAuthService.getOne(new QueryWrapper() .eq("orderNo", order_id)); if (orderNo!=null){ orderNo.setRefuseReason(null); operatorAuthService.updateById(orderNo); Integer operatorId = orderNo.getOperatorId(); OperatorUser operatorId1 = operatorUserService.getOne(new QueryWrapper() .eq("operatorId", operatorId)); if (operatorId1!=null){ operatorId1.setAlipayNum(smid); operatorId1.setAlipayAudit(2); operatorUserService.updateById(operatorId1); } } }else if (msgApi.equals("ant.merchant.expand.indirect.zft.rejected")){ // 审核拒绝 JSONObject json = JSONObject.parseObject(bizContent); String reason = json.getString("reason"); String order_id = json.getString("order_id"); OperatorAuthAlipay orderNo = operatorAuthService.getOne(new QueryWrapper() .eq("orderNo", order_id)); if (orderNo!=null){ orderNo.setRefuseReason(reason); operatorAuthService.updateById(orderNo); Integer operatorId = orderNo.getOperatorId(); OperatorUser operatorId1 = operatorUserService.getOne(new QueryWrapper() .eq("operatorId", operatorId)); if (operatorId1!=null){ operatorId1.setAlipayAudit(3); operatorUserService.updateById(operatorId1); } } } } }); alipayMsgClient.connect(); return alipayMsgClient; } }