|
@@ -0,0 +1,66 @@
|
|
|
+package com.jpsoft.picc.modules.common.utils;
|
|
|
+
|
|
|
+import cn.hutool.json.JSONObject;
|
|
|
+import com.jpsoft.picc.modules.common.dto.MessageResult;
|
|
|
+import com.taobao.api.DefaultTaobaoClient;
|
|
|
+import com.taobao.api.TaobaoClient;
|
|
|
+import com.taobao.api.request.AlibabaAliqinFcSmsNumSendRequest;
|
|
|
+import com.taobao.api.response.AlibabaAliqinFcSmsNumSendResponse;
|
|
|
+
|
|
|
+public class SMSUtil {
|
|
|
+ public final static String REG_TEMPLATE_CODE = "SMS_49445088";
|
|
|
+
|
|
|
+ private final static String APP_KEY = "24698874";
|
|
|
+ private final static String APP_SECRET = "5f5b21d1dc93e124aa803f95d71c00b8";
|
|
|
+ private final static String APP_URL = "https://eco.taobao.com/router/rest";
|
|
|
+ private final static String SIGN_NAME = "荆鹏云平台";
|
|
|
+ private final static String SMS_TYPE = "normal";
|
|
|
+
|
|
|
+ public static MessageResult<String> sendVerificationCode(String phones, String code){
|
|
|
+ MessageResult<String> messageResult = new MessageResult<>();
|
|
|
+
|
|
|
+ TaobaoClient client = new DefaultTaobaoClient(APP_URL, APP_KEY, APP_SECRET);
|
|
|
+ AlibabaAliqinFcSmsNumSendRequest req = new AlibabaAliqinFcSmsNumSendRequest();
|
|
|
+ req.setSmsType(SMS_TYPE);
|
|
|
+ req.setSmsFreeSignName(SIGN_NAME);
|
|
|
+
|
|
|
+ JSONObject json = new JSONObject();
|
|
|
+ json.put("code", code);
|
|
|
+
|
|
|
+ req.setSmsParamString(json.toString());
|
|
|
+
|
|
|
+ req.setRecNum(phones);
|
|
|
+ req.setSmsTemplateCode(REG_TEMPLATE_CODE);
|
|
|
+
|
|
|
+ AlibabaAliqinFcSmsNumSendResponse rsp;
|
|
|
+ try {
|
|
|
+ rsp = client.execute(req);
|
|
|
+
|
|
|
+ JSONObject ret = new JSONObject(rsp.getBody());
|
|
|
+
|
|
|
+ if(ret.containsKey("error_response")){
|
|
|
+ messageResult.setResult(false);
|
|
|
+ messageResult.setMessage(ret.getJSONObject("error_response").getStr("sub_msg"));
|
|
|
+ }else if(ret.containsKey("alibaba_aliqin_fc_sms_num_send_response")){
|
|
|
+ JSONObject result = ret.getJSONObject("alibaba_aliqin_fc_sms_num_send_response").getJSONObject("result");
|
|
|
+
|
|
|
+ if(!result.getBool("success")){
|
|
|
+ messageResult.setMessage(result.getStr("msg"));
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ messageResult.setResult(true);
|
|
|
+ messageResult.setMessage(ret.toString());
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ messageResult.setResult(false);
|
|
|
+ messageResult.setMessage(e.toString());
|
|
|
+ }
|
|
|
+
|
|
|
+ return messageResult;
|
|
|
+ }
|
|
|
+
|
|
|
+ public static void main(String[] args){
|
|
|
+ MessageResult<String> messageResult = SMSUtil.sendVerificationCode("13986703087","134543");
|
|
|
+ System.out.println(messageResult);
|
|
|
+ }
|
|
|
+}
|