package com.stylefeng.guns.modular.system.util;
|
|
import com.alibaba.fastjson.JSONObject;
|
import com.aliyuncs.CommonRequest;
|
import com.aliyuncs.CommonResponse;
|
import com.aliyuncs.DefaultAcsClient;
|
import com.aliyuncs.IAcsClient;
|
import com.aliyuncs.exceptions.ClientException;
|
import com.aliyuncs.exceptions.ServerException;
|
import com.aliyuncs.http.MethodType;
|
import com.aliyuncs.profile.DefaultProfile;
|
import com.stylefeng.guns.core.util.MD5Util;
|
import org.apache.commons.codec.binary.Base64;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Component;
|
|
import java.io.IOException;
|
import java.util.HashMap;
|
import java.util.Map;
|
|
/**
|
* 中国移动工具类
|
*/
|
@Component
|
public class ChinaMobileUtil {
|
|
private static String APIKey = "LTAI4G1BpRaihVRZp1RS8Stn";
|
|
private static String SecretKey = "PDR7uUEGNf0wIPPVCPCVdySgTwCr90";
|
|
@Autowired
|
private HttpClientUtil httpClientUtil;
|
|
|
/**
|
* 绑定小号
|
* @param phoneA
|
* @param phoneB
|
* @param areaCode
|
* @return
|
* @throws Exception
|
*/
|
public static Map<String, String> midAxbBindSend(String phoneA, String phoneB, Integer areaCode) throws Exception{
|
Map<String, String> map1 = new HashMap<>();
|
map1.put("code", "-1");
|
map1.put("msg", "");
|
map1.put("telX", "");
|
map1.put("bindId", "");
|
return map1;
|
//暂时屏蔽-后期放开
|
/*DefaultProfile profile = DefaultProfile.getProfile(
|
"cn-hangzhou", // 地域ID
|
APIKey, // 您的AccessKey ID
|
SecretKey ); // 您的AccessKey Secret
|
IAcsClient client = new DefaultAcsClient(profile);
|
|
CommonRequest request = new CommonRequest();
|
request.setMethod(MethodType.POST);
|
request.setDomain("dyplsapi.aliyuncs.com");
|
request.setVersion("2017-05-25");
|
request.setAction("BindAxb");
|
// 绑定关系的过期时间。必须晚于当前时间1分钟以上。
|
request.putQueryParameter("Expiration", DateUtil.format(new Date(new Date().getTime()+7 * 24 * 60 * 60*1000L),"yyyy-MM-dd HH:mm:ss"));
|
// 号码池Key
|
request.putQueryParameter("PoolKey", "FC100000119206151");
|
// AXB中的B号码
|
request.putQueryParameter("PhoneNoB", phoneB);
|
// AXB中的A号码
|
request.putQueryParameter("PhoneNoA", phoneA);
|
// 指定城市进行X号码的选号。
|
request.putQueryParameter("ExpectCity", "北京");
|
// 是否需要针对该绑定关系产生的所有通话录制通话录音。
|
request.putQueryParameter("IsRecordingEnabled", "false");
|
Map<String, String> map1 = new HashMap<>();
|
try {
|
CommonResponse response = client.getCommonResponse(request);
|
// 处理请求结果
|
System.out.println(response.getData());
|
JSONObject jsonObject = JSONObject.parseObject(response.getData());
|
if(jsonObject.getString("Code").equals("OK")){
|
map1.put("code", "200");
|
map1.put("msg", jsonObject.getString("Message"));
|
map1.put("telX", jsonObject.getJSONObject("SecretBindDTO").getString("SecretNo"));
|
map1.put("bindId", jsonObject.getJSONObject("SecretBindDTO").getString("SubsId"));
|
}else{
|
map1.put("code", jsonObject.getString("Code"));
|
map1.put("msg", jsonObject.getString("Message"));
|
}
|
} catch (ServerException e) {
|
e.printStackTrace();
|
map1.put("code", "-1");
|
map1.put("msg", e.getErrMsg());
|
} catch (ClientException e) {
|
System.out.println("ErrCode:" + e.getErrCode());
|
System.out.println("ErrMsg:" + e.getErrMsg());
|
System.out.println("RequestId:" + e.getRequestId());
|
map1.put("code", "-1");
|
map1.put("msg", e.getErrMsg());
|
}
|
return map1;*/
|
}
|
|
|
/**
|
* 解绑小号关系
|
* @param bindId 绑定关系id
|
* @return
|
* @throws Exception
|
*/
|
public static Map<String, String> midAxbUnBindSend(String bindId,String secretNo) throws Exception{
|
DefaultProfile profile = DefaultProfile.getProfile(
|
"cn-hangzhou", // 地域ID
|
APIKey, // 您的AccessKey ID
|
SecretKey ); // 您的AccessKey Secret
|
IAcsClient client = new DefaultAcsClient(profile);
|
|
CommonRequest request = new CommonRequest();
|
request.setMethod(MethodType.POST);
|
request.setDomain("dyplsapi.aliyuncs.com");
|
request.setVersion("2017-05-25");
|
request.setAction("UnbindSubscription");
|
// 绑定关系的过期时间。必须晚于当前时间1分钟以上。
|
// 号码池Key
|
request.putQueryParameter("PoolKey", "FC100000119206151");
|
// 隐私号码。调用BindAXG等号码绑定接口时指定或自动分配的X号码。
|
request.putQueryParameter("SecretNo", secretNo);
|
// 绑定关系ID。
|
//
|
//可以在控制台的号码管理 > 号码详情中查看绑定关系ID,或者在调用BindAxb等号码绑定API时查看返回参数中的SubsId。
|
request.putQueryParameter("SubsId", bindId);
|
Map<String, String> map1 = new HashMap<>();
|
try {
|
CommonResponse response = client.getCommonResponse(request);
|
// 处理请求结果
|
System.out.println(response.getData());
|
JSONObject jsonObject = JSONObject.parseObject(response.getData());
|
if(jsonObject.getString("Code").equals("OK")){
|
map1.put("code", "200");
|
map1.put("msg", jsonObject.getString("Message"));
|
}else{
|
map1.put("code", jsonObject.getString("Code"));
|
map1.put("msg", jsonObject.getString("Message"));
|
}
|
} catch (ServerException e) {
|
e.printStackTrace();
|
map1.put("code", "-1");
|
map1.put("msg", e.getErrMsg());
|
} catch (ClientException e) {
|
System.out.println("ErrCode:" + e.getErrCode());
|
System.out.println("ErrMsg:" + e.getErrMsg());
|
System.out.println("RequestId:" + e.getRequestId());
|
map1.put("code", "-1");
|
map1.put("msg", e.getErrMsg());
|
}
|
return map1;
|
}
|
|
public static void main(String[] args) throws IOException {
|
try{
|
// System.out.println(midAxbBindSend("18380476116","13688394165",null));
|
System.out.println(midAxbUnBindSend("1000031640138366","17150145472"));
|
}catch (Exception e){
|
|
}
|
|
}
|
|
|
public Map<String, String> HeaderUtils(String APIKey, String SecretKey) throws Exception{
|
Map<String, String> header = new HashMap<>();
|
long time = System.currentTimeMillis();
|
String signStr = MD5Util.encrypt(APIKey + SecretKey + time);
|
JSONObject jsonObject = new JSONObject();
|
jsonObject.put("apiKey", APIKey);
|
jsonObject.put("time", time);
|
jsonObject.put("sign", signStr);
|
Base64 base64 = new Base64();
|
String s = base64.encodeToString(jsonObject.toJSONString().getBytes("UTF-8"));
|
header.put("header", s);
|
|
jsonObject = new JSONObject();
|
jsonObject.put("platformId", "");
|
jsonObject.put("secret", "");
|
s = base64.encodeToString(jsonObject.toJSONString().getBytes("UTF-8"));
|
header.put("accessCode", s);
|
return header;
|
}
|
}
|