commit
45b9d0587d
@ -0,0 +1,25 @@ |
||||
package com.order.consumer; |
||||
|
||||
import com.hfkj.model.order.OrderModel; |
||||
import com.hfkj.service.order.BsOrderService; |
||||
import lombok.extern.slf4j.Slf4j; |
||||
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener; |
||||
import org.apache.rocketmq.spring.core.RocketMQListener; |
||||
import org.springframework.stereotype.Component; |
||||
|
||||
import javax.annotation.Resource; |
||||
|
||||
@Component |
||||
@Slf4j |
||||
@RocketMQMessageListener(consumerGroup = "order-cancel-group", topic = "order-topic",selectorExpression = "cancel") |
||||
public class OrderCancelConsumer implements RocketMQListener<OrderModel> { |
||||
|
||||
@Resource |
||||
private BsOrderService orderService; |
||||
|
||||
@Override |
||||
public void onMessage(OrderModel order) { |
||||
// 取消订单
|
||||
orderService.cancel(order.getOrderNo()); |
||||
} |
||||
} |
@ -0,0 +1,24 @@ |
||||
package com.order.consumer; |
||||
|
||||
import com.hfkj.model.order.OrderModel; |
||||
import com.hfkj.service.order.BsOrderService; |
||||
import lombok.extern.slf4j.Slf4j; |
||||
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener; |
||||
import org.apache.rocketmq.spring.core.RocketMQListener; |
||||
import org.springframework.stereotype.Component; |
||||
|
||||
import javax.annotation.Resource; |
||||
|
||||
@Component |
||||
@Slf4j |
||||
@RocketMQMessageListener(consumerGroup = "order-profit-sharing-group", topic = "order-topic",selectorExpression = "profit-sharing") |
||||
public class OrderProfitSharingConsumer implements RocketMQListener<OrderModel> { |
||||
|
||||
@Resource |
||||
private BsOrderService orderService; |
||||
|
||||
@Override |
||||
public void onMessage(OrderModel order) { |
||||
|
||||
} |
||||
} |
@ -0,0 +1,90 @@ |
||||
package com.order.controller; |
||||
|
||||
import com.alibaba.fastjson.JSONObject; |
||||
import com.hfkj.common.utils.ResponseMsgUtil; |
||||
import com.hfkj.entity.BsOrder; |
||||
import com.hfkj.model.ResponseData; |
||||
import com.hfkj.model.order.OrderModel; |
||||
import com.hfkj.service.order.BsOrderService; |
||||
import com.hfkj.sysenum.order.OrderPayChannelEnum; |
||||
import com.hfkj.sysenum.order.OrderPayTypeEnum; |
||||
import com.hfkj.sysenum.order.OrderStatusEnum; |
||||
import io.swagger.annotations.Api; |
||||
import io.swagger.annotations.ApiOperation; |
||||
import org.slf4j.Logger; |
||||
import org.slf4j.LoggerFactory; |
||||
import org.springframework.stereotype.Controller; |
||||
import org.springframework.web.bind.annotation.RequestBody; |
||||
import org.springframework.web.bind.annotation.RequestMapping; |
||||
import org.springframework.web.bind.annotation.RequestMethod; |
||||
import org.springframework.web.bind.annotation.ResponseBody; |
||||
|
||||
import javax.annotation.Resource; |
||||
import javax.servlet.http.HttpServletResponse; |
||||
import java.io.PrintWriter; |
||||
import java.util.Date; |
||||
import java.util.HashMap; |
||||
import java.util.Map; |
||||
|
||||
/** |
||||
* @className: OrderPayNotifyController |
||||
* @author: HuRui |
||||
* @date: 2024/5/7 |
||||
**/ |
||||
@Controller |
||||
@RequestMapping(value="/notify") |
||||
@Api(value="通知业务") |
||||
public class OrderPayNotifyController { |
||||
Logger log = LoggerFactory.getLogger(OrderPayNotifyController.class); |
||||
@Resource |
||||
private BsOrderService orderService; |
||||
|
||||
@RequestMapping(value="/huipay",method = RequestMethod.POST) |
||||
@ResponseBody |
||||
@ApiOperation(value = "【惠支付】主扫通知") |
||||
public void huipay(@RequestBody String body, HttpServletResponse response) { |
||||
try { |
||||
log.info("===============惠支付回调start=================="); |
||||
JSONObject dataObject = JSONObject.parseObject(body); |
||||
// 处理业务
|
||||
log.info("开始处理业务"); |
||||
log.info("惠支付-回调参数: " + dataObject); |
||||
|
||||
// 查询交易订单
|
||||
OrderModel order = orderService.getDetail(dataObject.getString("outTradeNo")); |
||||
if (order != null && order.getOrderStatus().equals(OrderStatusEnum.status1.getCode())) { |
||||
// 支付方式 微信:WECHAT 支付宝:ALIPAY 银联:UQRCODEPAY
|
||||
String payMode = dataObject.getString("payMode"); |
||||
if ("WECHAT".equals(payMode)) { |
||||
order.setPayType(OrderPayTypeEnum.type1.getCode()); |
||||
|
||||
} else if ("ALIPAY".equals(payMode)) { |
||||
order.setPayType(OrderPayTypeEnum.type2.getCode()); |
||||
} |
||||
order.setPayChannel(OrderPayChannelEnum.type1.getCode()); |
||||
order.setPayTime(new Date(dataObject.getLong("payTime"))); |
||||
order.setPaySerialNo(dataObject.getString("accTradeNo")); |
||||
orderService.orderPaySuccessHandle(order); |
||||
} |
||||
log.info("处理业务完成"); |
||||
log.info("============回调任务End============="); |
||||
|
||||
response.setCharacterEncoding("UTF-8"); |
||||
response.setContentType("text/html;charset=utf-8"); |
||||
PrintWriter writer= response.getWriter(); |
||||
|
||||
JSONObject postJson = new JSONObject(); |
||||
postJson.put("code" ,"SUCCESS"); |
||||
postJson.put("message" ,"执行成功"); |
||||
writer.write(postJson.toJSONString()); |
||||
writer.flush(); |
||||
writer.close(); |
||||
|
||||
} catch (Exception e) { |
||||
log.error("订单处理异常", e); |
||||
} finally { |
||||
log.info("===============微信支付回调end=================="); |
||||
} |
||||
} |
||||
|
||||
} |
@ -1,358 +1,97 @@ |
||||
package com.hfkj.common.pay.util; |
||||
|
||||
import com.hfkj.common.pay.entity.WechatPayReturnParam; |
||||
import com.hfkj.common.pay.entity.WechatReturn; |
||||
import com.alibaba.fastjson.JSONObject; |
||||
import org.apache.commons.lang3.StringUtils; |
||||
import org.dom4j.DocumentException; |
||||
import org.slf4j.Logger; |
||||
import org.slf4j.LoggerFactory; |
||||
import org.xml.sax.SAXException; |
||||
|
||||
import javax.xml.parsers.ParserConfigurationException; |
||||
import java.io.IOException; |
||||
import java.io.UnsupportedEncodingException; |
||||
import java.lang.reflect.Field; |
||||
import javax.xml.bind.annotation.adapters.HexBinaryAdapter; |
||||
import java.security.MessageDigest; |
||||
import java.security.NoSuchAlgorithmException; |
||||
import java.util.ArrayList; |
||||
import java.util.Arrays; |
||||
import java.util.Map; |
||||
import java.util.SortedMap; |
||||
import java.util.Set; |
||||
|
||||
/** |
||||
* |
||||
* @Title: |
||||
* @Description: 微信支付签名工具类 |
||||
* @author: 魏真峰 |
||||
* @param: |
||||
* @return: |
||||
* @throws |
||||
* 签名工具类 |
||||
*/ |
||||
public class SignatureUtil { |
||||
|
||||
private static Logger logger = LoggerFactory.getLogger(SignatureUtil.class); |
||||
|
||||
/** |
||||
* 将字节数组转换为十六进制字符串 |
||||
* @param byteArray |
||||
* 参数签名 |
||||
* @param param 参数 |
||||
* @param key 秘钥 |
||||
* @return |
||||
* @throws Exception |
||||
*/ |
||||
private static String byteToStr(byte[] byteArray) { |
||||
String strDigest = ""; |
||||
for (int i = 0; i < byteArray.length; i++) { |
||||
strDigest += byteToHexStr(byteArray[i]); |
||||
} |
||||
return strDigest; |
||||
public static String createSign(Object param, String key) throws Exception { |
||||
Map map = JSONObject.parseObject(JSONObject.toJSONString(param), Map.class); |
||||
return md5Encode(paramSort(map, key).getBytes()); |
||||
} |
||||
|
||||
/** |
||||
* 将字节转换为十六进制字符串 |
||||
* |
||||
* @param mByte |
||||
* 验证签名 |
||||
* @param checkSign 需验证的签名字符串 |
||||
* @param param 参数 |
||||
* @param key 秘钥 |
||||
* @return |
||||
* @throws Exception |
||||
*/ |
||||
private static String byteToHexStr(byte mByte) { |
||||
char[] Digit = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' }; |
||||
char[] tempArr = new char[2]; |
||||
tempArr[0] = Digit[(mByte >>> 4) & 0X0F]; |
||||
tempArr[1] = Digit[mByte & 0X0F]; |
||||
return new String(tempArr); |
||||
public static Boolean checkSign(String checkSign,Object param, String key) throws Exception { |
||||
Map map = JSONObject.parseObject(JSONObject.toJSONString(param), Map.class); |
||||
// 去除签名
|
||||
map.remove("sign"); |
||||
if (checkSign.equals(createSign(map, key))) { |
||||
return true; |
||||
} |
||||
|
||||
/** |
||||
* 获取签名 |
||||
* |
||||
* @param o |
||||
* 待加密的对象 该处仅限于Class |
||||
* @return |
||||
*/ |
||||
public static String createSign(Object o, String apiKey, String encoding) { |
||||
String result = notSignParams(o, apiKey); |
||||
result = MD5Util.MD5Encode(result, encoding).toUpperCase(); |
||||
return result; |
||||
return false; |
||||
} |
||||
|
||||
/** |
||||
* 签名算法 |
||||
* |
||||
* @param o |
||||
* 要参与签名的数据对象 |
||||
* @param apiKey |
||||
* API密匙 |
||||
* @return 签名 |
||||
* @throws IllegalAccessException |
||||
* 参数排序 |
||||
* @param param |
||||
* @return |
||||
*/ |
||||
public static String notSignParams(Object o, String apiKey) { |
||||
ArrayList<String> list = new ArrayList<>(); |
||||
String result = ""; |
||||
try { |
||||
Class<?> cls = o.getClass(); |
||||
Field[] fields = cls.getDeclaredFields(); |
||||
list = getFieldList(fields, o); |
||||
Field[] superFields = cls.getSuperclass().getDeclaredFields(); // 获取父类的私有属性
|
||||
list.addAll(getFieldList(superFields, o)); |
||||
int size = list.size(); |
||||
String[] arrayToSort = list.toArray(new String[size]); |
||||
Arrays.sort(arrayToSort, String.CASE_INSENSITIVE_ORDER); // 严格按字母表顺序排序
|
||||
public static String paramSort(final Map<String, Object> param, String key) { |
||||
Set<String> keySet = param.keySet(); |
||||
String[] keyArray = keySet.toArray(new String[keySet.size()]); |
||||
Arrays.sort(keyArray); |
||||
StringBuilder sb = new StringBuilder(); |
||||
for (int i = 0; i < size; i++) { |
||||
sb.append(arrayToSort[i]); |
||||
} |
||||
result = sb.toString(); |
||||
if (apiKey != null && !"".equals(apiKey)) { |
||||
result += "key=" + apiKey; |
||||
for (String k : keyArray) { |
||||
if (StringUtils.isBlank(sb.toString())) { |
||||
sb.append(k).append("=").append(param.get(k)); |
||||
} else { |
||||
result = result.substring(0, result.lastIndexOf("&")); |
||||
sb.append("&").append(k).append("=").append(param.get(k)); |
||||
} |
||||
} catch (Exception e) { |
||||
e.printStackTrace(); |
||||
} |
||||
return result; |
||||
sb.append("&key=").append(key); |
||||
return sb.toString(); |
||||
} |
||||
|
||||
/** |
||||
* 将字段集合方法转换 |
||||
* |
||||
* @param array |
||||
* @param object |
||||
* MD5加密 |
||||
* @param data |
||||
* @return |
||||
* @throws IllegalArgumentException |
||||
* @throws IllegalAccessException |
||||
* @throws Exception |
||||
*/ |
||||
private static ArrayList<String> getFieldList(Field[] array, Object object) |
||||
throws IllegalArgumentException, IllegalAccessException { |
||||
ArrayList<String> list = new ArrayList<String>(); |
||||
for (Field f : array) { |
||||
f.setAccessible(true); |
||||
if (f.get(object) != null && f.get(object) != "" && !f.getName().equals("serialVersionUID") |
||||
&& !f.getName().equals("sign")) { |
||||
if (f.getName().equals("packageStr")) { |
||||
list.add("package" + "=" + f.get(object) + "&"); |
||||
} else { |
||||
list.add(f.getName() + "=" + f.get(object) + "&"); |
||||
} |
||||
} |
||||
} |
||||
return list; |
||||
public static String md5Encode(byte[] data) throws Exception { |
||||
// 初始化MessageDigest
|
||||
MessageDigest md = MessageDigest.getInstance("MD5"); |
||||
// 执行摘要信息
|
||||
byte[] digest = md.digest(data); |
||||
// 将摘要信息转换为32位的十六进制字符串
|
||||
return new String(new HexBinaryAdapter().marshal(digest)); |
||||
} |
||||
|
||||
public static void main(String[] args) throws Exception { |
||||
String paramStr = "{\n" + |
||||
" \"merchantNo\": \"2023090816465844909\",\n" + |
||||
" \"outTradeNo\": \"ZF1130202305051459532538973458\",\n" + |
||||
" \"payMode\": \"WECHAT\",\n" + |
||||
" \"totalAmount\": 0.01,\n" + |
||||
" \"transType\": \"JSAPI\",\n" + |
||||
" \"profitSharing\": 0,\n" + |
||||
" \"specialField\": \"测试\"" + |
||||
"}"; |
||||
String sign = createSign(JSONObject.parseObject(paramStr), "ZatCMLMSZxnkc2rk7dtpTORMLcKetcKt"); |
||||
System.out.println(sign); |
||||
} |
||||
|
||||
/** |
||||
* 通过Map<String,Object>中的所有元素参与签名 |
||||
* |
||||
* @param map |
||||
* 待参与签名的map集合 |
||||
* @params apikey apikey中 如果为空则不参与签名,如果不为空则参与签名 |
||||
* @return |
||||
*/ |
||||
public static String createSign(Map<Object, Object> map, String apiKey, String characterEncoding) { |
||||
String result = notSignParams(map, apiKey); |
||||
result = MD5Util.MD5Encode(result, characterEncoding).toUpperCase(); |
||||
logger.debug("sign result {}", result); |
||||
return result; |
||||
} |
||||
|
||||
/** |
||||
* 通过Map<SortedMap,Object>中的所有元素参与签名 |
||||
* |
||||
* @param map |
||||
* 待参与签名的map集合 |
||||
* @params apikey apikey中 如果为空则不参与签名,如果不为空则参与签名 |
||||
* @return |
||||
*/ |
||||
public static String createSign(SortedMap<Object, Object> map, String apiKey, String characterEncoding) { |
||||
String result = notSignParams(map, apiKey); |
||||
result = MD5Util.MD5Encode(result, characterEncoding).toUpperCase(); |
||||
logger.debug("sign result {}", result); |
||||
return result; |
||||
} |
||||
|
||||
/** |
||||
* 通过Map<SortedMap,Object>中的所有元素参与签名 |
||||
* |
||||
* @param map |
||||
* 待参与签名的map集合 |
||||
* @params apikey apikey中 如果为空则不参与签名,如果不为空则参与签名 |
||||
* @return |
||||
*/ |
||||
public static String createSha1Sign(SortedMap<Object, Object> map, String apiKey, String characterEncoding) { |
||||
String result = notSignParams(map, apiKey); |
||||
MessageDigest md = null; |
||||
try { |
||||
md = MessageDigest.getInstance("SHA-1"); |
||||
byte[] digest = md.digest(result.getBytes(characterEncoding)); |
||||
result = byteToStr(digest); |
||||
} catch (NoSuchAlgorithmException e) { |
||||
e.printStackTrace(); |
||||
} catch (UnsupportedEncodingException e) { |
||||
e.printStackTrace(); |
||||
} |
||||
return result; |
||||
} |
||||
|
||||
/** |
||||
* 返回未加密的字符串 |
||||
* |
||||
* @param params |
||||
* @param apiKey |
||||
* @return 待加密的字符串 |
||||
*/ |
||||
private static String notSignParams(SortedMap<Object, Object> params, String apiKey) { |
||||
StringBuffer buffer = new StringBuffer(); |
||||
for (Map.Entry<Object, Object> entry : params.entrySet()) { |
||||
if (!org.springframework.util.StringUtils.isEmpty(entry.getValue())) { |
||||
buffer.append(entry.getKey() + "=" + entry.getValue() + "&"); |
||||
} |
||||
} |
||||
buffer.append("key=" + apiKey); |
||||
return buffer.toString(); |
||||
} |
||||
|
||||
/** |
||||
* 返回未加密的字符串 |
||||
* |
||||
* @param params |
||||
* @param apiKey |
||||
* @return 待加密的字符串 |
||||
*/ |
||||
public static String notSignParams(Map<Object, Object> params, String apiKey) { |
||||
ArrayList<String> list = new ArrayList<>(); |
||||
for (Map.Entry<Object, Object> entry : params.entrySet()) { |
||||
if (entry.getValue() != "" && entry.getValue() != null) { |
||||
list.add(entry.getKey() + "=" + entry.getValue() + "&"); |
||||
} |
||||
} |
||||
int size = list.size(); |
||||
String[] arrayToSort = list.toArray(new String[size]); |
||||
Arrays.sort(arrayToSort, String.CASE_INSENSITIVE_ORDER); |
||||
StringBuilder sb = new StringBuilder(); |
||||
for (int i = 0; i < size; i++) { |
||||
sb.append(arrayToSort[i]); |
||||
} |
||||
String result = sb.toString(); |
||||
if (apiKey != null && !"".equals(apiKey)) { |
||||
result += "key=" + apiKey; |
||||
} else { |
||||
result = result.substring(0, result.lastIndexOf("&")); |
||||
} |
||||
return result; |
||||
} |
||||
|
||||
/** |
||||
* 从API返回的XML数据里面重新计算一次签名 |
||||
* |
||||
* @param responseString |
||||
* API返回的XML数据 |
||||
* @param apiKey |
||||
* Key |
||||
* @return 新的签名 |
||||
* @throws ParserConfigurationException |
||||
* @throws IOException |
||||
* @throws SAXException |
||||
*/ |
||||
public static String reCreateSign(String responseString, String apiKey, String encoding) |
||||
throws IOException, SAXException, ParserConfigurationException { |
||||
Map<String, Object> map = XmlUtil.parseXmlToMap(responseString, encoding); |
||||
// 清掉返回数据对象里面的Sign数据(不能把这个数据也加进去进行签名),然后用签名算法进行签名
|
||||
map.replace("sign",""); |
||||
// 将API返回的数据根据用签名算法进行计算新的签名,用来跟API返回的签名进行比较
|
||||
return createSign(map, apiKey, encoding); |
||||
} |
||||
|
||||
|
||||
/** |
||||
* 检验API返回的数据里面的签名是否合法,规则是:按参数名称a-z排序,遇到空值的参数不参加签名 |
||||
* |
||||
* @param resultXml |
||||
* API返回的XML数据字符串 |
||||
* @param apiKey |
||||
* Key |
||||
* @return API签名是否合法 |
||||
* @throws ParserConfigurationException |
||||
* @throws IOException |
||||
* @throws SAXException |
||||
* @throws DocumentException |
||||
*/ |
||||
public static boolean checkIsSignValidFromWeiXin(String checktXml, String apiKey, String encoding) |
||||
throws ParserConfigurationException, IOException, SAXException, DocumentException { |
||||
SortedMap<String, String> map = XmlUtil.parseXmlToTreeMap(checktXml,encoding); |
||||
String signFromresultXml = (String) map.get("sign"); |
||||
WechatReturn wechatReturn = new WechatReturn(); |
||||
wechatReturn.setAppid((String) map.get("appid")); |
||||
wechatReturn.setMch_id((String) map.get("mch_id")); |
||||
wechatReturn.setNonce_str((String) map.get("nonce_str")); |
||||
wechatReturn.setPrepay_id((String) map.get("prepay_id")); |
||||
wechatReturn.setResult_code((String) map.get("result_code")); |
||||
wechatReturn.setReturn_code((String) map.get("return_code")); |
||||
wechatReturn.setReturn_msg((String) map.get("return_msg")); |
||||
wechatReturn.setTrade_type((String) map.get("trade_type")); |
||||
if (StringUtils.isEmpty(signFromresultXml)) { |
||||
logger.debug("API返回的数据签名数据不存在"); |
||||
return false; |
||||
} |
||||
if(!("SUCCESS".equals(map.get("return_code"))) || !("SUCCESS".equals(map.get("result_code")))){ |
||||
logger.debug("返回代码不成功!"); |
||||
return false; |
||||
} |
||||
logger.debug("服务器回包里面的签名{}", signFromresultXml); |
||||
// 清掉返回数据对象里面的Sign数据(不能把这个数据也加进去进行签名),然后用签名算法进行签名
|
||||
// 将API返回的数据根据用签名算法进行计算新的签名,用来跟API返回的签名进行比较
|
||||
// String signForAPIResponse = createSign(wechatReturn, apiKey, encoding);
|
||||
// if (!signForAPIResponse.equals(signFromresultXml)) {
|
||||
// // 签名验不过,表示这个API返回的数据有可能已经被篡改了
|
||||
// logger.debug("API返回的数据签名验证不通过");
|
||||
// return false;
|
||||
// }
|
||||
logger.debug("API返回的数据签名验证通过"); |
||||
return true; |
||||
} |
||||
/** |
||||
* |
||||
* @Title: reCheckIsSignValidFromWeiXin |
||||
* @Description: 微信支付异步回调,检验签名是否正确 |
||||
* @author: 魏真峰 |
||||
* @param: [checktXml, apiKey, encoding] |
||||
* @return: boolean |
||||
* @throws |
||||
*/ |
||||
public static boolean reCheckIsSignValidFromWeiXin(String checktXml, String apiKey, String encoding) |
||||
throws ParserConfigurationException, IOException, SAXException, DocumentException { |
||||
SortedMap<String, String> map = XmlUtil.parseXmlToTreeMap(checktXml,encoding); |
||||
String signFromresultXml = (String) map.get("sign"); |
||||
WechatPayReturnParam wechatPayReturnParam = new WechatPayReturnParam(); |
||||
wechatPayReturnParam.setAppid((String) map.get("appid")); |
||||
wechatPayReturnParam.setAttach((String) map.get("attach")); |
||||
wechatPayReturnParam.setBank_type((String) map.get("bank_type")); |
||||
wechatPayReturnParam.setCash_fee((String) map.get("cash_fee")); |
||||
wechatPayReturnParam.setFee_type((String) map.get("fee_type")); |
||||
wechatPayReturnParam.setIs_subscribe((String) map.get("is_subscribe")); |
||||
wechatPayReturnParam.setMch_id((String) map.get("mch_id")); |
||||
wechatPayReturnParam.setNonce_str((String) map.get("nonce_str")); |
||||
wechatPayReturnParam.setOpenid((String) map.get("openid")); |
||||
wechatPayReturnParam.setOut_trade_no((String) map.get("out_trade_no")); |
||||
wechatPayReturnParam.setResult_code((String) map.get("result_code")); |
||||
wechatPayReturnParam.setReturn_code((String) map.get("return_code")); |
||||
wechatPayReturnParam.setTime_end((String) map.get("time_end")); |
||||
wechatPayReturnParam.setTotal_fee((String) map.get("total_fee")); |
||||
wechatPayReturnParam.setTrade_type((String) map.get("trade_type")); |
||||
wechatPayReturnParam.setTransaction_id((String) map.get("transaction_id")); |
||||
if (StringUtils.isEmpty(signFromresultXml)) { |
||||
logger.debug("API返回的数据签名数据不存在"); |
||||
return false; |
||||
} |
||||
if(!("SUCCESS".equals(map.get("return_code"))) || !("SUCCESS".equals(map.get("result_code")))){ |
||||
logger.debug("返回代码不成功!"); |
||||
return false; |
||||
} |
||||
logger.debug("服务器回包里面的签名{}", signFromresultXml); |
||||
// 清掉返回数据对象里面的Sign数据(不能把这个数据也加进去进行签名),然后用签名算法进行签名
|
||||
// 将API返回的数据根据用签名算法进行计算新的签名,用来跟API返回的签名进行比较
|
||||
String signForAPIResponse = createSign(wechatPayReturnParam, apiKey, encoding); |
||||
if (!signForAPIResponse.equals(signFromresultXml)) { |
||||
// 签名验不过,表示这个API返回的数据有可能已经被篡改了
|
||||
logger.debug("API返回的数据签名验证不通过"); |
||||
return false; |
||||
} |
||||
logger.debug("API返回的数据签名验证通过"); |
||||
return true; |
||||
} |
||||
} |
||||
|
@ -0,0 +1,28 @@ |
||||
package com.hfkj.mqtopic; |
||||
|
||||
import lombok.Getter; |
||||
|
||||
/** |
||||
* 订单主题 |
||||
* @author hurui |
||||
*/ |
||||
@Getter |
||||
public enum OrderTopic { |
||||
// 订单主题
|
||||
ORDER_TOPIC("order-topic", "订单主题"), |
||||
// 订单取消
|
||||
ORDER_TOPIC_CANCEL(ORDER_TOPIC.getTopic() + ":cancel", "订单取消"), |
||||
// 订单退款成功业务
|
||||
ORDER_TOPIC_REFUND_SUCCESS(ORDER_TOPIC.getTopic() + ":refund-success", "订单退款成功业务"), |
||||
// 订单分账业务
|
||||
ORDER_TOPIC_PROFIT_SHARING(ORDER_TOPIC.getTopic() + ":profit-sharing", "订单分账业务"), |
||||
; |
||||
|
||||
private String topic; |
||||
private String name; |
||||
|
||||
OrderTopic(String topic, String name) { |
||||
this.topic = topic; |
||||
this.name = name; |
||||
} |
||||
} |
@ -0,0 +1,30 @@ |
||||
package com.hfkj.service.order; |
||||
|
||||
import com.hfkj.entity.BsOrderChild; |
||||
import com.hfkj.model.order.OrderChildModel; |
||||
import com.hfkj.model.order.OrderModel; |
||||
|
||||
import java.util.List; |
||||
|
||||
/** |
||||
* @className: BsOrderChildService |
||||
* @author: HuRui |
||||
* @date: 2024/5/6 |
||||
**/ |
||||
public interface BsOrderChildService { |
||||
|
||||
/** |
||||
* 编辑数据 |
||||
* @param data |
||||
*/ |
||||
void editData(BsOrderChild data); |
||||
|
||||
|
||||
/** |
||||
* 查询子订单 |
||||
* @param orderNo |
||||
* @return |
||||
*/ |
||||
List<OrderChildModel> getOrderChildListByOrderNo(String orderNo); |
||||
|
||||
} |
@ -0,0 +1,53 @@ |
||||
package com.hfkj.service.order; |
||||
|
||||
import com.hfkj.common.utils.RedisUtil; |
||||
import com.hfkj.entity.BsOrderChild; |
||||
import com.hfkj.model.order.OrderModel; |
||||
import com.hfkj.sysenum.order.OrderChildProductTypeEnum; |
||||
import org.slf4j.Logger; |
||||
import org.slf4j.LoggerFactory; |
||||
import org.springframework.beans.factory.annotation.Autowired; |
||||
import org.springframework.stereotype.Component; |
||||
import org.springframework.transaction.annotation.Isolation; |
||||
import org.springframework.transaction.annotation.Propagation; |
||||
import org.springframework.transaction.annotation.Transactional; |
||||
|
||||
import javax.annotation.Resource; |
||||
|
||||
/** |
||||
* 取消订单业务 |
||||
* @className: OrderCancelService |
||||
* @author: HuRui |
||||
* @date: 2024/5/7 |
||||
**/ |
||||
@Component |
||||
public class OrderCancelService { |
||||
Logger log = LoggerFactory.getLogger(OrderCancelService.class); |
||||
@Autowired |
||||
private RedisUtil redisUtil; |
||||
@Resource |
||||
private BsOrderService orderService; |
||||
@Resource |
||||
private BsOrderChildService orderChildService; |
||||
|
||||
/** |
||||
* 订单业务处理 |
||||
* @param order |
||||
* @throws Exception |
||||
*/ |
||||
@Transactional( |
||||
propagation= Propagation.REQUIRED, |
||||
isolation = Isolation.READ_COMMITTED, |
||||
timeout = 20, |
||||
rollbackFor = Exception.class) |
||||
public void orderBusHandle(OrderModel order) { |
||||
for (BsOrderChild childOrder : order.getOrderChildList()) { |
||||
if (childOrder.getProductType().equals(OrderChildProductTypeEnum.type1.getCode())) { |
||||
|
||||
} |
||||
} |
||||
|
||||
} |
||||
|
||||
|
||||
} |
@ -0,0 +1,46 @@ |
||||
package com.hfkj.service.order; |
||||
|
||||
import com.hfkj.common.utils.RedisUtil; |
||||
import com.hfkj.entity.BsOrderChild; |
||||
import com.hfkj.model.order.OrderChildModel; |
||||
import com.hfkj.model.order.OrderModel; |
||||
import com.hfkj.sysenum.order.OrderChildProductTypeEnum; |
||||
import org.slf4j.Logger; |
||||
import org.slf4j.LoggerFactory; |
||||
import org.springframework.beans.factory.annotation.Autowired; |
||||
import org.springframework.stereotype.Component; |
||||
import org.springframework.transaction.annotation.Isolation; |
||||
import org.springframework.transaction.annotation.Propagation; |
||||
import org.springframework.transaction.annotation.Transactional; |
||||
|
||||
import javax.annotation.Resource; |
||||
import java.math.BigDecimal; |
||||
|
||||
/** |
||||
* 创建订单业务 |
||||
* @className: OrderCreateService |
||||
* @author: HuRui |
||||
* @date: 2024/5/7 |
||||
**/ |
||||
@Component |
||||
public class OrderCreateService { |
||||
Logger log = LoggerFactory.getLogger(OrderCreateService.class); |
||||
@Autowired |
||||
private RedisUtil redisUtil; |
||||
@Resource |
||||
private BsOrderService orderService; |
||||
@Resource |
||||
private BsOrderChildService orderChildService; |
||||
|
||||
/** |
||||
* 事务产品 |
||||
* @param orderChild 子订单 |
||||
* @throws Exception |
||||
*/ |
||||
public OrderChildModel materialProduct(OrderChildModel orderChild) { |
||||
orderChild.setProductPrice(new BigDecimal("10")); |
||||
return orderChild; |
||||
} |
||||
|
||||
|
||||
} |
@ -0,0 +1,23 @@ |
||||
package com.hfkj.service.order; |
||||
|
||||
import com.hfkj.model.order.OrderModel; |
||||
import org.springframework.stereotype.Component; |
||||
|
||||
/** |
||||
* 订单支付前校验 |
||||
* @className: OrderPayBeforeService |
||||
* @author: HuRui |
||||
* @date: 2024/5/8 |
||||
**/ |
||||
@Component |
||||
public class OrderPayBeforeService { |
||||
|
||||
/** |
||||
* 支付订单校验 |
||||
* @param order |
||||
*/ |
||||
public void payOrderCheck(OrderModel order) { |
||||
|
||||
} |
||||
|
||||
} |
@ -0,0 +1,55 @@ |
||||
package com.hfkj.service.order; |
||||
|
||||
import com.hfkj.common.utils.RedisUtil; |
||||
import com.hfkj.entity.BsOrderChild; |
||||
import com.hfkj.model.order.OrderModel; |
||||
import com.hfkj.sysenum.order.OrderChildProductTypeEnum; |
||||
import com.hfkj.sysenum.order.OrderChildStatusEnum; |
||||
import com.hfkj.sysenum.order.OrderStatusEnum; |
||||
import org.slf4j.Logger; |
||||
import org.slf4j.LoggerFactory; |
||||
import org.springframework.beans.factory.annotation.Autowired; |
||||
import org.springframework.stereotype.Component; |
||||
import org.springframework.transaction.annotation.Isolation; |
||||
import org.springframework.transaction.annotation.Propagation; |
||||
import org.springframework.transaction.annotation.Transactional; |
||||
|
||||
import javax.annotation.Resource; |
||||
import java.util.Date; |
||||
|
||||
/** |
||||
* @className: OrderPaySuccesService |
||||
* @author: HuRui |
||||
* @date: 2024/5/7 |
||||
**/ |
||||
@Component |
||||
public class OrderPaySuccessService { |
||||
Logger log = LoggerFactory.getLogger(OrderPaySuccessService.class); |
||||
@Autowired |
||||
private RedisUtil redisUtil; |
||||
@Resource |
||||
private BsOrderService orderService; |
||||
@Resource |
||||
private BsOrderChildService orderChildService; |
||||
|
||||
/** |
||||
* 订单业务处理 |
||||
* @param order |
||||
* @throws Exception |
||||
*/ |
||||
@Transactional( |
||||
propagation= Propagation.REQUIRED, |
||||
isolation = Isolation.READ_COMMITTED, |
||||
timeout = 20, |
||||
rollbackFor = Exception.class) |
||||
public void orderBusHandle(OrderModel order) { |
||||
for (BsOrderChild childOrder : order.getOrderChildList()) { |
||||
if (childOrder.getProductType().equals(OrderChildProductTypeEnum.type1.getCode())) { |
||||
|
||||
} |
||||
} |
||||
|
||||
} |
||||
|
||||
|
||||
} |
@ -0,0 +1,52 @@ |
||||
package com.hfkj.service.order.impl; |
||||
|
||||
import com.hfkj.dao.BsOrderChildMapper; |
||||
import com.hfkj.entity.BsOrderChild; |
||||
import com.hfkj.entity.BsOrderChildExample; |
||||
import com.hfkj.model.order.OrderChildModel; |
||||
import com.hfkj.service.order.BsOrderChildService; |
||||
import org.springframework.beans.BeanUtils; |
||||
import org.springframework.stereotype.Service; |
||||
|
||||
import javax.annotation.Resource; |
||||
import java.util.ArrayList; |
||||
import java.util.Date; |
||||
import java.util.List; |
||||
|
||||
/** |
||||
* @className: BsOrderChildServiceImpl |
||||
* @author: HuRui |
||||
* @date: 2024/5/6 |
||||
**/ |
||||
@Service("orderChildService") |
||||
public class BsOrderChildServiceImpl implements BsOrderChildService { |
||||
@Resource |
||||
private BsOrderChildMapper orderChildMapper; |
||||
|
||||
@Override |
||||
public void editData(BsOrderChild data) { |
||||
data.setUpdateTime(new Date()); |
||||
if (data.getId() == null) { |
||||
data.setCreateTime(new Date()); |
||||
orderChildMapper.insert(data); |
||||
} else { |
||||
orderChildMapper.updateByPrimaryKey(data); |
||||
} |
||||
} |
||||
|
||||
@Override |
||||
public List<OrderChildModel> getOrderChildListByOrderNo(String orderNo) { |
||||
BsOrderChildExample example = new BsOrderChildExample(); |
||||
example.createCriteria().andOrderNoEqualTo(orderNo); |
||||
example.setOrderByClause("id"); |
||||
List<BsOrderChild> list = orderChildMapper.selectByExample(example); |
||||
|
||||
List<OrderChildModel> orderChildModelList = new ArrayList<>(); |
||||
for (BsOrderChild orderChild : list) { |
||||
OrderChildModel childModel = new OrderChildModel(); |
||||
BeanUtils.copyProperties(orderChild, childModel); |
||||
orderChildModelList.add(childModel); |
||||
} |
||||
return orderChildModelList; |
||||
} |
||||
} |
@ -0,0 +1,93 @@ |
||||
package com.hfkj.service.pay; |
||||
|
||||
import com.alibaba.fastjson.JSONObject; |
||||
import com.hfkj.common.exception.ErrorCode; |
||||
import com.hfkj.common.exception.ErrorHelp; |
||||
import com.hfkj.common.exception.SysCode; |
||||
import com.hfkj.common.pay.util.SignatureUtil; |
||||
import com.hfkj.common.utils.HttpsUtils; |
||||
import com.hfkj.config.CommonSysConst; |
||||
import com.hfkj.model.order.OrderModel; |
||||
import com.hfkj.sysenum.order.OrderPayTypeEnum; |
||||
import org.slf4j.Logger; |
||||
import org.slf4j.LoggerFactory; |
||||
import org.springframework.stereotype.Component; |
||||
|
||||
import java.math.BigDecimal; |
||||
import java.util.HashMap; |
||||
import java.util.Map; |
||||
import java.util.SortedMap; |
||||
import java.util.TreeMap; |
||||
|
||||
/** |
||||
* @className: HuiPayService |
||||
* @author: HuRui |
||||
* @date: 2024/5/7 |
||||
**/ |
||||
public class HuiPayService { |
||||
static Logger log = LoggerFactory.getLogger(HuiPayService.class); |
||||
// 请求地址
|
||||
private final static String REQUEST_URL = "https://pay.dctpay.com/openApi/v1/"; |
||||
private final static String DEFAULT_MER_NO = "2023041916292112804"; |
||||
private final static String DEFAULT_MER_KEY = "2jLO2WjXcSRSzTCaca0Kmv0OFrfYBbrA"; |
||||
|
||||
public static Map<Object, Object> preorder(String openId,OrderModel order) throws Exception { |
||||
try { |
||||
log.info("=============== start 惠支付 start =================="); |
||||
Map<String, Object> param = new HashMap<>(); |
||||
param.put("merchantNo", DEFAULT_MER_NO); |
||||
param.put("outTradeNo", order.getOrderNo()); |
||||
param.put("transType", "JSAPI"); |
||||
if (OrderPayTypeEnum.type1.getCode() == order.getPayType()) { |
||||
param.put("payMode", "WECHAT"); |
||||
} else if (OrderPayTypeEnum.type2.getCode() == order.getPayType()) { |
||||
param.put("payMode", "ALIPAY"); |
||||
} |
||||
param.put("totalAmount", order.getPayRealPrice()); |
||||
param.put("profitSharing", "0"); |
||||
param.put("subject", "购买产品"); |
||||
param.put("userId", openId); |
||||
param.put("notifyUrl", CommonSysConst.getSysConfig().getHuiPayPreorderNotifyUrl()); |
||||
param.put("sign", SignatureUtil.createSign(param, DEFAULT_MER_KEY)); |
||||
|
||||
log.info("请求地址:" + (REQUEST_URL + "trade/preorder")); |
||||
log.info("请求参数:" + JSONObject.toJSONString(param)); |
||||
|
||||
JSONObject response = HttpsUtils.doPost(REQUEST_URL + "trade/preorder", param, new HashMap<>()); |
||||
log.info("响应参数:" + response.toJSONString()); |
||||
|
||||
if (response != null && response.getString("return_code").equals("000000")) { |
||||
JSONObject payParam = response.getJSONObject("return_data").getJSONObject("payParam"); |
||||
SortedMap<Object, Object> sortedMap = new TreeMap<>(); |
||||
sortedMap.put("appId", payParam.get("app_id")); |
||||
sortedMap.put("nonceStr", payParam.get("nonce_str")); |
||||
sortedMap.put("timeStamp", payParam.get("time_stamp")); |
||||
sortedMap.put("signType", "MD5"); |
||||
sortedMap.put("package", payParam.get("package")); |
||||
sortedMap.put("prepay_id", payParam.get("prepay_id")); |
||||
sortedMap.put("sign", payParam.get("pay_sign")); |
||||
return sortedMap; |
||||
|
||||
} |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, response.getString("return_msg")); |
||||
|
||||
} catch (Exception e) { |
||||
log.info("出现异常:" + e.getMessage()); |
||||
throw e; |
||||
} finally { |
||||
log.info("=============== end 惠支付 end =================="); |
||||
} |
||||
} |
||||
|
||||
|
||||
public static JSONObject refund() throws Exception { |
||||
Map<String,Object> param = new HashMap<>(); |
||||
param.put("merchantNo", ""); |
||||
param.put("outTradeNo", ""); |
||||
param.put("refundTradeNo", ""); |
||||
param.put("refundAmount", ""); |
||||
param.put("sign" , SignatureUtil.createSign(param, DEFAULT_MER_KEY)); |
||||
return HttpsUtils.doPost(REQUEST_URL + "trade/refund", param, new HashMap<>()); |
||||
|
||||
} |
||||
} |
@ -0,0 +1,53 @@ |
||||
package com.hfkj.sysenum.order; |
||||
|
||||
import lombok.Data; |
||||
import lombok.Getter; |
||||
|
||||
/** |
||||
* @className: OrderChildStatusEnum |
||||
* @author: HuRui |
||||
* @date: 2024/5/6 |
||||
**/ |
||||
@Getter |
||||
public enum OrderChildStatusEnum { |
||||
/** |
||||
* 待支付 |
||||
*/ |
||||
status1(1, "待支付"), |
||||
|
||||
/** |
||||
* 已支付 |
||||
*/ |
||||
status2(2, "已支付"), |
||||
|
||||
/** |
||||
* 已完成 |
||||
*/ |
||||
status3(3, "已完成"), |
||||
|
||||
/** |
||||
* 已退款 |
||||
*/ |
||||
status4(4, "已退款"), |
||||
|
||||
/** |
||||
* 已取消 |
||||
*/ |
||||
status5(5, "已取消"), |
||||
|
||||
/** |
||||
* 退款中 |
||||
*/ |
||||
status6(6, "退款中"), |
||||
; |
||||
|
||||
private final int code; |
||||
|
||||
private final String name; |
||||
|
||||
|
||||
OrderChildStatusEnum(int code, String name) { |
||||
this.code = code; |
||||
this.name = name; |
||||
} |
||||
} |
@ -0,0 +1,35 @@ |
||||
package com.hfkj.sysenum.order; |
||||
|
||||
import lombok.Getter; |
||||
|
||||
/** |
||||
* 交易支付渠道 |
||||
* @className: OrderPayModelEnum |
||||
* @author: HuRui |
||||
* @date: 2024/5/7 |
||||
**/ |
||||
@Getter |
||||
public enum OrderPayChannelEnum { |
||||
/** |
||||
* 微信 |
||||
*/ |
||||
type1(1, "惠支付"), |
||||
/** |
||||
* 支付宝 |
||||
*/ |
||||
type2(2, "微信合作商"), |
||||
/** |
||||
* 快捷支付 |
||||
*/ |
||||
type3(3, "贵州银行"), |
||||
; |
||||
|
||||
private final int code; |
||||
|
||||
private final String name; |
||||
|
||||
OrderPayChannelEnum(int code, String name) { |
||||
this.code = code; |
||||
this.name = name; |
||||
} |
||||
} |
@ -0,0 +1,35 @@ |
||||
package com.hfkj.sysenum.order; |
||||
|
||||
import lombok.Getter; |
||||
|
||||
/** |
||||
* 交易支付类型 |
||||
* @className: OrderPayModelEnum |
||||
* @author: HuRui |
||||
* @date: 2024/5/7 |
||||
**/ |
||||
@Getter |
||||
public enum OrderPayTypeEnum { |
||||
/** |
||||
* 微信 |
||||
*/ |
||||
type1(1, "微信"), |
||||
/** |
||||
* 支付宝 |
||||
*/ |
||||
type2(2, "支付宝"), |
||||
/** |
||||
* 快捷支付 |
||||
*/ |
||||
type3(3, "快捷支付"), |
||||
; |
||||
|
||||
private final int code; |
||||
|
||||
private final String name; |
||||
|
||||
OrderPayTypeEnum(int code, String name) { |
||||
this.code = code; |
||||
this.name = name; |
||||
} |
||||
} |
@ -0,0 +1,6 @@ |
||||
wechatMaAppid= |
||||
wechatMaSecret= |
||||
wechatMpAppid= |
||||
wechatMpSecret= |
||||
|
||||
huiPayPreorderNotifyUrl= |
@ -1 +1 @@ |
||||
package com.user.controller;
import com.alibaba.fastjson.JSONObject;
import com.hfkj.common.exception.ErrorCode;
import com.hfkj.common.exception.ErrorHelp;
import com.hfkj.common.exception.SysCode;
import com.hfkj.common.utils.MemberValidateUtil;
import com.hfkj.common.utils.RedisUtil;
import com.hfkj.common.utils.ResponseMsgUtil;
import com.hfkj.config.MessageConfig;
import com.hfkj.model.ResponseData;
import com.hfkj.service.user.BsUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.annotation.Resource;
import java.util.Random;
/**
* @Auther: 胡锐
* @Description:
* @Date: 2021/3/26 23:08
*/
@Controller
@RequestMapping(value = "/sms")
@Api(value = "短信服务")
public class SmsController {
private static Logger log = LoggerFactory.getLogger(SmsController.class);
@Resource
private RedisUtil redisUtil;
@Resource
private BsUserService userService;
@RequestMapping(value = "/getLoginSMSCode", method = RequestMethod.POST)
@ResponseBody
@ApiOperation(value = "获取登录验证码")
public ResponseData getLoginSMSCode(@RequestBody JSONObject body) {
try {
if (body == null || StringUtils.isBlank(body.getString("phone"))) {
log.error("LoginController --> phone() error!", "请求参数校验失败");
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, "");
}
String phone = body.getString("phone");
// 校验手机号格式
if (MemberValidateUtil.validatePhone(phone) == false) {
log.error("LoginController --> phone() error!", "请输入正确的手机号");
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "请输入正确的手机号");
}
// 生成随机6位验证码
String smsCode = String.valueOf(new Random().nextInt(899999) + 100000);
// MessageConfig.req(phone,smsCode, MessageConfig.HWMSG_ID5);
// 验证码缓存5分钟
redisUtil.set("SMS_CODE:"+phone, smsCode, 60*5);
return ResponseMsgUtil.success("短信发送成功");
} catch (Exception e) {
log.error("SMSController --> getLoginSMSCode() error!", e);
return ResponseMsgUtil.exception(e);
}
}
}
|
||||
package com.user.controller;
import com.alibaba.fastjson.JSONObject;
import com.hfkj.common.exception.ErrorCode;
import com.hfkj.common.exception.ErrorHelp;
import com.hfkj.common.exception.SysCode;
import com.hfkj.common.utils.MemberValidateUtil;
import com.hfkj.common.utils.RedisUtil;
import com.hfkj.common.utils.ResponseMsgUtil;
import com.hfkj.config.MessageConfig;
import com.hfkj.model.ResponseData;
import com.hfkj.service.user.BsUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.annotation.Resource;
import java.util.Random;
/**
* @Auther: 胡锐
* @Description:
* @Date: 2021/3/26 23:08
*/
@Controller
@RequestMapping(value = "/sms")
@Api(value = "短信服务")
public class SmsController {
private static Logger log = LoggerFactory.getLogger(SmsController.class);
@Resource
private RedisUtil redisUtil;
@Resource
private BsUserService userService;
@RequestMapping(value = "/sendLoginSMSCode", method = RequestMethod.POST)
@ResponseBody
@ApiOperation(value = "获取登录验证码")
public ResponseData sendLoginSMSCode(@RequestBody JSONObject body) {
try {
if (body == null || StringUtils.isBlank(body.getString("phone"))) {
log.error("LoginController --> phone() error!", "请求参数校验失败");
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, "");
}
String phone = body.getString("phone");
// 校验手机号格式
if (MemberValidateUtil.validatePhone(phone) == false) {
log.error("LoginController --> phone() error!", "请输入正确的手机号");
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "请输入正确的手机号");
}
// 生成随机6位验证码
String smsCode = String.valueOf(new Random().nextInt(899999) + 100000);
// MessageConfig.req(phone,smsCode, MessageConfig.HWMSG_ID5);
// 验证码缓存5分钟
redisUtil.set("SMS_CODE:"+phone, smsCode, 60*5);
return ResponseMsgUtil.success("短信发送成功");
} catch (Exception e) {
log.error("SMSController --> getLoginSMSCode() error!", e);
return ResponseMsgUtil.exception(e);
}
}
}
|
Loading…
Reference in new issue