wisdomisite-java/src/main/java/com/zhgd/xmgl/call/YunPianMessageCall.java
2025-09-05 11:29:57 +08:00

55 lines
1.8 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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);
}
}
}