| | |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | |
| | | import org.springblade.common.utils.UtilRandom; |
| | | import org.springblade.common.utils.sms.AlipaySignature; |
| | | import org.springblade.core.redis.cache.BladeRedis; |
| | | import org.springblade.modules.resource.entity.Sms; |
| | | import org.springblade.modules.resource.service.ISmsService; |
| | | import org.springblade.modules.sms.entity.SmsTemplateEntity; |
| | | import org.springblade.modules.sms.mapper.SmsTemplateMapper; |
| | | import org.springblade.modules.sms.service.ISmsSendService; |
| | |
| | | public static final String SMS_VALIDATE_PHONE = "sms:validate:code:"; |
| | | public static final String SMS_VALIDATE_PHONE_NUM = "sms:validate:phone:"; |
| | | |
| | | // @Autowired |
| | | // private SmsConfig smsConfig; |
| | | |
| | | @Autowired |
| | | private SmsConfig smsConfig; |
| | | private ISmsService iSmsService; |
| | | |
| | | @Override |
| | | public Boolean smsSend(String phone) { |
| | | |
| | | Sms serviceOne = iSmsService.getOne(Wrappers.<Sms>lambdaQuery().eq(Sms::getSmsCode, "106575361457")); |
| | | //发送的手机号 |
| | | List<Map> phonesList = new ArrayList<>(); |
| | | |
| | |
| | | params.put("priority", priority); |
| | | params.put("type", type); |
| | | //创建人主键 |
| | | params.put("sop_create_by", smsConfig.getSopCreateBy()); |
| | | params.put("sop_create_by", serviceOne.getSmsCode()); |
| | | String s = null; |
| | | try { |
| | | s = testGet(params, "message.sop.differentMes"); |
| | | s = testGet(params, "message.sop.differentMes",serviceOne); |
| | | JSONObject jsonObject = JSON.parseObject(s); |
| | | JSONObject messageSopEqualsMesResponse = (JSONObject) jsonObject.get("message_sop_equalsMes_response"); |
| | | if (messageSopEqualsMesResponse.get("code").equals(200)) { |
| | |
| | | return false; |
| | | } |
| | | |
| | | public String testGet(Object bizContent, String method) throws Exception { |
| | | public String testGet(Object bizContent, String method,Sms serviceOne) throws Exception { |
| | | |
| | | // 公共请求参数 |
| | | Map<String, String> params = new HashMap<String, String>(); |
| | | params.put("app_id", smsConfig.getSmsAppId()); |
| | | params.put("app_id", serviceOne.getAccessKey()); |
| | | params.put("method", method); |
| | | params.put("format", "json"); |
| | | params.put("charset", "utf-8"); |
| | |
| | | // 业务参数 |
| | | params.put("biz_content", JSON.toJSONString(bizContent)); |
| | | String content = AlipaySignature.getSignContent(params); |
| | | String sign = AlipaySignature.rsa256Sign(content, smsConfig.getSmsPrivateKey(), "utf-8"); |
| | | String sign = AlipaySignature.rsa256Sign(content, serviceOne.getSecretKey(), "utf-8"); |
| | | params.put("sign", sign); |
| | | |
| | | System.out.println("----------- 请求信息 -----------"); |
| | | System.out.println("请求参数:" + buildParamQuery(params)); |
| | | System.out.println("商户秘钥:" + smsConfig.getSmsPrivateKey()); |
| | | System.out.println("商户秘钥:" + serviceOne.getSecretKey()); |
| | | System.out.println("待签名内容:" + content); |
| | | System.out.println("签名(sign):" + sign); |
| | | System.out.println("URL参数:" + buildUrlQuery(params)); |
| | | |
| | | System.out.println("----------- 返回结果 -----------"); |
| | | String responseData = HttpClientUtils.doGet(smsConfig.getSmsUrl(), params);// 发送请求 |
| | | String responseData = HttpClientUtils.doGet(serviceOne.getRemark(), params);// 发送请求 |
| | | System.out.println("返回数据" + responseData); |
| | | return responseData; |
| | | } |