微信小程序点歌接口
This commit is contained in:
@@ -0,0 +1,117 @@
|
||||
package com.chaozhanggui.system.cashierservice.util;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.chaozhanggui.system.cashierservice.dao.TbMemberInMapper;
|
||||
import com.chaozhanggui.system.cashierservice.entity.Enum.PayTypeConstant;
|
||||
import com.chaozhanggui.system.cashierservice.entity.TbMemberIn;
|
||||
import com.chaozhanggui.system.cashierservice.entity.TbMerchantThirdApply;
|
||||
import com.chaozhanggui.system.cashierservice.exception.MsgException;
|
||||
import com.chaozhanggui.system.cashierservice.thirdpay.resp.PublicResp;
|
||||
import com.chaozhanggui.system.cashierservice.thirdpay.resp.WxScanPayResp;
|
||||
import com.chaozhanggui.system.cashierservice.thirdpay.service.ThirdPayService;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Date;
|
||||
|
||||
|
||||
@Component
|
||||
public class PayUtils {
|
||||
private static final Logger log = LoggerFactory.getLogger(PayUtils.class);
|
||||
@Value("${thirdPay.payType}")
|
||||
private String thirdPayType;
|
||||
@Value("${thirdPay.url}")
|
||||
private String thirdUrl;
|
||||
|
||||
@Value("${thirdPay.callInBack}")
|
||||
private String callInBack;
|
||||
|
||||
@Value("${thirdPay.callFSTBack}")
|
||||
private String callFSTBack;
|
||||
|
||||
@Value("${ysk.url}")
|
||||
private String url;
|
||||
|
||||
@Value("${ysk.callBackurl}")
|
||||
private String callBackurl;
|
||||
|
||||
@Value("${ysk.callBackGroupurl}")
|
||||
private String callBackGroupurl;
|
||||
|
||||
@Value("${ysk.callBackIn}")
|
||||
private String callBackIn;
|
||||
|
||||
private final RestTemplate restTemplate;
|
||||
|
||||
private final ThirdPayService thirdPayService;
|
||||
private final TbMemberInMapper tbMemberInMapper;
|
||||
|
||||
|
||||
|
||||
public PayUtils(RestTemplate restTemplate, ThirdPayService thirdPayService, TbMemberInMapper tbMemberInMapper) {
|
||||
this.restTemplate = restTemplate;
|
||||
this.thirdPayService = thirdPayService;
|
||||
this.tbMemberInMapper = tbMemberInMapper;
|
||||
}
|
||||
|
||||
public JsonNode getWxPay(String ip, String songOrderNo,
|
||||
Integer userId,
|
||||
String code,
|
||||
Integer shopId,
|
||||
BigDecimal money,
|
||||
Integer merchantId,
|
||||
String openId, TbMerchantThirdApply thirdApply) {
|
||||
TbMemberIn memberIn=new TbMemberIn();
|
||||
memberIn.setAmount(money);
|
||||
memberIn.setUserId(userId);
|
||||
memberIn.setCode(code);
|
||||
memberIn.setShopId(shopId);
|
||||
memberIn.setStatus("100");
|
||||
memberIn.setMerchantId(merchantId);
|
||||
memberIn.setCreateTime(new Date());
|
||||
String orderNo=DateUtils.getsdfTimesSS();
|
||||
log.info("开始发送支付请求,携带参数:{}", memberIn);
|
||||
JSONObject ext = new JSONObject();
|
||||
ext.put("payType", PayTypeConstant.MINI_PAY);
|
||||
ext.put("orderNo", songOrderNo);
|
||||
PublicResp<WxScanPayResp> publicResp= thirdPayService
|
||||
.scanpay(thirdUrl,thirdApply.getAppId(),
|
||||
"会员充值","会员充值",money.setScale(2, BigDecimal.ROUND_DOWN).multiply(new BigDecimal(100)).longValue(),
|
||||
"WECHAT",
|
||||
thirdApply.getSmallAppid(),
|
||||
openId,ip, orderNo,
|
||||
thirdApply.getStoreId(),callInBack,null,thirdApply.getAppToken(), ext.toJSONString());
|
||||
log.info("支付请求发送完毕,响应内容:{}", publicResp);
|
||||
if(ObjectUtil.isNotNull(publicResp)&&ObjectUtil.isNotEmpty(publicResp)){
|
||||
if("000000".equals(publicResp.getCode())){
|
||||
WxScanPayResp wxScanPayResp= publicResp.getObjData();
|
||||
if("TRADE_AWAIT".equals(wxScanPayResp.getState())){
|
||||
|
||||
memberIn.setOrderNo(orderNo);
|
||||
memberIn.setTradeNo(wxScanPayResp.getPayOrderId());
|
||||
memberIn.setUpdateTime(new Date());
|
||||
tbMemberInMapper.updateByPrimaryKeySelective(memberIn);
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
try {
|
||||
return mapper.readTree(wxScanPayResp.getPayInfo());
|
||||
} catch (JsonProcessingException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
}else{
|
||||
throw new MsgException(publicResp.getMsg());
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -6,7 +6,10 @@ import io.jsonwebtoken.Claims;
|
||||
import io.jsonwebtoken.Jwts;
|
||||
import io.jsonwebtoken.SignatureAlgorithm;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.web.context.request.RequestContextHolder;
|
||||
import org.springframework.web.context.request.ServletRequestAttributes;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
@@ -118,6 +121,13 @@ public class TokenUtil {
|
||||
}
|
||||
return jsonObject;
|
||||
}
|
||||
|
||||
public static Integer getUserId() {
|
||||
HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
|
||||
JSONObject jsonObject = parseParamFromToken(request.getHeader("token"));
|
||||
return jsonObject.getInteger("userId");
|
||||
|
||||
}
|
||||
// public static void main(String[] args) throws Exception {
|
||||
// System.out.println(refreshToken("eyJhbGciOiJIUzUxMiJ9.eyJleHAiOjE1OTY4Nzc5MjEsInN1YiI6ImRkZGRkIiwiaWF0IjoxNTk2Njk3OTIxfQ.lrg3KF9h9izbmyD2q5onqnZIKBqanWy9xCcroFpjxPKmJz6kz27G9lVlFpVanrL1I4SFf3Dz3q3Xu01DX2T_dw"));
|
||||
// SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
||||
|
||||
Reference in New Issue
Block a user