微信官网
一.电商平台
流程
电商平台=>客户选择好商品=>提交订单=>电商平台保存订单信息到数据库=>电商平台发送订单相关信息到支付平台=>
支付平台获取订单信息=>支付平台保存订单信息=>支付平台根据订单信息判断是微信还是支付宝支付=>如果是微信=>
支付平台发送请求微信,一键下单=>支付平台等待回应=>支付平台接受到支付链接=>
支付平台将支付链接发送到电商平台前端=>前端生成支付二维码
1.1 客户端提交订单信息
@PostMapping("/sendRequestToZFZX")
public AjaxResult sendRequestToZFZX(@Validated @RequestBody ClientOrder clientOrder) {
clientOrder.setId(IdUtils.simpleUUID());
clientOrderService.addOrderInfo(clientOrder);
MerchantOrdersVO merchantOrdersVO = new MerchantOrdersVO();
merchantOrdersVO.setMerchantOrderId(clientOrder.getId());
merchantOrdersVO.setMerchantUserId(100);
merchantOrdersVO.setAmount(1);
merchantOrdersVO.setPayMethod(PayWay.WEIXIN.key);
merchantOrdersVO.setReturnUrl(payReturnUrl);
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
headers.add("userName", "admin");
headers.add("password", "admin123");
HttpEntity<MerchantOrdersVO> entity =
new HttpEntity<>(merchantOrdersVO, headers);
ResponseEntity<AjaxResult> responseEntity =
restTemplate.postForEntity(paymentUrl,
entity,
AjaxResult.class);
AjaxResult ajaxResult = responseEntity.getBody();
if (!ajaxResult.get("code").toString().equals("200")) {
logger.error("发送错误:{}", ajaxResult.get("msg"));
return AjaxResult.error("支付中心订单创建失败,请联系管理员!");
}
return AjaxResult.success();
}
二.支付中心
三.其他
3.1 ClientOrderServiceImpl实现类
package com.ruoyi.pay.service.impl;
import com.ruoyi.common.core.domain.entity.ClientOrder;
import com.ruoyi.pay.mapper.ClientOrderMapper;
import com.ruoyi.pay.service.ClientOrderService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
@Service
public class ClientOrderServiceImpl implements ClientOrderService {
@Resource
private ClientOrderMapper clientOrderMapper;
@Override
@Transactional
public void addOrderInfo(ClientOrder clientOrder) {
clientOrderMapper.addOrderInfo(clientOrder);
}
@Override
public void updateOrderStatus(String OrderId, Integer type) {
clientOrderMapper.updateOrderStatus(OrderId,type);
}
}
3.2 ClientOrder 客户端订单信息
package com.ruoyi.common.core.domain.entity;
import com.ruoyi.common.core.domain.BaseEntity;
import com.ruoyi.common.utils.uuid.IdUtils;
public class ClientOrder extends BaseEntity {
private String id;
private int userId;
private String status;
private Integer type;
private String way;
private Integer price;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public int getUserId() {
return userId;
}
public void setUserId(int userId) {
this.userId = userId;
}
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
public Integer getType() {
return type;
}
public void setType(Integer type) {
this.type = type;
}
public String getWay() {
return way;
}
public void setWay(String way) {
this.way = way;
}
public Integer getPrice() {
return price;
}
public void setPrice(Integer price) {
this.price = price;
}
}
3.3 MerchantOrdersVO 订单信息
package com.ruoyi.common.core.domain.vo;
public class MerchantOrdersVO {
private String merchantOrderId;
private int merchantUserId;
private Integer amount;
private Integer payMethod;
private String returnUrl;
public String getMerchantOrderId() {
return merchantOrderId;
}
public void setMerchantOrderId(String merchantOrderId) {
this.merchantOrderId = merchantOrderId;
}
public int getMerchantUserId() {
return merchantUserId;
}
public void setMerchantUserId(int merchantUserId) {
this.merchantUserId = merchantUserId;
}
public Integer getAmount() {
return amount;
}
public void setAmount(Integer amount) {
this.amount = amount;
}
public Integer getPayMethod() {
return payMethod;
}
public void setPayMethod(Integer payMethod) {
this.payMethod = payMethod;
}
public String getReturnUrl() {
return returnUrl;
}
public void setReturnUrl(String returnUrl) {
this.returnUrl = returnUrl;
}
}