File was renamed from project-common/src/main/java/com/project/common/sms/YPSmsApi.java |
| | |
| | | package com.project.common.sms; |
| | | package com.project.system.sms; |
| | | |
| | | import com.project.common.constant.Constants; |
| | | import com.project.common.utils.SslUtils; |
| | | import com.project.system.service.ISysConfigService; |
| | | import lombok.RequiredArgsConstructor; |
| | | import org.apache.http.HttpEntity; |
| | | import org.apache.http.NameValuePair; |
| | | import org.apache.http.client.entity.UrlEncodedFormEntity; |
| | |
| | | import org.apache.http.impl.client.CloseableHttpClient; |
| | | import org.apache.http.message.BasicNameValuePair; |
| | | import org.apache.http.util.EntityUtils; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.HashMap; |
| | |
| | | * @author Mr.Zhao |
| | | */ |
| | | |
| | | @Service |
| | | @RequiredArgsConstructor |
| | | public class YPSmsApi { |
| | | |
| | | |
| | | private final ISysConfigService configService; |
| | | |
| | | |
| | | /** |
| | | * 智能匹配模板发送地址 |
| | |
| | | * @param mobile 接受的手机号 |
| | | * @param msg 短信内容 |
| | | */ |
| | | public static String sendSms(String mobile, String msg) |
| | | public String sendSms(String mobile, String msg) |
| | | { |
| | | Map<String, String> params = new HashMap<>(3); |
| | | params.put("apikey", API_KEY); |
| | | params.put("text", msg); |
| | | params.put("mobile", mobile); |
| | | return post(YP_SMS_URI, params); |
| | | String smsFlag = configService.selectConfigByKey("sys.sms.flag"); |
| | | if ("1".equals(smsFlag)) { |
| | | Map<String, String> params = new HashMap<>(3); |
| | | params.put("apikey", API_KEY); |
| | | params.put("text", msg); |
| | | params.put("mobile", mobile); |
| | | return post(YP_SMS_URI, params); |
| | | } |
| | | return ""; |
| | | } |
| | | |
| | | public static void main(String[] args) { |
| | | sendSms("18537821663", "【金明源】您的验证码是1234"); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 基于HttpClient 4.3的通用POST方法 |
| | |
| | | } |
| | | method.setEntity(new UrlEncodedFormEntity(paramList, Constants.UTF8)); |
| | | } |
| | | response = client.execute(method); |
| | | HttpEntity entity = response.getEntity(); |
| | | if (client != null) { |
| | | response = client.execute(method); |
| | | } |
| | | HttpEntity entity = null; |
| | | if (response != null) { |
| | | entity = response.getEntity(); |
| | | } |
| | | if (entity != null) { |
| | | responseText = EntityUtils.toString(entity); |
| | | } |