Commit f1a19ceb authored by qinxunjia's avatar qinxunjia

dmhub获取token基础流程

parent 52fa15b7
...@@ -11,9 +11,6 @@ import org.slf4j.LoggerFactory; ...@@ -11,9 +11,6 @@ import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@RequestMapping("/test/chuanglan") @RequestMapping("/test/chuanglan")
@RestController @RestController
public class ChuangLanApi { public class ChuangLanApi {
...@@ -26,10 +23,7 @@ public class ChuangLanApi { ...@@ -26,10 +23,7 @@ public class ChuangLanApi {
@PostMapping("/notify") @PostMapping("/notify")
public String notify(@RequestParam CLNotifyRequest notifyInfo) { public String notify(@RequestParam CLNotifyRequest notifyInfo) {
log.info("创蓝异步通知接口入参:{}", JSONObject.toJSONString(notifyInfo)); log.info("创蓝异步通知接口入参:{}", JSONObject.toJSONString(notifyInfo));
chuangLanSmsService.asyncNotify(notifyInfo); chuangLanSmsService.asyncNotify(notifyInfo);
String response = "success"; String response = "success";
log.info("创蓝异步通知接口出参:{}", response); log.info("创蓝异步通知接口出参:{}", response);
return response; return response;
......
package com.jz.sms.dmHub.config;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
@Component
public class DmHubConfig {
// 应用过id
public static String applicationId;
// 应用key
public static String applicationKey;
public static String tokenUrl;
@Value("${system.config.dmHub.applicationId}")
public void setApplicationId(String applicationId) {
DmHubConfig.applicationId = applicationId;
}
@Value("{system.config.dmHub.applicationKey}")
public void setApplicationKey(String applicationKey) {
DmHubConfig.applicationKey = applicationKey;
}
@Value("{system.config.dmHub.tokenUrl}")
public void setTokenUrl(String tokenUrl) {
DmHubConfig.tokenUrl = tokenUrl;
}
}
...@@ -7,10 +7,9 @@ public interface DmHubService { ...@@ -7,10 +7,9 @@ public interface DmHubService {
/** /**
* 获取DM hub token,用户请求DM hub接口 * 获取DM hub token,用户请求DM hub接口
* *
* @param accInfo
* @return token信息 * @return token信息
*/ */
String getToken(Map<String, Object> accInfo); String getToken();
/** /**
......
package com.jz.sms.dmHub.service.impl; package com.jz.sms.dmHub.service.impl;
import com.alibaba.fastjson.JSONObject;
import com.jz.sms.dmHub.config.DmHubConfig;
import com.jz.sms.dmHub.service.DmHubService; import com.jz.sms.dmHub.service.DmHubService;
import com.jz.sms.util.OkHttpUtil;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.HashMap;
import java.util.Map; import java.util.Map;
/** /**
...@@ -13,12 +17,33 @@ public class DmHubServiceImpl implements DmHubService { ...@@ -13,12 +17,33 @@ public class DmHubServiceImpl implements DmHubService {
@Override @Override
public String getToken(Map<String, Object> accInfo) { public String getToken() {
String appid = DmHubConfig.applicationId;
String secret = DmHubConfig.applicationKey;
String tokenUrl = DmHubConfig.tokenUrl;
String grantType = "client_credentials";
Map<String, String> requestMap = new HashMap<>();
requestMap.put("appid", appid);
requestMap.put("secret", secret);
requestMap.put("grant_type", grantType);
String retStr = OkHttpUtil.get(tokenUrl, requestMap);
JSONObject retJson = JSONObject.parseObject(retStr);
String errorCode = retJson.getString("error_code");
if ("0".equals(errorCode)) {
String accessToken = retJson.getString("access_token");
String expires = retJson.getString("expires_in");
return accessToken;
} else {
return null; return null;
} }
// TODO 存redis,过期时间=expires-600(秒)
}
@Override @Override
public Map<String,Object> smsReport(Map<String, Object> accInfo) { public Map<String, Object> smsReport(Map<String, Object> accInfo) {
return null; return null;
} }
} }
...@@ -29,3 +29,7 @@ system: ...@@ -29,3 +29,7 @@ system:
addTemplate: https://zz.253.com/apis/template/add # 创建短信模板 addTemplate: https://zz.253.com/apis/template/add # 创建短信模板
interfaceUser: admin001 # 接口用户名 interfaceUser: admin001 # 接口用户名
interfacePassword: 9zdata0423 # 接口密码 interfacePassword: 9zdata0423 # 接口密码
dmHub:
applicationId: cl0300171a6012c21
applicationKey: 4017078e9dfd593b2d9a0ede58eff589644fbe50
tokenUrl: https://api.convertlab.com/security/accesstoken
\ No newline at end of file
...@@ -30,4 +30,8 @@ system: ...@@ -30,4 +30,8 @@ system:
addTemplate: https://zz.253.com/apis/template/add # 创建短信模板 addTemplate: https://zz.253.com/apis/template/add # 创建短信模板
interfaceUser: admin001 # 接口用户名 interfaceUser: admin001 # 接口用户名
interfacePassword: 9zdata0423 # 接口密码 interfacePassword: 9zdata0423 # 接口密码
dmHub:
applicationId: cl0300171a6012c21
applicationKey: 4017078e9dfd593b2d9a0ede58eff589644fbe50
tokenUrl: https://api.convertlab.com/security/accesstoken
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment