xuhy
2025-01-09 712f70b2936079a131ecb1e63c6d337171618cad
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
93
94
95
96
97
98
99
package com.stylefeng.guns.modular.system.util;
 
import com.aliyun.dyplsapi20170525.models.*;
import com.aliyun.teaopenapi.models.Config;
import org.springframework.stereotype.Component;
 
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
 
/**
 * 中国移动工具类
 */
@Component
public class ChinaMobileUtil {
 
    private String accessKeyId = "LTAI5tCeHnZXREQBcVf3NHLB";
 
    private String accessKeySecret = "OEX6AtRb3qOCyp53xOFdDEYgBjzZzS";
 
    private String poolKey = "FC100000145494178";//号码池KEY
 
 
 
    /**
     * 使用AK&SK初始化账号Client
     * @return Client
     * @throws Exception
     */
    public com.aliyun.dyplsapi20170525.Client createClient() throws Exception {
        Config config = new Config()
                // 您的AccessKey ID
                .setAccessKeyId(accessKeyId)
                // 您的AccessKey Secret
                .setAccessKeySecret(accessKeySecret);
        // 访问的域名
        config.endpoint = "dyplsapi.aliyuncs.com";
        return new com.aliyun.dyplsapi20170525.Client(config);
    }
 
 
    /**
     * 绑定隐私号
     * @param phoneA
     * @param phoneB
     * @param expiration    "2021-12-14 12:00:00"
     * @return
     * @throws Exception
     */
    public Map<String, String> midAxbBindSend(String phoneA, String phoneB, Long expiration) throws Exception{
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        com.aliyun.dyplsapi20170525.Client client = createClient();
        BindAxbRequest bindAxbRequest = new BindAxbRequest()
                .setPhoneNoA(phoneA)
                .setExpiration(sdf.format(new Date(expiration)))
                .setPoolKey(poolKey)
                .setPhoneNoB(phoneB);
        // 复制代码运行请自行打印 API 的返回值
        BindAxbResponse bindAxbResponse = client.bindAxb(bindAxbRequest);
        Map<String, String> map = new HashMap<>();
        if(!bindAxbResponse.getBody().getCode().equals("OK")){
            map.put("code", "-1");
        }else{
            map.put("code", "200");
            map.put("telX", bindAxbResponse.getBody().getSecretBindDTO().getSecretNo());
            map.put("bindId", bindAxbResponse.getBody().getSecretBindDTO().getSubsId());
        }
        return map;
    }
 
 
    /**
     * 修改绑定关系
     * @param bindId    绑定关系id
     * @param phone     隐私号
     * @return
     * @throws Exception
     */
    public Map<String, String> midAxbUnBindSend(String bindId, String phone, Long expiration) throws Exception{
        com.aliyun.dyplsapi20170525.Client client = createClient();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        UnbindSubscriptionRequest updateSubscriptionRequest = new UnbindSubscriptionRequest()
                .setPoolKey(poolKey)
                .setSubsId(bindId)
                .setSecretNo(phone);
        // 复制代码运行请自行打印 API 的返回值
        UnbindSubscriptionResponse unbindSubscriptionResponse = client.unbindSubscription(updateSubscriptionRequest);
        System.out.println(unbindSubscriptionResponse.getBody());
        Map<String, String> map = new HashMap<>();
        if(!unbindSubscriptionResponse.getBody().getCode().equals("OK")){
            map.put("code", "-1");
        }else{
            map.put("code", "200");
        }
        return map;
    }
 
}