支付模块,调通对 ping++ 的调用,以实现模拟支付。
当然,整体代码还是有点乱,后面花点时间重构下~ 现在,缺一个异步 MQ 通知业务方订单支付成功
This commit is contained in:
@@ -31,7 +31,7 @@ public class PayDemoController {
|
||||
|
||||
// 调用【支付服务】,创建交易订单
|
||||
PayTransactionCreateDTO payTransactionCreateDTO = new PayTransactionCreateDTO()
|
||||
.setAppId("1024")
|
||||
.setAppId("POd4RC6a")
|
||||
.setCreateIp(HttpUtil.getIp(request))
|
||||
.setOrderId("1")
|
||||
.setOrderSubject("商品名" )
|
||||
@@ -43,4 +43,55 @@ public class PayDemoController {
|
||||
Assert.isTrue(result.isSuccess(), "一定会成功的");
|
||||
}
|
||||
|
||||
@PostMapping("/pingxx")
|
||||
public String pingxx() {
|
||||
return "{\n" +
|
||||
" \"id\": \"ch_n5COmHGG8iX5TWf5qDynvTaP\",\n" +
|
||||
" \"object\": \"charge\",\n" +
|
||||
" \"created\": 1552445643,\n" +
|
||||
" \"livemode\": false,\n" +
|
||||
" \"paid\": false,\n" +
|
||||
" \"refunded\": false,\n" +
|
||||
" \"reversed\": false,\n" +
|
||||
" \"app\": \"app_aTyfXDjrvzDSbLuz\",\n" +
|
||||
" \"channel\": \"wx_pub\",\n" +
|
||||
" \"order_no\": \"1552445643093\",\n" +
|
||||
" \"client_ip\": \"127.0.0.1\",\n" +
|
||||
" \"amount\": 1,\n" +
|
||||
" \"amount_settle\": 1,\n" +
|
||||
" \"currency\": \"cny\",\n" +
|
||||
" \"subject\": \"测试商品\",\n" +
|
||||
" \"body\": \"测试描述\",\n" +
|
||||
" \"time_paid\": null,\n" +
|
||||
" \"time_expire\": 1552452843,\n" +
|
||||
" \"time_settle\": null,\n" +
|
||||
" \"transaction_no\": null,\n" +
|
||||
" \"refunds\": {\n" +
|
||||
" \"object\": \"list\",\n" +
|
||||
" \"url\": \"/v1/charges/ch_n5COmHGG8iX5TWf5qDynvTaP/refunds\",\n" +
|
||||
" \"has_more\": false,\n" +
|
||||
" \"data\": []\n" +
|
||||
" },\n" +
|
||||
" \"amount_refunded\": 0,\n" +
|
||||
" \"failure_code\": null,\n" +
|
||||
" \"failure_msg\": null,\n" +
|
||||
" \"metadata\": {},\n" +
|
||||
" \"credential\": {\n" +
|
||||
" \"object\": \"credential\",\n" +
|
||||
" \"wx_pub\": {\n" +
|
||||
" \"appId\": \"wxytom5krtuf54qjff\",\n" +
|
||||
" \"timeStamp\": \"1552445643\",\n" +
|
||||
" \"nonceStr\": \"5cc0206f78d8bf931980f5132d5ce394\",\n" +
|
||||
" \"package\": \"prepay_id=1101000000190313rx9y5oahkkcsm5gg\",\n" +
|
||||
" \"signType\": \"MD5\",\n" +
|
||||
" \"paySign\": \"9F6E80E89439575B8414FA56ADB07228\"\n" +
|
||||
" }\n" +
|
||||
" },\n" +
|
||||
" \"extra\": {\n" +
|
||||
" \"open_id\": \"just_for_test\"\n" +
|
||||
" },\n" +
|
||||
" \"description\": null\n" +
|
||||
"}";
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,12 +1,22 @@
|
||||
package cn.iocoder.mall.pay.application.controller.users;
|
||||
|
||||
import cn.iocoder.common.framework.util.HttpUtil;
|
||||
import cn.iocoder.common.framework.vo.CommonResult;
|
||||
import cn.iocoder.mall.pay.api.PayTransactionService;
|
||||
import cn.iocoder.mall.pay.api.bo.PayTransactionSubmitBO;
|
||||
import cn.iocoder.mall.pay.api.constant.PayChannelEnum;
|
||||
import cn.iocoder.mall.pay.api.dto.PayTransactionSubmitDTO;
|
||||
import com.alibaba.dubbo.config.annotation.Reference;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("users/transaction") // TODO 芋艿,理论来说,是用户无关的。这里先酱紫先~
|
||||
public class PayTransactionController {
|
||||
@@ -15,8 +25,35 @@ public class PayTransactionController {
|
||||
private PayTransactionService payService;
|
||||
|
||||
@PostMapping("/submit") // TODO api 注释
|
||||
public CommonResult submit() { // TODO 1. params 2. result
|
||||
return null;
|
||||
// TODO result 后面改下
|
||||
public CommonResult<PayTransactionSubmitBO> submit(HttpServletRequest request,
|
||||
@RequestParam("appId") String appId,
|
||||
@RequestParam("orderId") String orderId,
|
||||
@RequestParam("payChannel") Integer payChannel) {
|
||||
PayTransactionSubmitDTO payTransactionSubmitDTO = new PayTransactionSubmitDTO()
|
||||
.setAppId(appId).setOrderId(orderId).setPayChannel(payChannel)
|
||||
.setCreateIp(HttpUtil.getIp(request));
|
||||
// 提交支付提交
|
||||
return payService.submitTransaction(payTransactionSubmitDTO);
|
||||
}
|
||||
|
||||
@PostMapping(value = "pingxx_pay_success", consumes = MediaType.APPLICATION_JSON_VALUE)
|
||||
// @GetMapping(value = "pingxx_pay_success")
|
||||
public String pingxxSuccess(HttpServletRequest request) throws IOException {
|
||||
// 读取 webhook
|
||||
StringBuilder sb = new StringBuilder();
|
||||
try (BufferedReader reader = request.getReader()) {
|
||||
String line;
|
||||
while ((line = reader.readLine()) != null) {
|
||||
sb.append(line);
|
||||
}
|
||||
}
|
||||
|
||||
// JSONObject bodyObj = JSON.parseObject(sb.toString());
|
||||
// bodyObj.put("webhookId", bodyObj.remove("id"));
|
||||
// String body = bodyObj.toString();
|
||||
payService.updateTransactionPaySuccess(PayChannelEnum.PINGXX.getId(), sb.toString());
|
||||
return "";
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
import com.alibaba.dubbo.config.ApplicationConfig;
|
||||
import com.alibaba.dubbo.config.ReferenceConfig;
|
||||
import com.alibaba.dubbo.config.RegistryConfig;
|
||||
import com.alibaba.dubbo.rpc.service.GenericService;
|
||||
|
||||
public class DubboGenericInvokerTest {
|
||||
|
||||
public static void main(String[] args) {
|
||||
ApplicationConfig application = new ApplicationConfig();
|
||||
application.setName("api-generic-consumer");
|
||||
|
||||
RegistryConfig registry = new RegistryConfig();
|
||||
registry.setAddress("zookeeper://127.0.0.1:2181");
|
||||
|
||||
application.setRegistry(registry);
|
||||
|
||||
ReferenceConfig<GenericService> reference = new ReferenceConfig<>();
|
||||
// 弱类型接口名
|
||||
reference.setInterface("cn.iocoder.mall.pay.api.PayDemoService");
|
||||
// 声明为泛化接口
|
||||
reference.setGeneric(true);
|
||||
|
||||
reference.setApplication(application);
|
||||
|
||||
// 用com.alibaba.dubbo.rpc.service.GenericService可以替代所有接口引用
|
||||
GenericService genericService = reference.get();
|
||||
|
||||
String name = (String) genericService.$invoke("updatePaySuccess", new String[]{String.class.getName()}, new Object[]{"1"});
|
||||
System.out.println(name);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user