mirror of
https://gitcode.com/ageerle/ruoyi-ai.git
synced 2026-04-11 18:47:20 +00:00
init
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
package com.xmzs.common.config;
|
||||
|
||||
/**
|
||||
* 支付配置信息
|
||||
*
|
||||
* @author Admin
|
||||
*/
|
||||
public class PayConfig {
|
||||
|
||||
/**
|
||||
* 商户ID
|
||||
*/
|
||||
public static String pid = "xx";
|
||||
|
||||
/**
|
||||
* 支付方式
|
||||
*/
|
||||
public static String type = "wxpay";
|
||||
|
||||
/**
|
||||
* 接口地址
|
||||
*/
|
||||
public static String payUrl = "https://pay.bluetuo.com/mapi.php";
|
||||
|
||||
/**
|
||||
* 服务器异步通知地址
|
||||
*/
|
||||
public static String notify_url = "http://xx/pay/returnUrl";
|
||||
|
||||
/**
|
||||
* 页面跳转通知地址
|
||||
*/
|
||||
public static String return_url = "http://xx/pay/notifyUrl";
|
||||
|
||||
/**
|
||||
* 设备类型
|
||||
*/
|
||||
public static String device = "pc";
|
||||
|
||||
/**
|
||||
* 加密方式默认MD5
|
||||
*/
|
||||
|
||||
public static String sign_type = "MD5";
|
||||
|
||||
/**
|
||||
* 私钥
|
||||
*/
|
||||
public static String key = "xx";
|
||||
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
package com.xmzs.common.response;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 支付结果响应
|
||||
*
|
||||
* @author: wangle
|
||||
* @date: 2023/7/3
|
||||
*/
|
||||
@Data
|
||||
public class PayResponse {
|
||||
|
||||
/**
|
||||
* 商户ID
|
||||
*/
|
||||
private String pid;
|
||||
|
||||
/**
|
||||
* 易支付订单号
|
||||
*/
|
||||
|
||||
@JsonProperty("trade_no")
|
||||
private String trade_no;
|
||||
|
||||
/**
|
||||
* 商户订单号
|
||||
*/
|
||||
@JsonProperty("out_trade_no")
|
||||
private String out_trade_no;
|
||||
|
||||
/**
|
||||
* 支付方式
|
||||
*/
|
||||
private String type;
|
||||
|
||||
/**
|
||||
* 商品名称
|
||||
*/
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* 商品金额
|
||||
*/
|
||||
private String money;
|
||||
|
||||
/**
|
||||
* 支付状态
|
||||
*/
|
||||
@JsonProperty("trade_status")
|
||||
private String trade_status;
|
||||
|
||||
/**
|
||||
* 业务扩展参数
|
||||
*/
|
||||
private String param;
|
||||
|
||||
/**
|
||||
* 签名字符串
|
||||
*/
|
||||
private String sign;
|
||||
|
||||
/**
|
||||
* 签名类型
|
||||
*/
|
||||
@JsonProperty("sign_type")
|
||||
private String signType;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package com.xmzs.common.service;
|
||||
|
||||
/**
|
||||
* 支付服务
|
||||
*
|
||||
* @author: wangle
|
||||
* @date: 2023/7/3
|
||||
*/
|
||||
public interface PayService {
|
||||
|
||||
/**
|
||||
* 获取支付地址
|
||||
*
|
||||
* @Date 2023/7/3
|
||||
* @param orderNo
|
||||
* @param name
|
||||
* @param money
|
||||
* @param clientIp
|
||||
* @return String
|
||||
**/
|
||||
String getPayUrl(String orderNo, String name, double money, String clientIp);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
package com.xmzs.common.service.impl;
|
||||
|
||||
import cn.hutool.http.HttpUtil;
|
||||
import cn.hutool.json.JSONObject;
|
||||
import com.xmzs.common.config.PayConfig;
|
||||
import com.xmzs.common.service.PayService;
|
||||
import com.xmzs.common.utils.MD5Util;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 支付服务
|
||||
* @author Admin
|
||||
*/
|
||||
@Service
|
||||
public class PayServiceImpl implements PayService {
|
||||
@Override
|
||||
public String getPayUrl(String orderNo, String name, double money, String clientIp) {
|
||||
String out_trade_no = orderNo, sign = "";
|
||||
//封装请求参数
|
||||
String mdString = "clientip=" + clientIp + "&device=" + PayConfig.device + "&money=" + money + "&name=" + name + "&" +
|
||||
"notify_url=" + PayConfig.notify_url + "&out_trade_no=" + out_trade_no + "&pid=" + PayConfig.pid + "&return_url=" + PayConfig.return_url +
|
||||
"&type=" + PayConfig.type + PayConfig.key;
|
||||
sign = MD5Util.GetMD5Code(mdString);
|
||||
Map<String, Object> map = new HashMap<>(10);
|
||||
map.put("clientip", clientIp);
|
||||
map.put("device", PayConfig.device);
|
||||
map.put("money", money);
|
||||
map.put("name", name);
|
||||
map.put("notify_url", PayConfig.notify_url);
|
||||
map.put("out_trade_no", out_trade_no);
|
||||
map.put("pid", PayConfig.pid);
|
||||
map.put("return_url", PayConfig.return_url);
|
||||
map.put("sign_type", PayConfig.sign_type);
|
||||
map.put("type", PayConfig.type);
|
||||
map.put("sign", sign);
|
||||
String body = HttpUtil.post(PayConfig.payUrl, map);
|
||||
JSONObject jsonObject = new JSONObject(body);
|
||||
return (String) jsonObject.get("qrcode");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,107 @@
|
||||
package com.xmzs.common.utils;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
|
||||
/**
|
||||
* MD5 算法
|
||||
*
|
||||
* @author Admin
|
||||
*/
|
||||
public class MD5Util {
|
||||
|
||||
/**
|
||||
* 全局数组
|
||||
*/
|
||||
public final static String[] strDigits = { "0", "1", "2", "3", "4", "5",
|
||||
"6", "7", "8", "9", "a", "b", "c", "d", "e", "f" };
|
||||
|
||||
public MD5Util() {
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回形式为数字跟字符串
|
||||
*
|
||||
* @Date 2023/7/3
|
||||
* @param bByte
|
||||
* @return String
|
||||
**/
|
||||
public static String byteToArrayString(byte bByte) {
|
||||
int iRet = bByte;
|
||||
if (iRet < 0) {
|
||||
iRet += 256;
|
||||
}
|
||||
int iD1 = iRet / 16;
|
||||
int iD2 = iRet % 16;
|
||||
return strDigits[iD1] + strDigits[iD2];
|
||||
}
|
||||
|
||||
/**
|
||||
* 转换字节数组为16进制字串
|
||||
*
|
||||
* @Date 2023/7/3
|
||||
* @param bByte
|
||||
* @return String
|
||||
**/
|
||||
public static String byteToString(byte[] bByte) {
|
||||
StringBuffer sBuffer = new StringBuffer();
|
||||
for (int i = 0; i < bByte.length; i++) {
|
||||
sBuffer.append(byteToArrayString(bByte[i]));
|
||||
}
|
||||
return sBuffer.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成md5代码
|
||||
*
|
||||
* @Date 2023/7/3
|
||||
* @param strObj
|
||||
* @return String
|
||||
**/
|
||||
public static String GetMD5Code(String strObj) {
|
||||
String resultString = null;
|
||||
try {
|
||||
resultString = new String(strObj);
|
||||
MessageDigest md = MessageDigest.getInstance("MD5");
|
||||
resultString = byteToString(md.digest(strObj.getBytes()));
|
||||
} catch (NoSuchAlgorithmException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
return resultString;
|
||||
}
|
||||
|
||||
/**
|
||||
* 组装签名的字段
|
||||
*
|
||||
* @param params 参数
|
||||
* @param urlEncoder 是否urlEncoder
|
||||
* @return {String}
|
||||
*/
|
||||
public static String packageSign(Map<String, Object> params, boolean urlEncoder) {
|
||||
// 先将参数以其参数名的字典序升序进行排序
|
||||
TreeMap<String, Object> sortedParams = new TreeMap<String, Object>(params);
|
||||
// 遍历排序后的字典,将所有参数按"key=value"格式拼接在一起
|
||||
StringBuilder sb = new StringBuilder();
|
||||
boolean first = true;
|
||||
for (Map.Entry<String, Object> param : sortedParams.entrySet()) {
|
||||
String value = String.valueOf(param.getValue());
|
||||
if (StrUtil.isBlank(value)) {
|
||||
continue;
|
||||
}
|
||||
if (first) {
|
||||
first = false;
|
||||
} else {
|
||||
sb.append("&");
|
||||
}
|
||||
sb.append(param.getKey()).append("=");
|
||||
sb.append(value);
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user