44323
2024-01-30 987fd6c12a7dcfb2b6ae9ee585fc182d2d865040
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
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<OperatorAuthAlipay>()
                            .eq("orderNo", order_id));
                    if (orderNo!=null){
                        Integer operatorId = orderNo.getOperatorId();
                        OperatorUser operatorId1 = operatorUserService.getOne(new QueryWrapper<OperatorUser>()
                                .eq("operatorId", operatorId));
                        if (operatorId1!=null){
                            operatorId1.setAlipayNum(smid);
                            operatorId1.setAlipayAudit(2);
                        }
                    }
                }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<OperatorAuthAlipay>()
                            .eq("orderNo", order_id));
                    if (orderNo!=null){
                        orderNo.setRefuseReason(reason);
                        operatorAuthService.updateById(orderNo);
                        Integer operatorId = orderNo.getOperatorId();
                        OperatorUser operatorId1 = operatorUserService.getOne(new QueryWrapper<OperatorUser>()
                                .eq("operatorId", operatorId));
                        if (operatorId1!=null){
                            operatorId1.setAlipayAudit(3);
                            operatorUserService.updateById(operatorId1);
                        }
                    }
                }
 
            }
        });
        alipayMsgClient.connect();
        return alipayMsgClient;
    }
 }