添加pcpay 支付
This commit is contained in:
parent
668edeb23c
commit
2695748ab7
|
|
@ -1,5 +1,13 @@
|
|||
package com.chaozhanggui.system.cashierservice.controller;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.alipay.api.AlipayApiException;
|
||||
import com.alipay.api.AlipayClient;
|
||||
import com.alipay.api.DefaultAlipayClient;
|
||||
import com.alipay.api.request.AlipaySystemOauthTokenRequest;
|
||||
import com.alipay.api.request.AlipayUserInfoShareRequest;
|
||||
import com.alipay.api.response.AlipaySystemOauthTokenResponse;
|
||||
import com.alipay.api.response.AlipayUserInfoShareResponse;
|
||||
import com.chaozhanggui.system.cashierservice.annotation.LimitSubmit;
|
||||
import com.chaozhanggui.system.cashierservice.entity.TbOrderDetail;
|
||||
import com.chaozhanggui.system.cashierservice.entity.dto.ReturnGroupOrderDto;
|
||||
|
|
@ -10,14 +18,18 @@ import com.chaozhanggui.system.cashierservice.sign.CodeEnum;
|
|||
import com.chaozhanggui.system.cashierservice.sign.Result;
|
||||
import com.chaozhanggui.system.cashierservice.util.IpUtil;
|
||||
import com.chaozhanggui.system.cashierservice.util.RedisCst;
|
||||
import com.chaozhanggui.system.cashierservice.util.WechatUtil;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
@CrossOrigin(origins = "*")
|
||||
@RestController
|
||||
|
|
@ -278,4 +290,98 @@ public class PayController {
|
|||
){
|
||||
return payService.getOrderDiscount(staffId, orderId, token);
|
||||
}
|
||||
|
||||
|
||||
@RequestMapping("pcscanpay")
|
||||
@LimitSubmit(key = "pcscanpay:%s")
|
||||
public Result pcscanpay(HttpServletRequest request,@RequestBody PaymentReq paymentReq){
|
||||
try {
|
||||
return payService.pcscanpay(paymentReq.getOrderId(),IpUtil.getIpAddr(request),paymentReq.getUserId(),paymentReq.getPayType());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return Result.fail(CodeEnum.FAIL);
|
||||
}
|
||||
|
||||
|
||||
@RequestMapping("createOrder")
|
||||
public Result createOrder(HttpServletRequest request,@RequestBody PaymentReq paymentReq){
|
||||
try {
|
||||
return payService.createOrder(IpUtil.getIpAddr(request),paymentReq.getUserId(),paymentReq.getPayType(),paymentReq.getShopId(),paymentReq.getPayAmount());
|
||||
} catch (JsonProcessingException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return Result.fail(CodeEnum.FAIL);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@Value("${wx.ysk.appId}")
|
||||
private String appId;
|
||||
|
||||
@Value("${wx.ysk.secrete}")
|
||||
private String secrete;
|
||||
|
||||
|
||||
|
||||
@Value("${ali.appId}")
|
||||
private String aliAppId;
|
||||
|
||||
@Value("${ali.privateKey}")
|
||||
private String privateKey;
|
||||
|
||||
@Value("${ali.publicKey}")
|
||||
private String publicKey;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 获取支付宝或微信openId
|
||||
* @param code
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/openId")
|
||||
public Result getOpenId(
|
||||
@RequestParam String code,
|
||||
@RequestParam String payType
|
||||
) throws AlipayApiException {
|
||||
|
||||
if("WECHAT".equals(payType)){
|
||||
JSONObject SessionKeyOpenId = WechatUtil.getSessionKeyOrOpenId(code, appId, secrete);
|
||||
log.info("SessionKeyOpenId:{}",SessionKeyOpenId.toString());
|
||||
String openid = SessionKeyOpenId.getString("openid");
|
||||
if(Objects.isNull(openid)){
|
||||
return Result.fail("获取微信id失败");
|
||||
}
|
||||
|
||||
return Result.success(CodeEnum.SUCCESS,openid);
|
||||
}else if("ALIPAY".equals(payType)){
|
||||
|
||||
AlipayClient alipayClient = new DefaultAlipayClient("https://openapi.alipay.com/gateway.do",aliAppId,privateKey,"json","GBK",publicKey,"RSA2");
|
||||
AlipayUserInfoShareRequest request = new AlipayUserInfoShareRequest();
|
||||
AlipayUserInfoShareResponse response = alipayClient.execute(request,code);
|
||||
log.info("AlipayUserInfoShareResponse:{}",JSONObject.toJSONString(response));
|
||||
if(!response.isSuccess()){
|
||||
return Result.fail("获取支付宝userId失败");
|
||||
}
|
||||
|
||||
return Result.success(CodeEnum.SUCCESS,response.getUserId());
|
||||
}
|
||||
|
||||
return Result.fail(CodeEnum.FAIL);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,4 +15,6 @@ public class OrderVo {
|
|||
private String tableId;
|
||||
private Integer vipUserId;
|
||||
private Integer type;
|
||||
|
||||
private String sendType;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -86,13 +86,6 @@ public class LimitSubmitAspect {
|
|||
Object[] args= joinPoint.getArgs();
|
||||
String orderId=orderId(method,args);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
LimitSubmit limitSubmit = method.getAnnotation(LimitSubmit.class);
|
||||
String redisKey = limitSubmit.key();
|
||||
String key = getRedisKey1(joinPoint, redisKey,orderId);
|
||||
|
|
@ -205,6 +198,13 @@ public class LimitSubmitAspect {
|
|||
if(o instanceof List){
|
||||
orderId= ((List<TbOrderDetail>)o).get(0).getOrderId().toString();
|
||||
}
|
||||
}else if("pcscanpay".equals(method.getName())){
|
||||
Object o=args[1];
|
||||
|
||||
if(o instanceof PaymentReq){
|
||||
orderId=((PaymentReq)o).getOrderId();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return orderId;
|
||||
|
|
|
|||
|
|
@ -28,6 +28,9 @@ public class WebAppConfigurer implements WebMvcConfigurer {
|
|||
.excludePathPatterns("/order/sendMessage")
|
||||
.excludePathPatterns("/order/getOrderById")
|
||||
.excludePathPatterns("/data/handoverprint")
|
||||
.excludePathPatterns("/pay/pcscanpay")
|
||||
.excludePathPatterns("/pay/openId")
|
||||
.excludePathPatterns("/pay/createOrder")
|
||||
;
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -22,5 +22,12 @@ public class PaymentReq implements Serializable {
|
|||
|
||||
private String memberCode;
|
||||
|
||||
private String payType;
|
||||
|
||||
private String userId;
|
||||
|
||||
private String shopId;
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -717,15 +717,27 @@ public class OrderService {
|
|||
|
||||
for (TbCashierCart cashierCart : list) {
|
||||
|
||||
|
||||
TbOrderDetail orderDetail = new TbOrderDetail();
|
||||
TbProductWithBLOBs product=tbProductMapper.selectByPrimaryKey(Integer.valueOf(cashierCart.getProductId()));
|
||||
if("takeaway".equals(orderVo.getSendType())||"takeself".equals(orderVo.getSendType())){
|
||||
if(Objects.nonNull(product.getPackFee())){
|
||||
packAMount = packAMount.add(product.getPackFee());
|
||||
orderDetail.setPackAmount(product.getPackFee());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
TbProductSkuWithBLOBs tbProduct = tbProductSkuMapper.selectByPrimaryKey(Integer.valueOf(cashierCart.getSkuId()));
|
||||
totalAmount = totalAmount.add(cashierCart.getTotalAmount());
|
||||
packAMount = packAMount.add(cashierCart.getPackFee());
|
||||
|
||||
feeAmount = cashierCart.getPackFee();
|
||||
if (Objects.nonNull(tbProduct)) {
|
||||
saleAmount = saleAmount.add(tbProduct.getSalePrice());
|
||||
}
|
||||
skuMap.put(tbProduct.getId(), tbProduct);
|
||||
TbOrderDetail orderDetail = new TbOrderDetail();
|
||||
|
||||
orderDetail.setCreateTime(new Date());
|
||||
orderDetail.setNum(cashierCart.getNumber());
|
||||
orderDetail.setPrice(cashierCart.getSalePrice());
|
||||
|
|
@ -739,7 +751,6 @@ public class OrderService {
|
|||
orderDetail.setProductSkuName(tbProduct.getSpecSnap());
|
||||
orderDetail.setProductName(cashierCart.getName());
|
||||
orderDetail.setShopId(orderVo.getShopId());
|
||||
orderDetail.setPackAmount(cashierCart.getPackFee());
|
||||
orderDetail.setStatus("unpaid");
|
||||
orderDetail.setProductImg(cashierCart.getCoverImg());
|
||||
masterId = cashierCart.getMasterId();
|
||||
|
|
@ -774,10 +785,11 @@ public class OrderService {
|
|||
orderInfo.setTradeDay(DateUtils.getDay());
|
||||
orderInfo.setUserId(orderVo.getUserId());
|
||||
orderInfo.setUseType(StrUtil.isNotBlank(orderVo.getTableId()) ? "postPay" : "afterPay");
|
||||
orderInfo.setPackFee(packAMount);
|
||||
tbOrderInfoMapper.updateByPrimaryKeySelective(orderInfo);
|
||||
} else {
|
||||
orderInfo = new TbOrderInfo(orderNo, totalAmount, packAMount, totalAmount, saleAmount, totalAmount, feeAmount, "",
|
||||
"table", "cash", orderVo.getMerchantId().toString(), orderVo.getShopId().toString(),
|
||||
orderVo.getSendType(), "cash", orderVo.getMerchantId().toString(), orderVo.getShopId().toString(),
|
||||
"", (byte) 1, day, masterId);
|
||||
orderInfo.setMasterId(orderVo.getMasterId());
|
||||
orderInfo.setRemark(orderVo.getRemark());
|
||||
|
|
|
|||
|
|
@ -24,6 +24,8 @@ import com.chaozhanggui.system.cashierservice.sign.Result;
|
|||
import com.chaozhanggui.system.cashierservice.thirdpay.resp.*;
|
||||
import com.chaozhanggui.system.cashierservice.thirdpay.service.ThirdPayService;
|
||||
import com.chaozhanggui.system.cashierservice.util.*;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
|
@ -1738,6 +1740,284 @@ public class PayService {
|
|||
}
|
||||
|
||||
|
||||
public Result pcscanpay(String orderId,String ip,String userId,String payType) throws JsonProcessingException {
|
||||
if (ObjectUtil.isEmpty(orderId) || ObjectUtil.isEmpty(ip)) {
|
||||
return Result.fail(CodeEnum.PARAM);
|
||||
}
|
||||
|
||||
TbOrderInfo orderInfo = tbOrderInfoMapper.selectByPrimaryKey(Integer.valueOf(orderId));
|
||||
|
||||
if (ObjectUtil.isEmpty(orderInfo)) {
|
||||
return Result.fail(CodeEnum.ORDERNOEXIST);
|
||||
}
|
||||
|
||||
|
||||
if (!"unpaid".equals(orderInfo.getStatus()) && !"paying".equals(orderInfo.getStatus())) {
|
||||
return Result.fail(CodeEnum.ORDERSTATUSERROR);
|
||||
}
|
||||
|
||||
|
||||
|
||||
List<TbCashierCart> cashierCarts = tbCashierCartMapper.selectByOrderId(orderId, null);
|
||||
if (ObjectUtil.isEmpty(cashierCarts) || ObjectUtil.isNull(cashierCarts)) {
|
||||
return Result.fail(CodeEnum.CARTEXIST);
|
||||
}
|
||||
|
||||
StringBuffer body = new StringBuffer();
|
||||
for (TbCashierCart cashierCart : cashierCarts) {
|
||||
body.append(cashierCart.getName());
|
||||
}
|
||||
if (ObjectUtil.isNull(orderInfo.getMerchantId()) || ObjectUtil.isEmpty(orderInfo.getMerchantId())) {
|
||||
return Result.fail(CodeEnum.NOCUSTOMER);
|
||||
}
|
||||
|
||||
|
||||
TbMerchantThirdApply thirdApply = tbMerchantThirdApplyMapper.selectByPrimaryKey(Integer.valueOf(orderInfo.getMerchantId()));
|
||||
if (ObjectUtil.isEmpty(thirdApply) || ObjectUtil.isNull(thirdApply)) {
|
||||
return Result.fail(CodeEnum.NOCUSTOMER);
|
||||
}
|
||||
|
||||
|
||||
|
||||
TbOrderPayment payment = tbOrderPaymentMapper.selectByOrderId(orderId);
|
||||
if (ObjectUtil.isEmpty(payment) || payment == null) {
|
||||
payment = new TbOrderPayment();
|
||||
payment.setPayTypeId("ysk");
|
||||
payment.setAmount(orderInfo.getOrderAmount());
|
||||
payment.setPaidAmount(orderInfo.getPayAmount());
|
||||
payment.setHasRefundAmount(BigDecimal.ZERO);
|
||||
payment.setReceived(payment.getAmount());
|
||||
payment.setChangeFee(BigDecimal.ZERO);
|
||||
payment.setMemberId(orderInfo.getMemberId());
|
||||
payment.setShopId(orderInfo.getShopId());
|
||||
payment.setOrderId(orderInfo.getId().toString());
|
||||
payment.setCreatedAt(System.currentTimeMillis());
|
||||
payment.setAuthCode("");
|
||||
tbOrderPaymentMapper.insert(payment);
|
||||
} else {
|
||||
payment.setAuthCode("");
|
||||
payment.setUpdatedAt(System.currentTimeMillis());
|
||||
tbOrderPaymentMapper.updateByPrimaryKey(payment);
|
||||
}
|
||||
|
||||
|
||||
orderInfo.setPayAmount(orderInfo.getOrderAmount());
|
||||
orderInfo.setUpdatedAt(System.currentTimeMillis());
|
||||
tbOrderInfoMapper.updateByPrimaryKeySelective(orderInfo);
|
||||
|
||||
|
||||
String reqbody = "";
|
||||
|
||||
if (body.length() > 15) {
|
||||
reqbody = body.substring(0, 6).concat("....").concat(body.substring(body.length() - 6, body.length()));
|
||||
} else {
|
||||
reqbody = body.toString();
|
||||
}
|
||||
|
||||
PublicResp<JspayResp> publicResp = thirdPayService.jspay(url,thirdApply.getAppId(),thirdApply.getAppToken(),reqbody,reqbody,orderInfo.getOrderAmount().multiply(new BigDecimal(100)).longValue(),payType,"WECHAT".equals(payType)?thirdApply.getSmallAppid():null,userId,ip,DateUtils.getSsdfTimes(),thirdApply.getStoreId(),backUrl,backUrl);
|
||||
|
||||
|
||||
if (ObjectUtil.isNotNull(publicResp) && ObjectUtil.isNotEmpty(publicResp)) {
|
||||
if ("000000".equals(publicResp.getCode())) {
|
||||
JspayResp scanpayResp = publicResp.getObjData();
|
||||
if ("TRADE_SUCCESS".equals(scanpayResp.getState())) {
|
||||
|
||||
payment.setTradeNumber(scanpayResp.getPayOrderId());
|
||||
payment.setUpdatedAt(System.currentTimeMillis());
|
||||
tbOrderPaymentMapper.updateByPrimaryKeySelective(payment);
|
||||
|
||||
//处理支付成功的订单
|
||||
orderInfo.setStatus("closed");
|
||||
orderInfo.setPayOrderNo(scanpayResp.getPayOrderId());
|
||||
tbOrderInfoMapper.updateByPrimaryKeySelective(orderInfo);
|
||||
|
||||
//更新购物车状态
|
||||
int cartCount = tbCashierCartMapper.updateByOrderId(orderId, "final");
|
||||
log.info("更新购物车:{}", cartCount);
|
||||
|
||||
if(ObjectUtil.isNotNull(orderInfo.getDiscountRatio())&&ObjectUtil.isNotEmpty(orderInfo.getDiscountRatio())){
|
||||
tbOrderDetailMapper.updateStatusByOrderId(Integer.valueOf(orderId), "closed",orderInfo.getDiscountRatio());
|
||||
}else {
|
||||
tbOrderDetailMapper.updateStatusByOrderId(Integer.valueOf(orderId), "closed",null);
|
||||
}
|
||||
|
||||
// JSONObject jsonObject = new JSONObject();
|
||||
// jsonObject.put("token", token);
|
||||
// jsonObject.put("type", "create");
|
||||
// jsonObject.put("orderId", orderId);
|
||||
//
|
||||
// producer.putOrderCollect(jsonObject.toJSONString());
|
||||
//
|
||||
// producer.printMechine(orderId);
|
||||
|
||||
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
return Result.success(CodeEnum.SUCCESS, mapper.readTree(scanpayResp.getPayInfo()));
|
||||
|
||||
}else if("TRADE_AWAIT".equals(scanpayResp.getState())){
|
||||
orderInfo.setStatus("paying");
|
||||
orderInfo.setPayOrderNo(payment.getTradeNumber());
|
||||
tbOrderInfoMapper.updateByPrimaryKeySelective(orderInfo);
|
||||
|
||||
payment.setTradeNumber(scanpayResp.getPayOrderId());
|
||||
payment.setUpdatedAt(System.currentTimeMillis());
|
||||
tbOrderPaymentMapper.updateByPrimaryKeySelective(payment);
|
||||
|
||||
|
||||
if("WECHAT".equals(scanpayResp.getPayType())){
|
||||
orderInfo.setPayType("WECHAT");
|
||||
}else if("ALIPAY".equals(scanpayResp.getPayType())){
|
||||
orderInfo.setPayType("ALIPAY");
|
||||
}else if("UNIONPAY".equals(scanpayResp.getPayType())){
|
||||
orderInfo.setPayType("UNIONPAY");
|
||||
}
|
||||
|
||||
|
||||
tbOrderInfoMapper.updateByPrimaryKey(orderInfo);
|
||||
|
||||
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
return Result.success(CodeEnum.PAYING,mapper.readTree(scanpayResp.getPayInfo()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return Result.fail(CodeEnum.FAIL);
|
||||
|
||||
}
|
||||
|
||||
|
||||
public String generateOrderNumber() {
|
||||
String date = DateUtils.getSdfTimes();
|
||||
Random random = new Random();
|
||||
int randomNum = random.nextInt(900) + 100;
|
||||
return "QR" + date + randomNum;
|
||||
}
|
||||
|
||||
|
||||
public Result createOrder(String ip,String userId,String payType,String shopId,BigDecimal amount) throws JsonProcessingException {
|
||||
|
||||
TbShopInfo shopInfo= tbShopInfoMapper.selectByPrimaryKey(Integer.valueOf(shopId));
|
||||
|
||||
if(ObjectUtil.isNull(shopInfo)){
|
||||
return Result.fail(CodeEnum.SHOPINFONOEXIST);
|
||||
}
|
||||
|
||||
|
||||
|
||||
TbOrderInfo orderInfo=new TbOrderInfo();
|
||||
|
||||
String orderNo = generateOrderNumber();
|
||||
orderInfo.setOrderNo(orderNo);
|
||||
orderInfo.setSettlementAmount(amount);
|
||||
orderInfo.setPackFee(BigDecimal.ZERO);
|
||||
orderInfo.setOriginAmount(amount);
|
||||
orderInfo.setPayAmount(amount);
|
||||
orderInfo.setAmount(amount);
|
||||
orderInfo.setRefundAmount(BigDecimal.ZERO);
|
||||
orderInfo.setPayType(payType);
|
||||
orderInfo.setPayAmount(amount);
|
||||
orderInfo.setOrderAmount(amount);
|
||||
orderInfo.setSendType("QR");
|
||||
orderInfo.setStatus("WAIT_PAY");
|
||||
orderInfo.setMerchantId(shopInfo.getMerchantId());
|
||||
orderInfo.setShopId(shopId);
|
||||
orderInfo.setRefundAble(Byte.valueOf("1"));
|
||||
orderInfo.setSystemTime(System.currentTimeMillis());
|
||||
orderInfo.setCreatedAt(System.currentTimeMillis());
|
||||
orderInfo.setIsAccepted(Byte.valueOf("1"));
|
||||
orderInfo.setTradeDay(DateUtils.getDay());
|
||||
|
||||
tbOrderInfoMapper.insert(orderInfo);
|
||||
|
||||
|
||||
TbOrderPayment payment = tbOrderPaymentMapper.selectByOrderId(orderInfo.getId().toString());
|
||||
if (ObjectUtil.isEmpty(payment) || payment == null) {
|
||||
payment = new TbOrderPayment();
|
||||
payment.setPayTypeId("ysk");
|
||||
payment.setAmount(orderInfo.getOrderAmount());
|
||||
payment.setPaidAmount(orderInfo.getPayAmount());
|
||||
payment.setHasRefundAmount(BigDecimal.ZERO);
|
||||
payment.setReceived(payment.getAmount());
|
||||
payment.setChangeFee(BigDecimal.ZERO);
|
||||
payment.setMemberId(orderInfo.getMemberId());
|
||||
payment.setShopId(orderInfo.getShopId());
|
||||
payment.setOrderId(orderInfo.getId().toString());
|
||||
payment.setCreatedAt(System.currentTimeMillis());
|
||||
payment.setAuthCode("");
|
||||
tbOrderPaymentMapper.insert(payment);
|
||||
} else {
|
||||
payment.setAuthCode("");
|
||||
payment.setUpdatedAt(System.currentTimeMillis());
|
||||
tbOrderPaymentMapper.updateByPrimaryKey(payment);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
TbMerchantThirdApply thirdApply = tbMerchantThirdApplyMapper.selectByPrimaryKey(Integer.valueOf(orderInfo.getMerchantId()));
|
||||
if (ObjectUtil.isEmpty(thirdApply) || ObjectUtil.isNull(thirdApply)) {
|
||||
return Result.fail(CodeEnum.NOCUSTOMER);
|
||||
}
|
||||
|
||||
String reqbody = "店铺收款码";
|
||||
|
||||
|
||||
PublicResp<JspayResp> publicResp = thirdPayService.jspay(url,thirdApply.getAppId(),thirdApply.getAppToken(),reqbody,reqbody,orderInfo.getOrderAmount().multiply(new BigDecimal(100)).longValue(),payType,"WECHAT".equals(payType)?thirdApply.getSmallAppid():null,userId,ip,DateUtils.getSsdfTimes(),thirdApply.getStoreId(),backUrl,backUrl);
|
||||
|
||||
|
||||
if (ObjectUtil.isNotNull(publicResp) && ObjectUtil.isNotEmpty(publicResp)) {
|
||||
if ("000000".equals(publicResp.getCode())) {
|
||||
JspayResp scanpayResp = publicResp.getObjData();
|
||||
if ("TRADE_SUCCESS".equals(scanpayResp.getState())) {
|
||||
|
||||
payment.setTradeNumber(scanpayResp.getPayOrderId());
|
||||
payment.setUpdatedAt(System.currentTimeMillis());
|
||||
tbOrderPaymentMapper.updateByPrimaryKeySelective(payment);
|
||||
|
||||
//处理支付成功的订单
|
||||
orderInfo.setStatus("closed");
|
||||
orderInfo.setPayOrderNo(scanpayResp.getPayOrderId());
|
||||
tbOrderInfoMapper.updateByPrimaryKeySelective(orderInfo);
|
||||
|
||||
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
return Result.success(CodeEnum.SUCCESS, mapper.readTree(scanpayResp.getPayInfo()));
|
||||
|
||||
} else if ("TRADE_AWAIT".equals(scanpayResp.getState())) {
|
||||
orderInfo.setStatus("paying");
|
||||
orderInfo.setPayOrderNo(payment.getTradeNumber());
|
||||
tbOrderInfoMapper.updateByPrimaryKeySelective(orderInfo);
|
||||
|
||||
payment.setTradeNumber(scanpayResp.getPayOrderId());
|
||||
payment.setUpdatedAt(System.currentTimeMillis());
|
||||
tbOrderPaymentMapper.updateByPrimaryKeySelective(payment);
|
||||
|
||||
|
||||
if ("WECHAT".equals(scanpayResp.getPayType())) {
|
||||
orderInfo.setPayType("WECHAT");
|
||||
} else if ("ALIPAY".equals(scanpayResp.getPayType())) {
|
||||
orderInfo.setPayType("ALIPAY");
|
||||
} else if ("UNIONPAY".equals(scanpayResp.getPayType())) {
|
||||
orderInfo.setPayType("UNIONPAY");
|
||||
}
|
||||
|
||||
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
return Result.success(CodeEnum.PAYING, mapper.readTree(scanpayResp.getPayInfo()));
|
||||
}
|
||||
}
|
||||
}
|
||||
return Result.fail(CodeEnum.FAIL);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println(MD5Util.encrypt("123456".concat("13718478323").concat("10")));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,48 @@
|
|||
package com.chaozhanggui.system.cashierservice.thirdpay.req;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
@Data
|
||||
public class ApppayReq implements Serializable {
|
||||
|
||||
|
||||
private String subject;
|
||||
|
||||
private String body;
|
||||
|
||||
private Long amount;
|
||||
|
||||
private String currency="cny";
|
||||
|
||||
/**
|
||||
* 微信 WECHAT;
|
||||
* 支付宝 ALIPAY
|
||||
*/
|
||||
private String payType;
|
||||
|
||||
private String clientIp;
|
||||
|
||||
private String mchOrderNo;
|
||||
|
||||
private String storeId;
|
||||
|
||||
private String notifyUrl;
|
||||
|
||||
private String returnUrl;
|
||||
|
||||
|
||||
public ApppayReq(String subject, String body, Long amount, String currency, String payType, String clientIp, String mchOrderNo, String storeId, String notifyUrl, String returnUrl) {
|
||||
this.subject = subject;
|
||||
this.body = body;
|
||||
this.amount = amount;
|
||||
this.currency = currency;
|
||||
this.payType = payType;
|
||||
this.clientIp = clientIp;
|
||||
this.mchOrderNo = mchOrderNo;
|
||||
this.storeId = storeId;
|
||||
this.notifyUrl = notifyUrl;
|
||||
this.returnUrl = returnUrl;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,47 @@
|
|||
package com.chaozhanggui.system.cashierservice.thirdpay.req;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
@Data
|
||||
public class H5payReq implements Serializable {
|
||||
|
||||
private String subject;
|
||||
|
||||
private String body;
|
||||
|
||||
private Long amount;
|
||||
|
||||
private String currency="cny";
|
||||
|
||||
/**
|
||||
* 微信 WECHAT;
|
||||
* 支付宝 ALIPAY
|
||||
*/
|
||||
private String payType;
|
||||
|
||||
private String clientIp;
|
||||
|
||||
private String mchOrderNo;
|
||||
|
||||
private String storeId;
|
||||
|
||||
private String notifyUrl;
|
||||
|
||||
private String returnUrl;
|
||||
|
||||
|
||||
public H5payReq(String subject, String body, Long amount, String currency, String payType, String clientIp, String mchOrderNo, String storeId, String notifyUrl, String returnUrl) {
|
||||
this.subject = subject;
|
||||
this.body = body;
|
||||
this.amount = amount;
|
||||
this.currency = currency;
|
||||
this.payType = payType;
|
||||
this.clientIp = clientIp;
|
||||
this.mchOrderNo = mchOrderNo;
|
||||
this.storeId = storeId;
|
||||
this.notifyUrl = notifyUrl;
|
||||
this.returnUrl = returnUrl;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,53 @@
|
|||
package com.chaozhanggui.system.cashierservice.thirdpay.req;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
@Data
|
||||
public class JspayReq implements Serializable {
|
||||
|
||||
private String subject;
|
||||
|
||||
private String body;
|
||||
|
||||
private Long amount;
|
||||
|
||||
private String currency="cny";
|
||||
|
||||
/**
|
||||
* 微信 WECHAT;
|
||||
* 支付宝 ALIPAY
|
||||
*/
|
||||
private String payType;
|
||||
|
||||
|
||||
private String subAppid;
|
||||
|
||||
private String userId;
|
||||
|
||||
private String clientIp;
|
||||
|
||||
private String mchOrderNo;
|
||||
|
||||
private String storeId;
|
||||
|
||||
private String notifyUrl;
|
||||
|
||||
private String returnUrl;
|
||||
|
||||
public JspayReq(String subject, String body, Long amount, String currency, String payType, String subAppid, String userId, String clientIp, String mchOrderNo, String storeId, String notifyUrl, String returnUrl) {
|
||||
this.subject = subject;
|
||||
this.body = body;
|
||||
this.amount = amount;
|
||||
this.currency = currency;
|
||||
this.payType = payType;
|
||||
this.subAppid = subAppid;
|
||||
this.userId = userId;
|
||||
this.clientIp = clientIp;
|
||||
this.mchOrderNo = mchOrderNo;
|
||||
this.storeId = storeId;
|
||||
this.notifyUrl = notifyUrl;
|
||||
this.returnUrl = returnUrl;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,35 @@
|
|||
package com.chaozhanggui.system.cashierservice.thirdpay.req;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
@Data
|
||||
public class ScanpayReq implements Serializable {
|
||||
|
||||
private String subject;
|
||||
|
||||
private String body;
|
||||
|
||||
private Long amount;
|
||||
|
||||
private String currency="cny";
|
||||
|
||||
private String clientIp;
|
||||
|
||||
private String mchOrderNo;
|
||||
|
||||
private String storeId;
|
||||
|
||||
|
||||
|
||||
public ScanpayReq(String subject, String body, Long amount, String currency, String clientIp, String mchOrderNo, String storeId) {
|
||||
this.subject = subject;
|
||||
this.body = body;
|
||||
this.amount = amount;
|
||||
this.currency = currency;
|
||||
this.clientIp = clientIp;
|
||||
this.mchOrderNo = mchOrderNo;
|
||||
this.storeId = storeId;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,51 @@
|
|||
package com.chaozhanggui.system.cashierservice.thirdpay.resp;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
@Data
|
||||
public class ApppayResp implements Serializable {
|
||||
|
||||
private Long amount;
|
||||
|
||||
private String mchOrderNo;
|
||||
|
||||
private String payOrderId;
|
||||
|
||||
private String mercNo;
|
||||
|
||||
private String channelSendNo;
|
||||
|
||||
private String channelTradeNo;
|
||||
|
||||
private String state;
|
||||
|
||||
private String payType;
|
||||
|
||||
private String ifCode;
|
||||
|
||||
private String extParam;
|
||||
|
||||
private String payInfo;
|
||||
|
||||
private String liteInfo;
|
||||
|
||||
private String note;
|
||||
|
||||
private String tradeFee;
|
||||
|
||||
private String storeId;
|
||||
|
||||
private String subject;
|
||||
|
||||
private String drType;
|
||||
|
||||
private String refundAmt;
|
||||
|
||||
private String refundState;
|
||||
|
||||
private String cashFee;
|
||||
|
||||
private String settlementType;
|
||||
}
|
||||
|
|
@ -0,0 +1,50 @@
|
|||
package com.chaozhanggui.system.cashierservice.thirdpay.resp;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
@Data
|
||||
public class H5payResp implements Serializable {
|
||||
|
||||
|
||||
private Long amount;
|
||||
|
||||
private String mchOrderNo;
|
||||
|
||||
private String payOrderId;
|
||||
|
||||
private String mercNo;
|
||||
|
||||
private String channelSendNo;
|
||||
|
||||
private String channelTradeNo;
|
||||
|
||||
private String state;
|
||||
|
||||
private String payType;
|
||||
|
||||
private String ifCode;
|
||||
|
||||
private String extParam;
|
||||
|
||||
private String payInfo;
|
||||
|
||||
private String note;
|
||||
|
||||
private String tradeFee;
|
||||
|
||||
private String storeId;
|
||||
|
||||
private String subject;
|
||||
|
||||
private String drType;
|
||||
|
||||
private String refundAmt;
|
||||
|
||||
private String refundState;
|
||||
|
||||
private String cashFee;
|
||||
|
||||
private String settlementType;
|
||||
}
|
||||
|
|
@ -0,0 +1,50 @@
|
|||
package com.chaozhanggui.system.cashierservice.thirdpay.resp;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
@Data
|
||||
public class JspayResp implements Serializable {
|
||||
|
||||
|
||||
private Long amount;
|
||||
|
||||
private String mchOrderNo;
|
||||
|
||||
private String payOrderId;
|
||||
|
||||
private String mercNo;
|
||||
|
||||
private String channelSendNo;
|
||||
|
||||
private String channelTradeNo;
|
||||
|
||||
private String state;
|
||||
|
||||
private String payType;
|
||||
|
||||
private String ifCode;
|
||||
|
||||
private String extParam;
|
||||
|
||||
private String payInfo;
|
||||
|
||||
private String note;
|
||||
|
||||
private String tradeFee;
|
||||
|
||||
private String storeId;
|
||||
|
||||
private String subject;
|
||||
|
||||
private String drType;
|
||||
|
||||
private String refundAmt;
|
||||
|
||||
private String refundState;
|
||||
|
||||
private String cashFee;
|
||||
|
||||
private String settlementType;
|
||||
}
|
||||
|
|
@ -0,0 +1,49 @@
|
|||
package com.chaozhanggui.system.cashierservice.thirdpay.resp;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
@Data
|
||||
public class ScanpayResp implements Serializable {
|
||||
|
||||
private Long amount;
|
||||
|
||||
private String mchOrderNo;
|
||||
|
||||
private String payOrderId;
|
||||
|
||||
private String mercNo;
|
||||
|
||||
private String channelSendNo;
|
||||
|
||||
private String channelTradeNo;
|
||||
|
||||
private String state;
|
||||
|
||||
private String payType;
|
||||
|
||||
private String ifCode;
|
||||
|
||||
private String extParam;
|
||||
|
||||
private String payInfo;
|
||||
|
||||
private String note;
|
||||
|
||||
private String tradeFee;
|
||||
|
||||
private String storeId;
|
||||
|
||||
private String subject;
|
||||
|
||||
private String drType;
|
||||
|
||||
private String refundAmt;
|
||||
|
||||
private String refundState;
|
||||
|
||||
private String cashFee;
|
||||
|
||||
private String settlementType;
|
||||
}
|
||||
|
|
@ -29,6 +29,13 @@ public class ThirdPayService {
|
|||
|
||||
private static String refund="/api/open/order/refund";
|
||||
|
||||
private static String scanpay="/api/open/payment/scanpay";
|
||||
|
||||
private static String h5pay="/api/open/payment/h5pay";
|
||||
|
||||
private static String jspay="/api/open/payment/jspay";
|
||||
|
||||
private static String apppay="/api/open/payment/apppay";
|
||||
/**
|
||||
* 被扫接口
|
||||
* @param url
|
||||
|
|
@ -47,14 +54,14 @@ public class ThirdPayService {
|
|||
public PublicResp<MainScanResp> mainScan(String url,String appId, String subject, String body, Long amount, String subAppId, String authCode, String orderNo, String storeId, String notifyUrl,
|
||||
String key
|
||||
) {
|
||||
MainScanReq mainScanReq=null;
|
||||
if("66bab943ae82f63b50ae3cff".equals(appId)){
|
||||
|
||||
mainScanReq = new MainScanReq(subject, body, amount, subAppId, "cny", authCode, orderNo, storeId, notifyUrl,1,"TA1824003985261588482",null);
|
||||
url="https://paymentweb.sxczgkj.cn";
|
||||
}else {
|
||||
mainScanReq = new MainScanReq(subject, body, amount, subAppId, "cny", authCode, orderNo, storeId, notifyUrl,0,null,null);
|
||||
}
|
||||
MainScanReq mainScanReq= new MainScanReq(subject, body, amount, subAppId, "cny", authCode, orderNo, storeId, notifyUrl,0,null,null);;
|
||||
// if("66bab943ae82f63b50ae3cff".equals(appId)){
|
||||
//
|
||||
// mainScanReq = new MainScanReq(subject, body, amount, subAppId, "cny", authCode, orderNo, storeId, notifyUrl,1,"TA1824003985261588482",null);
|
||||
// url="https://paymentweb.sxczgkj.cn";
|
||||
// }else {
|
||||
// mainScanReq = new MainScanReq(subject, body, amount, subAppId, "cny", authCode, orderNo, storeId, notifyUrl,0,null,null);
|
||||
// }
|
||||
|
||||
|
||||
|
||||
|
|
@ -108,13 +115,13 @@ public class ThirdPayService {
|
|||
|
||||
String clinetIp,String orderNo, String storeId, String notifyUrl,String returnUrl,
|
||||
String key){
|
||||
WxScanPayReq scanPayReq=null;
|
||||
if("66bab943ae82f63b50ae3cff".equals(appId)){
|
||||
scanPayReq=new WxScanPayReq(subject,body,amount,"cny",payType,subAppId,userId,clinetIp,orderNo,storeId,1,null,"TA1824003985261588482",notifyUrl,returnUrl);
|
||||
url="https://paymentweb.sxczgkj.cn";
|
||||
}else {
|
||||
scanPayReq=new WxScanPayReq(subject,body,amount,"cny",payType,subAppId,userId,clinetIp,orderNo,storeId,0,null,null,notifyUrl,returnUrl);
|
||||
}
|
||||
WxScanPayReq scanPayReq=new WxScanPayReq(subject,body,amount,"cny",payType,subAppId,userId,clinetIp,orderNo,storeId,0,null,null,notifyUrl,returnUrl);
|
||||
// if("66bab943ae82f63b50ae3cff".equals(appId)){
|
||||
// scanPayReq=new WxScanPayReq(subject,body,amount,"cny",payType,subAppId,userId,clinetIp,orderNo,storeId,1,null,"TA1824003985261588482",notifyUrl,returnUrl);
|
||||
// url="https://paymentweb.sxczgkj.cn";
|
||||
// }else {
|
||||
// scanPayReq=new WxScanPayReq(subject,body,amount,"cny",payType,subAppId,userId,clinetIp,orderNo,storeId,0,null,null,notifyUrl,returnUrl);
|
||||
// }
|
||||
|
||||
PublicParam param=new PublicParam(appId,null,SignTypeEnum.MD5.getValue(),null,DateUtils.getSdfTimes(), "1.0", String.valueOf(System.currentTimeMillis()));
|
||||
|
||||
|
|
@ -247,6 +254,177 @@ public class ThirdPayService {
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* Pc 扫码支付
|
||||
* @param url
|
||||
* @param appId
|
||||
* @param key
|
||||
* @param subject
|
||||
* @param body
|
||||
* @param amount
|
||||
* @param clientIp
|
||||
* @param mchOrderNo
|
||||
* @param storeId
|
||||
* @param notifyUrl
|
||||
* @param returnUrl
|
||||
* @return
|
||||
*/
|
||||
public PublicResp<ScanpayResp> pcscanpay(String url,String appId,String key,String subject, String body, Long amount, String clientIp, String mchOrderNo, String storeId, String notifyUrl, String returnUrl ){
|
||||
ScanpayReq scanpayReq=new ScanpayReq(subject, body, amount, "cny", clientIp, mchOrderNo, storeId);
|
||||
PublicParam param=new PublicParam(appId,null,SignTypeEnum.MD5.getValue(), null,DateUtils.getSdfTimes(),"1.0",String.valueOf(System.currentTimeMillis()));
|
||||
try {
|
||||
String str=JSONUtil.toJSONString(sortFields(scanpayReq));
|
||||
param.setBizData(str);
|
||||
String tt = sortFieldsAndPrint(param);
|
||||
String MD5 = tt.concat("appSecret=" + key);
|
||||
log.info("加签原传:{}", MD5);
|
||||
String sign = MD5Util.encrypt(MD5);
|
||||
param.setSign(sign);
|
||||
String reqbody = JSONUtil.toJSONString(param);
|
||||
log.info("请求参数:{}", reqbody);
|
||||
String response = HttpRequest.post(url.concat(scanpay)).body(reqbody).execute().body();
|
||||
log.info("返回结果:{}", response);
|
||||
PublicResp<ScanpayResp> resp =JSONUtil.parseJSONStr2T(response,PublicResp.class);
|
||||
resp.setObjData(JSONUtil.parseJSONStr2T(resp.getBizData(),ScanpayResp.class));
|
||||
return resp;
|
||||
} catch (IllegalAccessException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 手机网页支付
|
||||
* @param url
|
||||
* @param appId
|
||||
* @param key
|
||||
* @param subject
|
||||
* @param body
|
||||
* @param amount
|
||||
* @param payType
|
||||
* @param clientIp
|
||||
* @param mchOrderNo
|
||||
* @param storeId
|
||||
* @param notifyUrl
|
||||
* @param returnUrl
|
||||
* @return
|
||||
*/
|
||||
public PublicResp<H5payResp> h5Pay(String url,String appId,String key,String subject, String body, Long amount, String payType, String clientIp, String mchOrderNo, String storeId, String notifyUrl, String returnUrl){
|
||||
H5payReq h5payReq=new H5payReq(subject, body, amount, "cny", payType, clientIp, mchOrderNo, storeId, notifyUrl, returnUrl);
|
||||
|
||||
PublicParam param=new PublicParam(appId,null,SignTypeEnum.MD5.getValue(), null,DateUtils.getSdfTimes(),"1.0",String.valueOf(System.currentTimeMillis()));
|
||||
try {
|
||||
String str=JSONUtil.toJSONString(sortFields(h5payReq));
|
||||
param.setBizData(str);
|
||||
String tt = sortFieldsAndPrint(param);
|
||||
String MD5 = tt.concat("appSecret=" + key);
|
||||
log.info("加签原传:{}", MD5);
|
||||
String sign = MD5Util.encrypt(MD5);
|
||||
param.setSign(sign);
|
||||
String reqbody = JSONUtil.toJSONString(param);
|
||||
log.info("请求参数:{}", reqbody);
|
||||
String response = HttpRequest.post(url.concat(h5pay)).body(reqbody).execute().body();
|
||||
log.info("返回结果:{}", response);
|
||||
PublicResp<H5payResp> resp =JSONUtil.parseJSONStr2T(response,PublicResp.class);
|
||||
resp.setObjData(JSONUtil.parseJSONStr2T(resp.getBizData(),H5payResp.class));
|
||||
return resp;
|
||||
} catch (IllegalAccessException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 公众号/生活号/银联js支付
|
||||
* @param url
|
||||
* @param appId
|
||||
* @param key
|
||||
* @param subject
|
||||
* @param body
|
||||
* @param amount
|
||||
* @param payType
|
||||
* @param subAppid
|
||||
* @param userId
|
||||
* @param clientIp
|
||||
* @param mchOrderNo
|
||||
* @param storeId
|
||||
* @param notifyUrl
|
||||
* @param returnUrl
|
||||
* @return
|
||||
*/
|
||||
public PublicResp<JspayResp> jspay(String url,String appId,String key,String subject, String body, Long amount, String payType, String subAppid, String userId, String clientIp, String mchOrderNo, String storeId, String notifyUrl, String returnUrl){
|
||||
JspayReq jspayReq=new JspayReq(subject, body, amount, "cny", payType, subAppid, userId, clientIp, mchOrderNo, storeId, notifyUrl, returnUrl);
|
||||
|
||||
PublicParam param=new PublicParam(appId,null,SignTypeEnum.MD5.getValue(), null,DateUtils.getSdfTimes(),"1.0",String.valueOf(System.currentTimeMillis()));
|
||||
try {
|
||||
String str=JSONUtil.toJSONString(sortFields(jspayReq));
|
||||
param.setBizData(str);
|
||||
String tt = sortFieldsAndPrint(param);
|
||||
String MD5 = tt.concat("appSecret=" + key);
|
||||
log.info("加签原传:{}", MD5);
|
||||
String sign = MD5Util.encrypt(MD5);
|
||||
param.setSign(sign);
|
||||
String reqbody = JSONUtil.toJSONString(param);
|
||||
log.info("请求参数:{}", reqbody);
|
||||
String response = HttpRequest.post(url.concat(jspay)).body(reqbody).execute().body();
|
||||
log.info("返回结果:{}", response);
|
||||
PublicResp<JspayResp> resp =JSONUtil.parseJSONStr2T(response,PublicResp.class);
|
||||
resp.setObjData(JSONUtil.parseJSONStr2T(resp.getBizData(),JspayResp.class));
|
||||
return resp;
|
||||
} catch (IllegalAccessException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/***
|
||||
* app 支付
|
||||
* @param url
|
||||
* @param appId
|
||||
* @param key
|
||||
* @param subject
|
||||
* @param body
|
||||
* @param amount
|
||||
* @param payType
|
||||
* @param clientIp
|
||||
* @param mchOrderNo
|
||||
* @param storeId
|
||||
* @param notifyUrl
|
||||
* @param returnUrl
|
||||
* @return
|
||||
*/
|
||||
|
||||
public PublicResp<ApppayResp> apppay(String url,String appId,String key,String subject, String body, Long amount, String payType, String clientIp, String mchOrderNo, String storeId, String notifyUrl, String returnUrl){
|
||||
ApppayReq apppayReq=new ApppayReq(subject, body, amount, "cny", payType, clientIp, mchOrderNo, storeId, notifyUrl, returnUrl);
|
||||
|
||||
|
||||
PublicParam param=new PublicParam(appId,null,SignTypeEnum.MD5.getValue(), null,DateUtils.getSdfTimes(),"1.0",String.valueOf(System.currentTimeMillis()));
|
||||
try {
|
||||
String str=JSONUtil.toJSONString(sortFields(apppayReq));
|
||||
param.setBizData(str);
|
||||
String tt = sortFieldsAndPrint(param);
|
||||
String MD5 = tt.concat("appSecret=" + key);
|
||||
log.info("加签原传:{}", MD5);
|
||||
String sign = MD5Util.encrypt(MD5);
|
||||
param.setSign(sign);
|
||||
String reqbody = JSONUtil.toJSONString(param);
|
||||
log.info("请求参数:{}", reqbody);
|
||||
String response = HttpRequest.post(url.concat(apppay)).body(reqbody).execute().body();
|
||||
log.info("返回结果:{}", response);
|
||||
PublicResp<ApppayResp> resp =JSONUtil.parseJSONStr2T(response,PublicResp.class);
|
||||
resp.setObjData(JSONUtil.parseJSONStr2T(resp.getBizData(),ApppayResp.class));
|
||||
return resp;
|
||||
} catch (IllegalAccessException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -101,4 +101,22 @@ public class WechatUtil {
|
|||
|
||||
throw new RuntimeException(linkedHashMap.getOrDefault(resObj.get("errcode") + "", "未知错误"));
|
||||
}
|
||||
|
||||
|
||||
public static JSONObject getSessionKeyOrOpenId(String code, String appId, String secrete) {
|
||||
String requestUrl = "https://api.weixin.qq.com/sns/jscode2session";
|
||||
Map<String, String> requestUrlParam = new HashMap<>();
|
||||
// https://mp.weixin.qq.com/wxopen/devprofile?action=get_profile&token=164113089&lang=zh_CN
|
||||
//小程序appId
|
||||
requestUrlParam.put("appid", appId);
|
||||
//小程序secret
|
||||
requestUrlParam.put("secret", secrete);
|
||||
//小程序端返回的code
|
||||
requestUrlParam.put("js_code", code);
|
||||
//默认参数
|
||||
requestUrlParam.put("grant_type", "authorization_code");
|
||||
//发送post请求读取调用微信接口获取openid用户唯一标识
|
||||
JSONObject jsonObject = JSON.parseObject(HttpClientUtil.doPost(requestUrl,requestUrlParam));
|
||||
return jsonObject;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue