继续开发支付场景
This commit is contained in:
parent
5fcafe8d39
commit
952a286a59
43
doc/支付流程图.drawio
Normal file
43
doc/支付流程图.drawio
Normal file
@ -0,0 +1,43 @@
|
||||
<mxfile host="65bd71144e">
|
||||
<diagram id="eUwQ9UTd_wFMP36Shy1F" name="第 1 页">
|
||||
<mxGraphModel dx="1173" dy="766" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="827" pageHeight="1169" math="0" shadow="0">
|
||||
<root>
|
||||
<mxCell id="0"/>
|
||||
<mxCell id="1" parent="0"/>
|
||||
<mxCell id="4" value="" style="edgeStyle=none;html=1;" edge="1" parent="1" source="2" target="3">
|
||||
<mxGeometry relative="1" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="2" value="获取支付链接" style="html=1;" vertex="1" parent="1">
|
||||
<mxGeometry x="400" y="140" width="110" height="50" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="6" value="" style="edgeStyle=none;html=1;" edge="1" parent="1" source="3" target="5">
|
||||
<mxGeometry relative="1" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="3" value="用户支付" style="html=1;" vertex="1" parent="1">
|
||||
<mxGeometry x="400" y="220" width="110" height="50" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="8" value="" style="edgeStyle=none;html=1;" edge="1" parent="1" source="5" target="7">
|
||||
<mxGeometry relative="1" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="5" value="进入支付回调" style="html=1;" vertex="1" parent="1">
|
||||
<mxGeometry x="400" y="310" width="110" height="50" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="17" value="" style="edgeStyle=none;html=1;" edge="1" parent="1" source="7" target="13">
|
||||
<mxGeometry relative="1" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="7" value="验签" style="html=1;" vertex="1" parent="1">
|
||||
<mxGeometry x="400" y="400" width="110" height="50" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="9" value="用户定义的回调业务" style="html=1;" vertex="1" parent="1">
|
||||
<mxGeometry x="400" y="580" width="110" height="50" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="18" value="" style="edgeStyle=none;html=1;" edge="1" parent="1" source="13" target="9">
|
||||
<mxGeometry relative="1" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="13" value="更改订单状态" style="html=1;" vertex="1" parent="1">
|
||||
<mxGeometry x="400" y="490" width="110" height="50" as="geometry"/>
|
||||
</mxCell>
|
||||
</root>
|
||||
</mxGraphModel>
|
||||
</diagram>
|
||||
</mxfile>
|
@ -5,6 +5,7 @@ import java.util.Map;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
@ -14,7 +15,9 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
import com.alipay.easysdk.factory.Factory;
|
||||
import com.alipay.easysdk.payment.page.models.AlipayTradePagePayResponse;
|
||||
import com.ruoyi.common.annotation.Anonymous;
|
||||
import com.ruoyi.common.core.controller.BaseController;
|
||||
import com.ruoyi.common.core.domain.AjaxResult;
|
||||
import com.ruoyi.pay.alipay.service.IAliPayService;
|
||||
import com.ruoyi.pay.domain.PayOrder;
|
||||
import com.ruoyi.pay.service.IPayOrderService;
|
||||
|
||||
@ -28,21 +31,24 @@ import jakarta.servlet.http.HttpServletRequest;
|
||||
* @author zlh
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/alipay")
|
||||
@RequestMapping("/pay/alipay")
|
||||
@ConditionalOnProperty(prefix = "pay.alipay", name = "enabled", havingValue = "true")
|
||||
@Tag(name = "【支付宝】管理")
|
||||
public class AliPayController {
|
||||
public class AliPayController extends BaseController {
|
||||
|
||||
@Autowired
|
||||
private IPayOrderService payOrderService;
|
||||
|
||||
@Autowired(required = false)
|
||||
private IAliPayService aliPayService;
|
||||
|
||||
@Anonymous
|
||||
@Operation(summary = "支付宝支付")
|
||||
@Parameters({
|
||||
@Parameter(name = "orderId", description = "订单号", required = true)
|
||||
})
|
||||
@GetMapping("/pay/{orderNumber}")
|
||||
public AjaxResult pay(@PathVariable String orderNumber) {
|
||||
public AjaxResult pay(@PathVariable(name = "orderNumber") String orderNumber) {
|
||||
AlipayTradePagePayResponse response;
|
||||
PayOrder aliPay = payOrderService.selectPayOrderByOrderNumber(orderNumber);
|
||||
try {
|
||||
@ -53,15 +59,15 @@ public class AliPayController {
|
||||
aliPay.getActualAmount(),
|
||||
"");
|
||||
} catch (Exception e) {
|
||||
System.err.println("调用遭遇异常,原因:" + e.getMessage());
|
||||
throw new RuntimeException(e.getMessage(), e);
|
||||
return error(e.getMessage());
|
||||
}
|
||||
return AjaxResult.success(response.getBody());
|
||||
return success(response.getBody());
|
||||
}
|
||||
|
||||
@Anonymous
|
||||
@Operation(summary = "支付宝支付回调")
|
||||
@PostMapping("/notify") // 注意这里必须是POST接口
|
||||
@Transactional
|
||||
@PostMapping("/notify")
|
||||
public AjaxResult payNotify(HttpServletRequest request) throws Exception {
|
||||
if (request.getParameter("trade_status").equals("TRADE_SUCCESS")) {
|
||||
System.out.println("=========支付宝异步回调========");
|
||||
@ -87,8 +93,11 @@ public class AliPayController {
|
||||
|
||||
// // 更新订单未已支付
|
||||
payOrderService.updateStatus(orderNumber, "已支付");
|
||||
if (aliPayService != null) {
|
||||
aliPayService.callback(params);
|
||||
}
|
||||
}
|
||||
return AjaxResult.success("success");
|
||||
}
|
||||
return success("success");
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,7 @@
|
||||
package com.ruoyi.pay.alipay.service;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public interface IAliPayService {
|
||||
public void callback(Map<String, String> params);
|
||||
}
|
@ -1,20 +1,24 @@
|
||||
package com.ruoyi.pay.sqb.controller;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.ruoyi.common.annotation.Anonymous;
|
||||
import com.ruoyi.common.core.controller.BaseController;
|
||||
import com.ruoyi.common.core.domain.AjaxResult;
|
||||
import com.ruoyi.common.core.domain.R;
|
||||
import com.ruoyi.pay.domain.PayOrder;
|
||||
import com.ruoyi.pay.service.IPayOrderService;
|
||||
import com.ruoyi.pay.sqb.service.ISqbPayService;
|
||||
import com.ruoyi.pay.sqb.service.Impl.SQBServiceImpl;
|
||||
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
@ -24,7 +28,7 @@ import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
|
||||
@Tag(name = "sqb支付")
|
||||
@RestController
|
||||
@RequestMapping("/pay/sql")
|
||||
@RequestMapping("/pay/sqb")
|
||||
@ConditionalOnProperty(prefix = "pay.sqb", name = "enabled", havingValue = "true")
|
||||
public class SQBController extends BaseController {
|
||||
@Autowired
|
||||
@ -32,13 +36,16 @@ public class SQBController extends BaseController {
|
||||
@Autowired
|
||||
private IPayOrderService payOrderServicer;
|
||||
|
||||
@Autowired(required = false)
|
||||
private ISqbPayService sqbPayService;
|
||||
|
||||
@Operation(summary = "获取支付url")
|
||||
@Parameters(value = {
|
||||
@Parameter(name = "orderNumber", description = "订单号", required = true)
|
||||
})
|
||||
@PostMapping("/payUrl")
|
||||
@PostMapping("/url/{orderNumber}")
|
||||
@Anonymous
|
||||
public R<String> payUrl(@RequestParam("orderNumber") String orderNumber) throws Exception {
|
||||
public R<String> payUrl(@PathVariable(name = "orderNumber") String orderNumber) throws Exception {
|
||||
PayOrder payOrder = payOrderServicer.selectPayOrderByOrderNumber(orderNumber);
|
||||
String url = sqbServiceImpl.payUrl(payOrder);
|
||||
return R.ok(url);
|
||||
@ -48,8 +55,8 @@ public class SQBController extends BaseController {
|
||||
@Parameters(value = {
|
||||
@Parameter(name = "orderNumber", description = "订单号", required = true)
|
||||
})
|
||||
@PostMapping("/query")
|
||||
public AjaxResult query(@RequestParam("orderNumber") String orderNumber) throws Exception {
|
||||
@PostMapping("/query/{orderNumber}")
|
||||
public AjaxResult query(@PathVariable(name = "orderNumber") String orderNumber) throws Exception {
|
||||
PayOrder payOrder = payOrderServicer.selectPayOrderByOrderNumber(orderNumber);
|
||||
return success(sqbServiceImpl.query(payOrder));
|
||||
}
|
||||
@ -63,4 +70,18 @@ public class SQBController extends BaseController {
|
||||
Object parse = JSON.parse(refund);
|
||||
return success(parse);
|
||||
}
|
||||
|
||||
@PostMapping("/notify")
|
||||
@Anonymous
|
||||
@Operation(summary = "支付回调")
|
||||
public AjaxResult payNotify(@RequestBody JSONObject jsonObject) throws IOException {
|
||||
// 验签
|
||||
// 修改订单状态
|
||||
// 用户自定义行为
|
||||
if (sqbPayService != null) {
|
||||
sqbPayService.callback(jsonObject);
|
||||
}
|
||||
return AjaxResult.success();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,7 @@
|
||||
package com.ruoyi.pay.sqb.service;
|
||||
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
|
||||
public interface ISqbPayService {
|
||||
public void callback(JSONObject param);
|
||||
}
|
@ -4,22 +4,31 @@ import java.io.UnsupportedEncodingException;
|
||||
import java.net.URLEncoder;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.ruoyi.common.utils.SecurityUtils;
|
||||
import com.ruoyi.common.utils.ServletUtils;
|
||||
import com.ruoyi.common.utils.sign.Md5Utils;
|
||||
import com.ruoyi.pay.domain.PayOrder;
|
||||
import com.ruoyi.pay.sqb.config.SqbConfig;
|
||||
import com.ruoyi.pay.sqb.utils.HttpUtil;
|
||||
|
||||
@Service
|
||||
@ConditionalOnProperty(prefix = "pay.sqb", name = "enabled", havingValue = "true")
|
||||
public class SQBServiceImpl {
|
||||
@Autowired
|
||||
private SqbConfig sqbConstant;
|
||||
private SqbConfig sqbConfig;
|
||||
|
||||
@Value("${pay.sqb.notifyUrl}")
|
||||
private String defaultNotifyUrl;
|
||||
|
||||
@Value("${pay.sqb.notifyBaseUrl}")
|
||||
private String defaultNotifyBaseUrl;
|
||||
|
||||
@Value("${pay.sqb.proxy}")
|
||||
private String proxyPath;
|
||||
|
||||
/**
|
||||
* 计算字符串的MD5值
|
||||
@ -44,17 +53,16 @@ public class SQBServiceImpl {
|
||||
* @return {terminal_sn:"$终端号",terminal_key:"$终端密钥"}
|
||||
*/
|
||||
public JSONObject activate(String code, String deviceId, String clientSn, String name) {
|
||||
String url = sqbConstant.getApiDomain() + "/terminal/activate";
|
||||
String url = sqbConfig.getApiDomain() + "/terminal/activate";
|
||||
JSONObject params = new JSONObject();
|
||||
try {
|
||||
params.put("app_id", sqbConstant.getAppId()); // app_id,必填
|
||||
params.put("app_id", sqbConfig.getAppId()); // app_id,必填
|
||||
params.put("code", code); // 激活码,必填
|
||||
params.put("device_id", deviceId); // 客户方收银终端序列号,需保证同一app_id下唯一,必填。为方便识别,建议格式为“品牌名+门店编号+‘POS’+POS编号“
|
||||
params.put("client_sn", clientSn); // 客户方终端编号,一般客户方或系统给收银终端的编号,必填
|
||||
params.put("name", name); // 客户方终端名称,必填
|
||||
|
||||
String sign = getSign(params.toString() + sqbConstant.getVendorKey());
|
||||
String result = HttpUtil.httpPost(url, params.toString(), sign, sqbConstant.getVendorSn());
|
||||
String sign = getSign(params.toString() + sqbConfig.getVendorKey());
|
||||
String result = HttpUtil.httpPost(url, params.toString(), sign, sqbConfig.getVendorSn());
|
||||
JSONObject retObj = JSON.parseObject(result);
|
||||
String resCode = retObj.get("result_code").toString();
|
||||
if (!resCode.equals("200"))
|
||||
@ -75,15 +83,15 @@ public class SQBServiceImpl {
|
||||
* @return {terminal_sn:"$终端号",terminal_key:"$终端密钥"}
|
||||
*/
|
||||
public JSONObject checkin() {
|
||||
String url = sqbConstant.getApiDomain() + "/terminal/checkin";
|
||||
String url = sqbConfig.getApiDomain() + "/terminal/checkin";
|
||||
JSONObject params = new JSONObject();
|
||||
try {
|
||||
params.put("terminal_sn", sqbConstant.getTerminalSn());
|
||||
params.put("terminal_sn", sqbConfig.getTerminalSn());
|
||||
params.put("device_id", "HUISUAN001POS01");
|
||||
params.put("os_info", "Mac OS");
|
||||
params.put("sdk_version", "Java SDK v1.0");
|
||||
String sign = getSign(params.toString() + sqbConstant.getTerminalKey());
|
||||
String result = HttpUtil.httpPost(url, params.toString(), sign, sqbConstant.getTerminalSn());
|
||||
String sign = getSign(params.toString() + sqbConfig.getTerminalKey());
|
||||
String result = HttpUtil.httpPost(url, params.toString(), sign, sqbConfig.getTerminalSn());
|
||||
JSONObject retObj = JSON.parseObject(result);
|
||||
String resCode = retObj.get("result_code").toString();
|
||||
if (!resCode.equals("200"))
|
||||
@ -104,17 +112,17 @@ public class SQBServiceImpl {
|
||||
* @return
|
||||
*/
|
||||
public String refund(PayOrder payOrder) {
|
||||
String url = sqbConstant.getApiDomain() + "/upay/v2/refund";
|
||||
String url = sqbConfig.getApiDomain() + "/upay/v2/refund";
|
||||
JSONObject params = new JSONObject();
|
||||
try {
|
||||
params.put("terminal_sn", sqbConstant.getTerminalSn()); // 收钱吧终端ID
|
||||
params.put("terminal_sn", sqbConfig.getTerminalSn()); // 收钱吧终端ID
|
||||
params.put("client_sn", payOrder.getOrderNumber()); // 商户系统订单号,必须在商户系统内唯一;且长度不超过64字节
|
||||
params.put("refund_amount", payOrder.getActualAmount()); // 退款金额
|
||||
params.put("refund_amount", payOrder.getTotalAmount()); // 退款金额
|
||||
params.put("refund_request_no", "1"); // 商户退款所需序列号,表明是第几次退款
|
||||
params.put("operator", "kay"); // 门店操作员
|
||||
|
||||
String sign = getSign(params.toString() + sqbConstant.getTerminalKey());
|
||||
String result = HttpUtil.httpPost(url, params.toString(), sign, sqbConstant.getTerminalSn());
|
||||
String sign = getSign(params.toString() + sqbConfig.getTerminalKey());
|
||||
String result = HttpUtil.httpPost(url, params, sign, sqbConfig.getTerminalSn());
|
||||
|
||||
return result;
|
||||
} catch (Exception e) {
|
||||
@ -129,14 +137,14 @@ public class SQBServiceImpl {
|
||||
*/
|
||||
|
||||
public JSONObject query(PayOrder payOrder) {
|
||||
String url = sqbConstant.getApiDomain() + "/upay/v2/query";
|
||||
String url = sqbConfig.getApiDomain() + "/upay/v2/query";
|
||||
JSONObject params = new JSONObject();
|
||||
try {
|
||||
params.put("terminal_sn", sqbConstant.getTerminalSn()); // 终端号
|
||||
params.put("terminal_sn", sqbConfig.getTerminalSn()); // 终端号
|
||||
params.put("client_sn", payOrder.getOrderNumber()); // 商户系统订单号,必须在商户系统内唯一;且长度不超过64字节
|
||||
System.out.println(params.toString() + sqbConstant.getTerminalKey());
|
||||
String sign = getSign(params.toString() + sqbConstant.getTerminalKey());
|
||||
String result = HttpUtil.httpPost(url, params.toString(), sign, sqbConstant.getTerminalSn());
|
||||
System.out.println(params.toString() + sqbConfig.getTerminalKey());
|
||||
String sign = getSign(params.toString() + sqbConfig.getTerminalKey());
|
||||
String result = HttpUtil.httpPost(url, params, sign, sqbConfig.getTerminalSn());
|
||||
JSONObject retObj = JSON.parseObject(result);
|
||||
String resCode = retObj.get("result_code").toString();
|
||||
if (!resCode.equals("200"))
|
||||
@ -149,24 +157,43 @@ public class SQBServiceImpl {
|
||||
}
|
||||
|
||||
public String payUrl(PayOrder payOrder) throws UnsupportedEncodingException {
|
||||
return payUrl(payOrder, null);
|
||||
}
|
||||
|
||||
public String payUrl(PayOrder payOrder, String notifyBaseUrl) throws UnsupportedEncodingException {
|
||||
if (payOrder.getRemark() == null) {
|
||||
payOrder.setRemark("支付");
|
||||
}
|
||||
String orderNotifyUrl;
|
||||
if (notifyBaseUrl != null && !notifyBaseUrl.trim().equals("")) {
|
||||
orderNotifyUrl = notifyBaseUrl + defaultNotifyUrl;
|
||||
} else {
|
||||
if (defaultNotifyBaseUrl != null && !defaultNotifyBaseUrl.trim().equals("")) {
|
||||
orderNotifyUrl = defaultNotifyBaseUrl + proxyPath + defaultNotifyUrl;
|
||||
} else {
|
||||
orderNotifyUrl = "http://" + ServletUtils.getRequest().getServerName() + proxyPath + defaultNotifyUrl;
|
||||
}
|
||||
}
|
||||
System.out.println(orderNotifyUrl);
|
||||
String param = "" +
|
||||
"client_sn=" + payOrder.getOrderNumber() +
|
||||
"&operator=" + "admin" +
|
||||
"¬ify_url=" + orderNotifyUrl +
|
||||
"&operator=" + payOrder.getCreateBy() +
|
||||
"&return_url=" + "https://www.shouqianba.com/" +
|
||||
"&subject=" + payOrder.getRemark() +
|
||||
"&terminal_sn=" + sqbConstant.getTerminalSn() +
|
||||
"&total_amount=" + payOrder.getActualAmount();
|
||||
"&terminal_sn=" + sqbConfig.getTerminalSn() +
|
||||
"&total_amount=" + Long.valueOf(payOrder.getTotalAmount().toString());
|
||||
String urlParam = "" +
|
||||
"client_sn=" + payOrder.getOrderNumber() +
|
||||
"&operator=" + URLEncoder.encode("admin", "UTF-8") +
|
||||
"¬ify_url=" + URLEncoder.encode(orderNotifyUrl, "UTF-8") +
|
||||
"&operator=" + URLEncoder.encode(payOrder.getCreateBy(), "UTF-8") +
|
||||
"&return_url=" + "https://www.shouqianba.com/" +
|
||||
"&subject=" + URLEncoder.encode(payOrder.getRemark(), "UTF-8") +
|
||||
"&terminal_sn=" + sqbConstant.getTerminalSn() +
|
||||
"&total_amount=" + payOrder.getActualAmount();
|
||||
String sign = getSign(param + "&key=" + sqbConstant.getTerminalKey());
|
||||
"&terminal_sn=" + sqbConfig.getTerminalSn() +
|
||||
"&total_amount=" + Long.valueOf(payOrder.getTotalAmount().toString());
|
||||
System.out.println(param);
|
||||
System.out.println(orderNotifyUrl);
|
||||
String sign = getSign(param + "&key=" + sqbConfig.getTerminalKey());
|
||||
return "https://qr.shouqianba.com/gateway?" + urlParam + "&sign=" + sign.toUpperCase();
|
||||
}
|
||||
|
||||
@ -176,18 +203,18 @@ public class SQBServiceImpl {
|
||||
* @return
|
||||
*/
|
||||
public String precreate(PayOrder payOrder, String sn, String payway) {
|
||||
String url = sqbConstant.getApiDomain() + "/upay/v2/precreate";
|
||||
String url = sqbConfig.getApiDomain() + "/upay/v2/precreate";
|
||||
JSONObject params = new JSONObject();
|
||||
try {
|
||||
params.put("terminal_sn", sqbConstant.getTerminalSn()); // 收钱吧终端ID
|
||||
params.put("terminal_sn", sqbConfig.getTerminalSn()); // 收钱吧终端ID
|
||||
params.put("client_sn", payOrder.getOrderNumber()); // 商户系统订单号,必须在商户系统内唯一;且长度不超过32字节
|
||||
params.put("total_amount", payOrder.getActualAmount()); // 交易总金额
|
||||
params.put("total_amount", payOrder.getTotalAmount()); // 交易总金额
|
||||
// params.put("payway", payway); // 支付方式
|
||||
params.put("subject", "无简介"); // 交易简介
|
||||
params.put("operator", SecurityUtils.getUsername()); // 门店操作员
|
||||
|
||||
String sign = getSign(params.toString() + sqbConstant.getTerminalKey());
|
||||
String result = HttpUtil.httpPost(url, params.toString(), sign, sqbConstant.getTerminalSn());
|
||||
String sign = getSign(params.toString() + sqbConfig.getTerminalKey());
|
||||
String result = HttpUtil.httpPost(url, params.toString(), sign, sqbConfig.getTerminalSn());
|
||||
return result;
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
@ -202,7 +229,7 @@ public class SQBServiceImpl {
|
||||
* @return
|
||||
*/
|
||||
public String cancel(String terminal_sn, String terminal_key) {
|
||||
String url = sqbConstant.getApiDomain() + "/upay/v2/cancel";
|
||||
String url = sqbConfig.getApiDomain() + "/upay/v2/cancel";
|
||||
JSONObject params = new JSONObject();
|
||||
try {
|
||||
params.put("terminal_sn", terminal_sn); // 终端号
|
||||
|
@ -7,6 +7,8 @@ import java.security.NoSuchAlgorithmException;
|
||||
import java.security.UnrecoverableKeyException;
|
||||
import java.security.cert.CertificateException;
|
||||
import java.security.cert.X509Certificate;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.net.ssl.SSLContext;
|
||||
|
||||
@ -15,15 +17,15 @@ import org.apache.http.HttpResponse;
|
||||
import org.apache.http.client.ClientProtocolException;
|
||||
import org.apache.http.client.HttpClient;
|
||||
import org.apache.http.client.methods.HttpGet;
|
||||
import org.apache.http.client.methods.HttpPost;
|
||||
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
|
||||
import org.apache.http.conn.ssl.TrustStrategy;
|
||||
import org.apache.http.entity.StringEntity;
|
||||
import org.apache.http.impl.client.CloseableHttpClient;
|
||||
import org.apache.http.impl.client.HttpClients;
|
||||
import org.apache.http.ssl.SSLContextBuilder;
|
||||
import org.apache.http.util.EntityUtils;
|
||||
|
||||
import com.ruoyi.common.utils.http.HttpClientUtil;
|
||||
|
||||
public class HttpUtil {
|
||||
public static String httpPostWithoutException(String url, String string, String sign, String sn) {
|
||||
String xmlRes = "{}";
|
||||
@ -50,27 +52,33 @@ public class HttpUtil {
|
||||
* @param sn: 序列号
|
||||
* @return
|
||||
*/
|
||||
public static String httpPost(String url, String body, String sign, String sn)
|
||||
public static String httpPost(String url, Object body, String sign, String sn)
|
||||
throws UnrecoverableKeyException, NoSuchAlgorithmException, KeyStoreException, KeyManagementException {
|
||||
String xmlRes = "{}";
|
||||
HttpClient client = createSSLClientDefault();
|
||||
HttpPost httpost = new HttpPost(url);
|
||||
// HttpClient client = createSSLClientDefault();
|
||||
// HttpPost httpost = new HttpPost(url);
|
||||
try {
|
||||
// 所有请求的body都需采用UTF-8编码
|
||||
StringEntity entity = new StringEntity(body, "UTF-8");//
|
||||
entity.setContentType("application/json");
|
||||
httpost.setEntity(entity);
|
||||
// 支付平台所有的API仅支持JSON格式的请求调用,HTTP请求头Content-Type设为application/json
|
||||
httpost.addHeader("Content-Type", "application/json");
|
||||
// 支付平台所有的API调用都需要签名验证,签名首部: Authorization: sn + " " + sign
|
||||
httpost.addHeader("Authorization", sn + " " + sign);
|
||||
HttpResponse response = client.execute(httpost);
|
||||
// 所有响应也采用UTF-8编码
|
||||
xmlRes = EntityUtils.toString(response.getEntity(), "UTF-8");
|
||||
} catch (ClientProtocolException e) {
|
||||
Map<String, String> header = new HashMap<>();
|
||||
header.put("Authorization", sn + " " + sign);
|
||||
xmlRes = HttpClientUtil.sendHttpPost(url, body, header);
|
||||
// System.out.println("Request string: " + body);
|
||||
// // 所有请求的body都需采用UTF-8编码
|
||||
// StringEntity entity = new StringEntity(body, "UTF-8");//
|
||||
// entity.setContentType("application/json");
|
||||
// httpost.setEntity(entity);
|
||||
|
||||
} catch (IOException e) {
|
||||
// // 支付平台所有的API仅支持JSON格式的请求调用,HTTP请求头Content-Type设为application/json
|
||||
// httpost.addHeader("Content-Type", "application/json");
|
||||
|
||||
// // 支付平台所有的API调用都需要签名验证,签名首部: Authorization: sn + " " + sign
|
||||
// httpost.addHeader("Authorization", sn + " " + sign);
|
||||
// System.out.println("Authorization" + sn + " " + sign);
|
||||
// HttpResponse response = client.execute(httpost);
|
||||
|
||||
// // 所有响应也采用UTF-8编码
|
||||
// xmlRes = EntityUtils.toString(response.getEntity(), "UTF-8");
|
||||
// System.out.println("Response string: " + xmlRes);
|
||||
} catch (Exception e) {
|
||||
}
|
||||
return xmlRes;
|
||||
}
|
||||
@ -97,7 +105,7 @@ public class HttpUtil {
|
||||
}
|
||||
|
||||
public static String doGet(String url, String parameter) {
|
||||
String uriAPI = url + "?" + parameter; // "http://XX?str=I+am+get+String";
|
||||
String uriAPI = url + "?" + parameter; // "http://XXXXX?str=I+am+get+String";
|
||||
String result = "";
|
||||
HttpClient client = createSSLClientDefault();
|
||||
HttpGet httpRequst = new HttpGet(uriAPI);
|
||||
|
@ -18,6 +18,7 @@ import com.ruoyi.common.core.domain.AjaxResult;
|
||||
import com.ruoyi.pay.domain.PayOrder;
|
||||
import com.ruoyi.pay.service.IPayOrderService;
|
||||
import com.ruoyi.pay.wx.config.WxPayConfig;
|
||||
import com.ruoyi.pay.wx.service.IWxPayService;
|
||||
import com.wechat.pay.java.core.exception.ValidationException;
|
||||
import com.wechat.pay.java.core.notification.NotificationParser;
|
||||
import com.wechat.pay.java.core.notification.RequestParam;
|
||||
@ -32,18 +33,20 @@ import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.Parameters;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
* @author zlh
|
||||
*/
|
||||
@Slf4j
|
||||
@RestController
|
||||
@ConditionalOnProperty(prefix = "pay.wechat", name = "enabled", havingValue = "true")
|
||||
@RequestMapping("/wxPay")
|
||||
@RequestMapping("/pay/wechat")
|
||||
public class WxPayController extends BaseController {
|
||||
@Autowired
|
||||
private WxPayConfig wxPayAppConfig;
|
||||
|
||||
@Autowired(required = false)
|
||||
private IWxPayService wxPayService;
|
||||
|
||||
@Autowired
|
||||
private IPayOrderService payOrderService;
|
||||
|
||||
@ -56,8 +59,8 @@ public class WxPayController extends BaseController {
|
||||
@Parameters({
|
||||
@Parameter(name = "orderNumber", description = "订单号", required = true)
|
||||
})
|
||||
@GetMapping("/pay/{orderNumber}")
|
||||
public AjaxResult pay(@PathVariable String orderNumber) throws Exception {
|
||||
@GetMapping("/url/{orderNumber}")
|
||||
public AjaxResult pay(@PathVariable(name = "orderNumber") String orderNumber) throws Exception {
|
||||
PayOrder aliPay = payOrderService.selectPayOrderByOrderNumber(orderNumber);
|
||||
String amountStr = aliPay.getActualAmount();
|
||||
double amountDouble = Double.parseDouble(amountStr);
|
||||
@ -72,7 +75,7 @@ public class WxPayController extends BaseController {
|
||||
request.setNotifyUrl(wxPayAppConfig.getNotifyUrl());
|
||||
request.setOutTradeNo(aliPay.getOrderNumber());
|
||||
PrepayResponse response = nativePayService.prepay(request);
|
||||
return AjaxResult.success(response.getCodeUrl());
|
||||
return success(response.getCodeUrl());
|
||||
}
|
||||
|
||||
@Anonymous
|
||||
@ -80,8 +83,6 @@ public class WxPayController extends BaseController {
|
||||
@PostMapping("/notify")
|
||||
public AjaxResult WxPayList(HttpServletRequest servletRequest, HttpServletResponse response)
|
||||
throws Exception {
|
||||
log.info("=========微信异步回调========");
|
||||
|
||||
String timeStamp = servletRequest.getHeader("Wechatpay-Timestamp");
|
||||
String nonce = servletRequest.getHeader("Wechatpay-Nonce");
|
||||
String signature = servletRequest.getHeader("Wechatpay-Signature");
|
||||
@ -99,15 +100,15 @@ public class WxPayController extends BaseController {
|
||||
|
||||
try {
|
||||
Transaction transaction = notificationParser.parse(requestParam, Transaction.class);
|
||||
String orderNumber = transaction.getOutTradeNo();
|
||||
payOrderService.updateStatus(orderNumber, "已支付");
|
||||
if (wxPayService != null) {
|
||||
wxPayService.callback(transaction);
|
||||
}
|
||||
return success();
|
||||
} catch (ValidationException e) {
|
||||
return error();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
log.error("Error reading request body", e);
|
||||
throw new RuntimeException("Error reading request body", e);
|
||||
return error(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,7 @@
|
||||
package com.ruoyi.pay.wx.service;
|
||||
|
||||
import com.wechat.pay.java.service.wexinpayscoreparking.model.Transaction;
|
||||
|
||||
public interface IWxPayService {
|
||||
public void callback(Transaction transaction);
|
||||
}
|
Loading…
Reference in New Issue
Block a user