This commit is contained in:
hucs
2024-07-30 10:57:01 +08:00
parent 97613cca71
commit f48e2d8fe4
6 changed files with 495 additions and 7 deletions

View File

@@ -17,6 +17,7 @@ import com.starry.admin.modules.clerk.service.IPlayClerkCommodityService;
import com.starry.admin.modules.clerk.service.IPlayClerkUserInfoService;
import com.starry.admin.modules.clerk.service.IPlayClerkUserReviewInfoService;
import com.starry.admin.modules.personnel.service.IPlayPersonnelGroupInfoService;
import com.starry.admin.modules.weichat.service.WxCustomMpService;
import com.starry.admin.utils.SecurityUtils;
import com.starry.common.utils.IdUtils;
import org.springframework.beans.BeanUtils;
@@ -34,25 +35,24 @@ import java.util.List;
*/
@Service
public class PlayClerkUserReviewInfoServiceImpl extends ServiceImpl<PlayClerkUserReviewInfoMapper, PlayClerkUserReviewInfoEntity> implements IPlayClerkUserReviewInfoService {
@Resource
private PlayClerkUserReviewInfoMapper playClerkUserReviewInfoMapper;
@Resource
private IPlayClerkUserInfoService playClerkUserInfoService;
@Resource
private IPlayPersonnelGroupInfoService playClerkGroupInfoService;
@Resource
private IPlayClerkCommodityService clerkCommodityService;
@Resource
private WxCustomMpService wxCustomMpService;
@Override
public PlayClerkUserReviewInfoEntity queryByClerkId(String clerkId,String reviewState) {
public PlayClerkUserReviewInfoEntity queryByClerkId(String clerkId, String reviewState) {
LambdaQueryWrapper<PlayClerkUserReviewInfoEntity> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(PlayClerkUserReviewInfoEntity::getClerkId, clerkId);
queryWrapper.eq(PlayClerkUserReviewInfoEntity::getReviewState,reviewState);
queryWrapper.eq(PlayClerkUserReviewInfoEntity::getReviewState, reviewState);
return this.baseMapper.selectOne(queryWrapper);
}
@@ -150,8 +150,9 @@ public class PlayClerkUserReviewInfoServiceImpl extends ServiceImpl<PlayClerkUse
@Override
public void updateDataReviewState(PlayClerkUserReviewStateEditVo vo) {
PlayClerkUserReviewInfoEntity entity = this.selectPlayClerkUserReviewInfoById(vo.getId());
PlayClerkUserInfoEntity userInfo = playClerkUserInfoService.queryByUserId(entity.getClerkId());
if ("1".equals(vo.getReviewState())) {
PlayClerkUserInfoEntity userInfo = playClerkUserInfoService.queryByUserId(entity.getClerkId());
BeanUtils.copyProperties(entity, userInfo);
userInfo.setClerkState("1");
userInfo.setId(entity.getClerkId());
@@ -161,6 +162,9 @@ public class PlayClerkUserReviewInfoServiceImpl extends ServiceImpl<PlayClerkUse
}
BeanUtils.copyProperties(vo, entity);
this.update(entity);
// 发送消息
wxCustomMpService.sendCheckMessage(entity, userInfo, vo.getReviewState());
}
/**

View File

@@ -0,0 +1,33 @@
package com.starry.admin.modules.system.controller;
import com.starry.admin.utils.SmsUtils;
import com.starry.common.result.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
/**
* 动态接口
*
* @author admin
* @since 2024/5/20 下午11:19
**/
@Slf4j
@RestController
@RequestMapping("/system/sms")
public class SysSmsController {
@Resource
private SmsUtils smsUtils;
@GetMapping("/send")
public R sendSms(@RequestParam("phone") String phone) {
smsUtils.sendSmsApi(phone);
return R.ok();
}
}

View File

@@ -0,0 +1,33 @@
package com.starry.admin.modules.weichat.controller;
import com.starry.admin.utils.SmsUtils;
import com.starry.common.result.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
/**
* 动态接口
*
* @author admin
* @since 2024/5/20 下午11:19
**/
@Slf4j
@RestController
@RequestMapping("/wx/sms")
public class WxSmsController {
@Resource
private SmsUtils smsUtils;
@GetMapping("/send")
public R sendSms(@RequestParam("phone") String phone) {
smsUtils.sendSmsApi(phone);
return R.ok();
}
}

View File

@@ -1,11 +1,14 @@
package com.starry.admin.modules.weichat.service;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.StrUtil;
import com.github.binarywang.wxpay.config.WxPayConfig;
import com.github.binarywang.wxpay.service.WxPayService;
import com.github.binarywang.wxpay.service.impl.WxPayServiceImpl;
import com.starry.admin.common.exception.CustomException;
import com.starry.admin.common.play.wx.WeChatConstants;
import com.starry.admin.modules.clerk.module.entity.PlayClerkUserInfoEntity;
import com.starry.admin.modules.clerk.module.entity.PlayClerkUserReviewInfoEntity;
import com.starry.admin.modules.custom.module.entity.PlayCustomUserInfoEntity;
import com.starry.admin.modules.custom.service.IPlayCustomUserInfoService;
import com.starry.admin.modules.order.module.entity.PlayOrderInfoEntity;
@@ -23,6 +26,7 @@ import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
/**
@@ -109,4 +113,29 @@ public class WxCustomMpService {
}
}
public void sendCheckMessage(PlayClerkUserReviewInfoEntity entity, PlayClerkUserInfoEntity userInfo, String reviewState) {
String touser = userInfo.getOpenid();
String template_id = "U51bGIGq6NsoF-zS-THOs8u-ogtMo0um_tdJoDhBd0A";
String tenantKey = tenantService.selectSysTenantByTenantId(userInfo.getTenantId()).getTenantKey();
String url = "http://" + tenantKey + ".july.hucs.top/clerk/";
WxMpTemplateMessage templateMessage = new WxMpTemplateMessage();
templateMessage.setTemplateId(template_id);
templateMessage.setToUser(touser);
templateMessage.setUrl(url);
List<WxMpTemplateData> data = new ArrayList<>();
data.add(new WxMpTemplateData("short_thing7", reviewState.equals("1") ? "通过" : "拒绝"));
data.add(new WxMpTemplateData("thing2", entity.getNickname()));
data.add(new WxMpTemplateData("thing11", entity.getWeiChatCode()));
data.add(new WxMpTemplateData("time8", DateUtil.format(new Date(), "yyyy-MM-dd HH:mm:ss")));
templateMessage.setData(data);
try {
proxyWxMpService().getTemplateMsgService().sendTemplateMsg(templateMessage);
} catch (WxErrorException e) {
log.error(e.getMessage(), e);
}
}
}

View File

@@ -0,0 +1,315 @@
package com.starry.admin.utils;
import org.apache.commons.lang3.StringUtils;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpDelete;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.methods.HttpPut;
import org.apache.http.conn.ClientConnectionManager;
import org.apache.http.conn.scheme.Scheme;
import org.apache.http.conn.scheme.SchemeRegistry;
import org.apache.http.conn.ssl.SSLSocketFactory;
import org.apache.http.entity.ByteArrayEntity;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import javax.net.ssl.SSLContext;
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException;
import java.security.cert.X509Certificate;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
public class HttpUtils {
/**
* get
*
* @param host
* @param path
* @param method
* @param headers
* @param querys
* @return
* @throws Exception
*/
public static HttpResponse doGet(String host, String path, String method,
Map<String, String> headers,
Map<String, String> querys)
throws Exception {
HttpClient httpClient = wrapClient(host);
HttpGet request = new HttpGet(buildUrl(host, path, querys));
for (Map.Entry<String, String> e : headers.entrySet()) {
request.addHeader(e.getKey(), e.getValue());
}
return httpClient.execute(request);
}
/**
* post form
*
* @param host
* @param path
* @param method
* @param headers
* @param querys
* @param bodys
* @return
* @throws Exception
*/
public static HttpResponse doPost(String host, String path, String method,
Map<String, String> headers,
Map<String, String> querys,
Map<String, String> bodys)
throws Exception {
HttpClient httpClient = wrapClient(host);
HttpPost request = new HttpPost(buildUrl(host, path, querys));
for (Map.Entry<String, String> e : headers.entrySet()) {
request.addHeader(e.getKey(), e.getValue());
}
if (bodys != null) {
List<NameValuePair> nameValuePairList = new ArrayList<NameValuePair>();
for (String key : bodys.keySet()) {
nameValuePairList.add(new BasicNameValuePair(key, bodys.get(key)));
}
UrlEncodedFormEntity formEntity = new UrlEncodedFormEntity(nameValuePairList, "utf-8");
formEntity.setContentType("application/x-www-form-urlencoded; charset=UTF-8");
request.setEntity(formEntity);
}
return httpClient.execute(request);
}
/**
* Post String
*
* @param host
* @param path
* @param method
* @param headers
* @param querys
* @param body
* @return
* @throws Exception
*/
public static HttpResponse doPost(String host, String path, String method,
Map<String, String> headers,
Map<String, String> querys,
String body)
throws Exception {
HttpClient httpClient = wrapClient(host);
HttpPost request = new HttpPost(buildUrl(host, path, querys));
for (Map.Entry<String, String> e : headers.entrySet()) {
request.addHeader(e.getKey(), e.getValue());
}
if (StringUtils.isNotBlank(body)) {
request.setEntity(new StringEntity(body, "utf-8"));
}
return httpClient.execute(request);
}
/**
* Post stream
*
* @param host
* @param path
* @param method
* @param headers
* @param querys
* @param body
* @return
* @throws Exception
*/
public static HttpResponse doPost(String host, String path, String method,
Map<String, String> headers,
Map<String, String> querys,
byte[] body)
throws Exception {
HttpClient httpClient = wrapClient(host);
HttpPost request = new HttpPost(buildUrl(host, path, querys));
for (Map.Entry<String, String> e : headers.entrySet()) {
request.addHeader(e.getKey(), e.getValue());
}
if (body != null) {
request.setEntity(new ByteArrayEntity(body));
}
return httpClient.execute(request);
}
/**
* Put String
*
* @param host
* @param path
* @param method
* @param headers
* @param querys
* @param body
* @return
* @throws Exception
*/
public static HttpResponse doPut(String host, String path, String method,
Map<String, String> headers,
Map<String, String> querys,
String body)
throws Exception {
HttpClient httpClient = wrapClient(host);
HttpPut request = new HttpPut(buildUrl(host, path, querys));
for (Map.Entry<String, String> e : headers.entrySet()) {
request.addHeader(e.getKey(), e.getValue());
}
if (StringUtils.isNotBlank(body)) {
request.setEntity(new StringEntity(body, "utf-8"));
}
return httpClient.execute(request);
}
/**
* Put stream
*
* @param host
* @param path
* @param method
* @param headers
* @param querys
* @param body
* @return
* @throws Exception
*/
public static HttpResponse doPut(String host, String path, String method,
Map<String, String> headers,
Map<String, String> querys,
byte[] body)
throws Exception {
HttpClient httpClient = wrapClient(host);
HttpPut request = new HttpPut(buildUrl(host, path, querys));
for (Map.Entry<String, String> e : headers.entrySet()) {
request.addHeader(e.getKey(), e.getValue());
}
if (body != null) {
request.setEntity(new ByteArrayEntity(body));
}
return httpClient.execute(request);
}
/**
* Delete
*
* @param host
* @param path
* @param method
* @param headers
* @param querys
* @return
* @throws Exception
*/
public static HttpResponse doDelete(String host, String path, String method,
Map<String, String> headers,
Map<String, String> querys)
throws Exception {
HttpClient httpClient = wrapClient(host);
HttpDelete request = new HttpDelete(buildUrl(host, path, querys));
for (Map.Entry<String, String> e : headers.entrySet()) {
request.addHeader(e.getKey(), e.getValue());
}
return httpClient.execute(request);
}
private static String buildUrl(String host, String path, Map<String, String> querys) throws UnsupportedEncodingException {
StringBuilder sbUrl = new StringBuilder();
sbUrl.append(host);
if (!StringUtils.isBlank(path)) {
sbUrl.append(path);
}
if (null != querys) {
StringBuilder sbQuery = new StringBuilder();
for (Map.Entry<String, String> query : querys.entrySet()) {
if (0 < sbQuery.length()) {
sbQuery.append("&");
}
if (StringUtils.isBlank(query.getKey()) && !StringUtils.isBlank(query.getValue())) {
sbQuery.append(query.getValue());
}
if (!StringUtils.isBlank(query.getKey())) {
sbQuery.append(query.getKey());
if (!StringUtils.isBlank(query.getValue())) {
sbQuery.append("=");
sbQuery.append(URLEncoder.encode(query.getValue(), "utf-8"));
}
}
}
if (0 < sbQuery.length()) {
sbUrl.append("?").append(sbQuery);
}
}
return sbUrl.toString();
}
private static HttpClient wrapClient(String host) {
HttpClient httpClient = new DefaultHttpClient();
if (host.startsWith("https://")) {
sslClient(httpClient);
}
return httpClient;
}
private static void sslClient(HttpClient httpClient) {
try {
SSLContext ctx = SSLContext.getInstance("TLS");
X509TrustManager tm = new X509TrustManager() {
public X509Certificate[] getAcceptedIssuers() {
return null;
}
public void checkClientTrusted(X509Certificate[] xcs, String str) {
}
public void checkServerTrusted(X509Certificate[] xcs, String str) {
}
};
ctx.init(null, new TrustManager[]{tm}, null);
SSLSocketFactory ssf = new SSLSocketFactory(ctx);
ssf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
ClientConnectionManager ccm = httpClient.getConnectionManager();
SchemeRegistry registry = ccm.getSchemeRegistry();
registry.register(new Scheme("https", 443, ssf));
} catch (KeyManagementException ex) {
throw new RuntimeException(ex);
} catch (NoSuchAlgorithmException ex) {
throw new RuntimeException(ex);
}
}
}

View File

@@ -0,0 +1,74 @@
package com.starry.admin.utils;
import cn.hutool.core.util.RandomUtil;
import com.starry.common.redis.RedisCache;
import lombok.extern.slf4j.Slf4j;
import org.apache.http.HttpResponse;
import org.apache.http.util.EntityUtils;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
/**
* @Author: huchuansai
* @Date: 2024/7/29 5:41 PM
* @Description:
*/
@Slf4j
@Service
public class SmsUtils {
@Resource
private RedisCache redisCache;
// 发送短信验证码接口
public void sendSmsApi(String phone) {
String code = RandomUtil.randomNumbers(4);
sendSms(phone, code, "CST_paqequfcmkuv11286");
String key = "sms:phone:" + phone;
// 存放到redis里
redisCache.setCacheObject(key, code, 10L, java.util.concurrent.TimeUnit.MINUTES);
}
// 校验短信验证码是否正确
public void checkSmsCode(String phone, String code) {
String key = "sms:phone:" + phone;
Object data = redisCache.getCacheObject(key);
if (Objects.isNull(data)) {
throw new RuntimeException("短信验证码无效或已过期");
}
if (!code.equals(data.toString())) {
throw new RuntimeException("短信验证码错误");
}
}
private static void sendSms(String phone, String code, String templateId) {
String host = "https://wwsms.market.alicloudapi.com";
String path = "/send_sms";
String method = "POST";
String appcode = "18639b38538849e1bc8a3413a8d0c0e5";
Map<String, String> headers = new HashMap<>();
headers.put("Authorization", "APPCODE " + appcode);
headers.put("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
Map<String, String> querys = new HashMap<>();
Map<String, String> bodys = new HashMap<>();
bodys.put("content", "code:" + code);
bodys.put("template_id", templateId); //注意模板CST_11253 仅作调试使用,下发短信不稳定,请联系客服报备自己的专属签名模板,以保障业务稳定使用
bodys.put("phone_number", phone);
try {
HttpResponse response = HttpUtils.doPost(host, path, method, headers, querys, bodys);
String resp = EntityUtils.toString(response.getEntity());
log.info("send sms result" + resp);
} catch (Exception e) {
log.error(e.getMessage(), e);
throw new RuntimeException(e);
}
}
public static void main(String[] args) {
sendSms("15974132949", "123456", "CST_paqequfcmkuv11286");
}
}