55 lines
1.8 KiB
Java
55 lines
1.8 KiB
Java
package com.zhgd.xmgl.call;
|
||
|
||
import cn.hutool.core.util.StrUtil;
|
||
import cn.hutool.http.HttpRequest;
|
||
import com.gexin.fastjson.JSON;
|
||
import com.zhgd.xmgl.call.api.MessageManufacturer;
|
||
import com.zhgd.xmgl.modules.project.entity.MessageConfigV2;
|
||
import lombok.extern.slf4j.Slf4j;
|
||
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
|
||
import org.springframework.context.annotation.Scope;
|
||
import org.springframework.stereotype.Component;
|
||
|
||
import java.util.HashMap;
|
||
import java.util.List;
|
||
|
||
/**
|
||
* 云片短信
|
||
*/
|
||
@Slf4j
|
||
@Component
|
||
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
|
||
public class YunPianMessageCall implements MessageManufacturer {
|
||
private MessageConfigV2 config;
|
||
|
||
@Override
|
||
public MessageConfigV2 getConfig() {
|
||
return config;
|
||
}
|
||
|
||
@Override
|
||
public void setConfig(MessageConfigV2 config) {
|
||
this.config = config;
|
||
}
|
||
|
||
@Override
|
||
public void sendMsg(List<String> phoneNums, String templateId, List<String> templateParams, String text) {
|
||
try {
|
||
for (String phoneNum : phoneNums) {
|
||
HashMap<String, Object> formMap = new HashMap<>();
|
||
formMap.put("apikey", config.getApiKey());
|
||
formMap.put("mobile", phoneNum);
|
||
formMap.put("text", StrUtil.format("【{}】{}", config.getSignature(), text));
|
||
String url = "https://sms.yunpian.com/v2/sms/single_send.json";
|
||
log.info("云片短信按短信配置发送短信,url:{},body:{}", url, JSON.toJSONString(formMap));
|
||
String body = HttpRequest.post(url).form(formMap).execute().body();
|
||
log.info("云片短信按短信配置发送短信,结果:{}", body);
|
||
}
|
||
} catch (Exception e) {
|
||
log.error("云片短信按短信配置发送短信异常", e);
|
||
}
|
||
}
|
||
|
||
|
||
}
|