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 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 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 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 map = new HashMap<>(); if(!unbindSubscriptionResponse.getBody().getCode().equals("OK")){ map.put("code", "-1"); }else{ map.put("code", "200"); } return map; } }