package com.stylefeng.guns.modular.system.util;
|
|
import com.aliyun.dyplsapi20170525.models.BindAxbRequest;
|
import com.aliyun.dyplsapi20170525.models.BindAxbResponse;
|
import com.aliyun.dyplsapi20170525.models.UpdateSubscriptionRequest;
|
import com.aliyun.dyplsapi20170525.models.UpdateSubscriptionResponse;
|
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");
|
UpdateSubscriptionRequest updateSubscriptionRequest = new UpdateSubscriptionRequest()
|
.setPoolKey(poolKey)
|
.setSubsId(bindId)
|
.setPhoneNoX(phone)
|
.setOperateType("updateExpire")
|
.setExpiration(sdf.format(new Date(expiration)));
|
// 复制代码运行请自行打印 API 的返回值
|
UpdateSubscriptionResponse updateSubscriptionResponse = client.updateSubscription(updateSubscriptionRequest);
|
Map<String, String> map = new HashMap<>();
|
if(!updateSubscriptionResponse.getBody().getCode().equals("OK")){
|
map.put("code", "-1");
|
}else{
|
map.put("code", "200");
|
}
|
return map;
|
}
|
}
|