package com.stylefeng.guns.modular.system.util;
|
|
import com.alibaba.fastjson.JSONObject;
|
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.util.HashMap;
|
import java.util.Map;
|
|
/**
|
* 中国移动工具类
|
*/
|
@Component
|
public class ChinaMobileUtil {
|
|
private String APIKey = "zj42494b1bdd416b9762229af6b5cbbd";
|
|
private String SecretKey = "30323561316534653735613230316339";
|
|
@Autowired
|
private HttpClientUtil httpClientUtil;
|
|
|
/**
|
* 绑定小号
|
* @param phoneA
|
* @param phoneB
|
* @param areaCode
|
* @return
|
* @throws Exception
|
*/
|
public Map<String, String> midAxbBindSend(String phoneA, String phoneB, Integer areaCode) throws Exception{
|
//组装请求对象-具体描述见开发文档-订单小号-AXB接口规范部分内容
|
Map<String, Object> request = new HashMap<>();
|
request.put("APPID", APIKey);
|
request.put("bindtype", "AXB");
|
request.put("requestId", UUIDUtil.getRandomCode(16));
|
request.put("record", "0");
|
//用户号码,必填,格式遵循国际电信联盟定义的E.164标准
|
request.put("telA", "86" + phoneA);
|
//用户号码B,必填,格式遵循国际电信联盟定义的E.164标准
|
request.put("telB", "86" + phoneB);
|
//需要选择的小号所属区号,当telX不写时必填,例如:杭州(571)
|
request.put("areaCode", 571);
|
//订单小号,非必填,当指定小号绑定时填写,格式遵循国际电信联盟定义的E.164标准
|
// request.setTelX("8618867110000");
|
//绑定关系过期失效时间,秒,取值必须大于0且最大值不超过4294967296
|
request.put("expiration", Integer.valueOf(7 * 24 * 60 * 60));
|
|
Map<String, String> header = new HashMap<String, String>(3);
|
header.put("Authorization", "Basic " + new String(Base64.encodeBase64((APIKey + ":" + SecretKey).getBytes())));
|
header.put("Content-Type", "application/json;charset=utf-8");
|
String post = httpClientUtil.pushHttpRequset("POST", "https://ct.open.10086.cn/ordernumber/v1/binding", request, header, "json");
|
Map<String, String> map1 = new HashMap<>();
|
if(post.indexOf("0000") != -1){
|
JSONObject jsonObject = JSONObject.parseObject(post);
|
if(jsonObject.getString("code").equals("0000")){
|
map1.put("code", "200");
|
map1.put("msg", jsonObject.getString("message"));
|
map1.put("telX", jsonObject.getString("x_no").substring(2));
|
map1.put("bindId", jsonObject.getString("bindId"));
|
}else{
|
map1.put("code", jsonObject.getString("code"));
|
map1.put("msg", jsonObject.getString("message"));
|
}
|
}else{
|
map1.put("code", "-1");
|
map1.put("msg", post);
|
}
|
|
return map1;
|
}
|
|
|
/**
|
* 解绑小号关系
|
* @param bindId 绑定关系id
|
* @return
|
* @throws Exception
|
*/
|
public Map<String, String> midAxbUnBindSend(String bindId) throws Exception{
|
//组装请求对象-具体描述见开发文档-订单小号-AXB接口规范部分内容
|
Map<String, Object> request = new HashMap<>();
|
//绑定关系ID
|
request.put("APPID", APIKey);
|
request.put("bindId", bindId);
|
|
Map<String, String> header = new HashMap<String, String>(3);
|
header.put("Authorization", "Basic " + new String(Base64.encodeBase64((APIKey + ":" + SecretKey).getBytes())));
|
header.put("Content-Type", "application/json;charset=utf-8");
|
String post = httpClientUtil.pushHttpRequset("POST", "https://ct.open.10086.cn/ordernumber/v1/unbinding", request, header, "json");
|
Map<String, String> map1 = new HashMap<>();
|
if(post.indexOf("0000") != -1){
|
JSONObject jsonObject = JSONObject.parseObject(post);
|
if(jsonObject.getString("code").equals("0000")){
|
map1.put("code", "200");
|
map1.put("msg", jsonObject.getString("message"));
|
}else{
|
map1.put("code", jsonObject.getString("code"));
|
map1.put("msg", jsonObject.getString("message"));
|
}
|
}else{
|
map1.put("code", "-1");
|
map1.put("msg", post);
|
}
|
return map1;
|
}
|
|
|
|
|
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;
|
}
|
}
|