updates 抖音新增体育小程序
This commit is contained in:
parent
a05f139797
commit
32aca1b426
|
|
@ -1,17 +1,26 @@
|
|||
package org.jeecg.modules.api.controller;
|
||||
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import cn.hutool.json.JSONObject;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import io.swagger.annotations.Api;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.jeecg.common.api.vo.Result;
|
||||
import org.jeecg.common.util.AssertUtils;
|
||||
import org.jeecg.modules.yx.entity.YxSportsScore;
|
||||
import org.jeecg.modules.yx.service.IYxSportsScoreService;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author ZhouWenTao
|
||||
|
|
@ -22,6 +31,9 @@ import javax.servlet.http.HttpServletRequest;
|
|||
@RequestMapping("/api/static/data")
|
||||
@Slf4j
|
||||
public class StaticDataController {
|
||||
@Resource
|
||||
private IYxSportsScoreService yxSportsScoreService;
|
||||
|
||||
@RequestMapping(value = "/getJson",method = RequestMethod.POST)
|
||||
public Result<?> getJson(@RequestBody JSONObject params, HttpServletRequest request){
|
||||
String key = params.getStr("key");
|
||||
|
|
@ -51,9 +63,27 @@ public class StaticDataController {
|
|||
String json = "[{\"value\":\"体育类\",\"label\":\"体育类\",\"scoreMax\":150}]";
|
||||
return Result.OK(JSONArray.parseArray(json));
|
||||
}
|
||||
}
|
||||
if ("reloadMajorModalMessage".equals(key)) {
|
||||
|
||||
case "sportsScore":
|
||||
// 体育成绩计算器
|
||||
Integer year = params.getInt("year");
|
||||
String sex = params.getStr("sex");
|
||||
BigDecimal sprint = params.getBigDecimal("sprint");// 100米跑
|
||||
BigDecimal jump = params.getBigDecimal("jump");// 立定跳远
|
||||
BigDecimal shotPut = params.getBigDecimal("shotPut");// 推铅球
|
||||
AssertUtils.notNull(sex,"请选择年份");
|
||||
AssertUtils.notNull(sex,"请选择性别成绩");
|
||||
AssertUtils.notNull(sprint,"请输入100米跑成绩");
|
||||
AssertUtils.notNull(jump,"请输入立定跳远成绩");
|
||||
AssertUtils.notNull(shotPut,"请输入推铅球成绩");
|
||||
List<BigDecimal> pointsList = new ArrayList<>();
|
||||
// 100米
|
||||
pointsList.add(yxSportsScoreService.getSprintPoints(year,sex,sprint));
|
||||
// 立定跳远
|
||||
pointsList.add(yxSportsScoreService.getJumpPoints(year,sex,jump));
|
||||
// 推铅球
|
||||
pointsList.add(yxSportsScoreService.getShotPutPoints(year,sex,shotPut));
|
||||
return Result.OK(pointsList);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -122,12 +122,13 @@ public class MiniPayApiController {
|
|||
BigDecimal totalAmount = skuPrice.multiply(YxConstant.bigDecimal100);
|
||||
// totalAmount = YxConstant.bigDecimal100;
|
||||
|
||||
String description = "艺体志愿宝VIP";
|
||||
String attach = programType;
|
||||
if (StringUtils.isNotBlank(yxVipSku.getSkuName())) {
|
||||
description += "-" + yxVipSku.getSkuName();
|
||||
attach += "-" + yxVipSku.getSkuName();
|
||||
}
|
||||
String description = attach;
|
||||
if (StringUtils.isNotBlank(yxVipSku.getSkuDetail())) {
|
||||
description += ";" + yxVipSku.getSkuDetail();
|
||||
description = yxVipSku.getSkuDetail();
|
||||
}
|
||||
|
||||
try {
|
||||
|
|
@ -138,18 +139,20 @@ public class MiniPayApiController {
|
|||
yxOrder.setPaymentUserId(user.getId());//付款人
|
||||
yxOrder.setOrderStatus("1");
|
||||
yxOrder.setProvider(provider);
|
||||
yxOrder.setPaymentType(programType);
|
||||
yxOrder.setProgramType(programType);
|
||||
//判断是抖音平台 还是 微信平台 小程序操作
|
||||
if ("toutiao".equals(provider)) {
|
||||
// 抖音平台
|
||||
if("体育志愿宝".equals(programType)){
|
||||
String douyinSign = DouYinUtil.main(douYinTiyuConfig.getAppId(), douYinTiyuConfig.getToken(),douYinTiyuConfig.getNotifyUrl(), douYinTiyuConfig.getSalt(), orderCode, totalAmount.intValue(),yxVipSku.getSkuName(), description);
|
||||
String douyinSign = DouYinUtil.main(douYinTiyuConfig.getAppId(), douYinTiyuConfig.getToken(),douYinTiyuConfig.getNotifyUrl(), douYinTiyuConfig.getSalt(), orderCode, totalAmount.intValue(),attach, description);
|
||||
yxOrder.setOrderSign(douyinSign);
|
||||
}else{
|
||||
String douyinSign = DouYinUtil.main(douYinConfig.getAppId(), douYinConfig.getToken(),douYinConfig.getNotifyUrl(), douYinConfig.getSalt(), orderCode, totalAmount.intValue(),yxVipSku.getSkuName(), description);
|
||||
String douyinSign = DouYinUtil.main(douYinConfig.getAppId(), douYinConfig.getToken(),douYinConfig.getNotifyUrl(), douYinConfig.getSalt(), orderCode, totalAmount.intValue(),attach, description);
|
||||
yxOrder.setOrderSign(douyinSign);
|
||||
}
|
||||
}
|
||||
else {
|
||||
// 微信平台
|
||||
String timeExpire = DateTimeZoneUtil.dateToTimeZone(System.currentTimeMillis() + 1000 * 60 * 3);
|
||||
UnifiedOrderModel unifiedOrderModel = new UnifiedOrderModel()
|
||||
// APPID
|
||||
|
|
@ -159,7 +162,7 @@ public class MiniPayApiController {
|
|||
.setDescription(description)
|
||||
.setOut_trade_no(orderCode)
|
||||
.setTime_expire(timeExpire)
|
||||
.setAttach("艺体志愿宝"+yxVipSku.getSkuName())
|
||||
.setAttach(attach)
|
||||
.setNotify_url(weXinConfig.getNotifyUrl())
|
||||
.setAmount(new Amount().setTotal(totalAmount.intValue()))
|
||||
.setPayer(new Payer().setOpenid(openId));
|
||||
|
|
@ -211,112 +214,74 @@ public class MiniPayApiController {
|
|||
Map<String, String> map = new HashMap<>(12);
|
||||
String result = HttpKit.readData(request);
|
||||
try {
|
||||
String timestamp = request.getHeader("Wechatpay-Timestamp");
|
||||
YxOrder yxOrder = null;
|
||||
SysUser sysUser = null;
|
||||
if (StringUtils.isNotBlank(timestamp)) {
|
||||
//微信平台
|
||||
String nonce = request.getHeader("Wechatpay-Nonce");
|
||||
String serialNo = request.getHeader("Wechatpay-Serial");
|
||||
String signature = request.getHeader("Wechatpay-Signature");
|
||||
log.info("timestamp:{} nonce:{} serialNo:{} signature:{}", timestamp, nonce, serialNo, signature);
|
||||
log.info("支付通知密文 {}", result);
|
||||
// 需要通过证书序列号查找对应的证书,verifyNotify 中有验证证书的序列号
|
||||
String plainText = WxPayKit.verifyNotify(serialNo, result, signature, nonce, timestamp,
|
||||
weXinConfig.getMchKey(), weXinConfig.getPlatFormPath());
|
||||
log.info("支付通知明文 {}", plainText);
|
||||
if (StrUtil.isNotEmpty(plainText)) {
|
||||
com.alibaba.fastjson.JSONObject plainTextJson = JSONObject.parseObject(plainText);
|
||||
//订单号
|
||||
String outTradeNo = plainTextJson.getString("out_trade_no");
|
||||
//支付状态
|
||||
String tradeState = plainTextJson.getString("trade_state");
|
||||
if ("SUCCESS".equals(tradeState)) {
|
||||
//支付成功
|
||||
yxOrderService.update(new LambdaUpdateWrapper<YxOrder>().eq(YxOrder::getOrderCode, outTradeNo).set(YxOrder::getPaymentTime, new Date()).set(YxOrder::getOrderStatus, "2"));
|
||||
}
|
||||
//支付成功,修改订单信息
|
||||
response.setStatus(200);
|
||||
map.put("code", "SUCCESS");
|
||||
map.put("message", "SUCCESS");
|
||||
} else {
|
||||
response.setStatus(500);
|
||||
map.put("code", "ERROR");
|
||||
map.put("message", "签名错误");
|
||||
//抖音小程序
|
||||
System.out.println("===================result:" + result);
|
||||
JSONObject requestJson = JSONObject.parseObject(result);
|
||||
|
||||
//生成本地签名
|
||||
List<String> sortedString = new ArrayList<>();
|
||||
//token
|
||||
sortedString.add(douYinConfig.getToken());
|
||||
//时间戳
|
||||
sortedString.add(requestJson.getString("timestamp"));
|
||||
//随机数
|
||||
sortedString.add(requestJson.getString("nonce"));
|
||||
//msg
|
||||
sortedString.add(requestJson.getString("msg"));
|
||||
Collections.sort(sortedString);
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sortedString.forEach(sb::append);
|
||||
String sign = Sign.callbackSign(sortedString);
|
||||
String nonce = requestJson.getString("nonce");//随机数
|
||||
String msgSignature = requestJson.getString("msg_signature");//签名
|
||||
String type = requestJson.getString("type");//回调类型标记,支付成功回调为"payment"
|
||||
String msg = requestJson.getString("msg");
|
||||
JSONObject msgJson = JSONObject.parseObject(msg);//订单信息的 json 字符串
|
||||
String way = msgJson.getString("way");//way 字段中标识了支付渠道: 1-微信支付,2-支付宝支付,10-抖音支付
|
||||
String cpOrderno = msgJson.getString("cp_orderno");//订单号
|
||||
String channelNo = msgJson.getString("channel_no");//支付渠道侧单号(抖音平台请求下游渠道微信或支付宝时传入的单号)
|
||||
String paymentOrderNo = msgJson.getString("payment_order_no");//支付渠道侧PC单号,支付页面可见(微信支付宝侧的订单号)
|
||||
Integer totalAmount = msgJson.getInteger("total_amount");//支付金额,单位为分
|
||||
String status = msgJson.getString("status");//固定SUCCESS
|
||||
Long paidAt = msgJson.getLong("paid_at");//支付时间,Unix 时间戳,10 位,整型数
|
||||
if ("SUCCESS".equals(status) && sign.equals(msgSignature)) {
|
||||
//支付成功,修改订单信息
|
||||
Date date = new Date();
|
||||
date.setTime(paidAt*YxConstant.bigDecimal1000);
|
||||
yxOrderService.paymentOrderOver(cpOrderno, DouWayPaymentMethod.getByWay(way), "2", date);
|
||||
yxOrder = yxOrderService.getByOrderCode(cpOrderno);
|
||||
sysUser = sysUserService.getById(yxOrder.getPaymentUserId());
|
||||
|
||||
long createTimeLong = yxOrder.getCreateTime().getTime() / YxConstant.bigDecimal1000;
|
||||
//同步抖音订单
|
||||
DouYinOrderSyncModel douYinOrderSyncModel = new DouYinOrderSyncModel();
|
||||
douYinOrderSyncModel.setOrder_id(cpOrderno);
|
||||
douYinOrderSyncModel.setCreate_time(createTimeLong);
|
||||
douYinOrderSyncModel.setStatus("已支付");
|
||||
douYinOrderSyncModel.setAmount(1);//订单总数
|
||||
douYinOrderSyncModel.setTotal_price(yxOrder.getTotalAmount().longValue());
|
||||
douYinOrderSyncModel.setDetail_url("pages/zyb/order/detail?orderCode="+cpOrderno);
|
||||
List<ItemStruct> itemList=new ArrayList<>();
|
||||
String img="https://mp-7a4eecb1-2a04-4d36-b050-1c4a78cc31a4.cdn.bspapp.com/images/vip.png";
|
||||
if ("1001".equals(yxOrder.getSkuCode())) {
|
||||
img="https://mp-7a4eecb1-2a04-4d36-b050-1c4a78cc31a4.cdn.bspapp.com/images/tiyanka.png";
|
||||
}
|
||||
response.setHeader("Content-type", ContentType.JSON.toString());
|
||||
response.getOutputStream().write(JSONUtil.toJsonStr(map).getBytes(StandardCharsets.UTF_8));
|
||||
response.flushBuffer();
|
||||
itemList.add(new ItemStruct(yxOrder.getSkuCode(),img,"艺体志愿宝-"+yxOrder.getSkuName(),null,1,yxOrder.getTotalAmount().longValue()));
|
||||
douYinOrderSyncModel.setItem_list(itemList);
|
||||
DouYinUtil.orderSync(douYinOrderSyncModel,douYinConfig.getAppId(),douYinConfig.getAppSecret(),sysUser.getDyOpenId());
|
||||
response.setStatus(200);
|
||||
map.put("code", "SUCCESS");
|
||||
map.put("message", "SUCCESS");
|
||||
} else {
|
||||
//抖音小程序
|
||||
System.out.println("===================result:" + result);
|
||||
JSONObject requestJson = JSONObject.parseObject(result);
|
||||
|
||||
//生成本地签名
|
||||
List<String> sortedString = new ArrayList<>();
|
||||
//token
|
||||
sortedString.add(douYinConfig.getToken());
|
||||
//时间戳
|
||||
sortedString.add(requestJson.getString("timestamp"));
|
||||
//随机数
|
||||
sortedString.add(requestJson.getString("nonce"));
|
||||
//msg
|
||||
sortedString.add(requestJson.getString("msg"));
|
||||
Collections.sort(sortedString);
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sortedString.forEach(sb::append);
|
||||
String sign = Sign.callbackSign(sortedString);
|
||||
timestamp = requestJson.getString("timestamp");//Unix 时间戳,字符串类型
|
||||
String nonce = requestJson.getString("nonce");//随机数
|
||||
String msgSignature = requestJson.getString("msg_signature");//签名
|
||||
String type = requestJson.getString("type");//回调类型标记,支付成功回调为"payment"
|
||||
String msg = requestJson.getString("msg");
|
||||
JSONObject msgJson = JSONObject.parseObject(msg);//订单信息的 json 字符串
|
||||
String way = msgJson.getString("way");//way 字段中标识了支付渠道: 1-微信支付,2-支付宝支付,10-抖音支付
|
||||
String cpOrderno = msgJson.getString("cp_orderno");//订单号
|
||||
String channelNo = msgJson.getString("channel_no");//支付渠道侧单号(抖音平台请求下游渠道微信或支付宝时传入的单号)
|
||||
String paymentOrderNo = msgJson.getString("payment_order_no");//支付渠道侧PC单号,支付页面可见(微信支付宝侧的订单号)
|
||||
Integer totalAmount = msgJson.getInteger("total_amount");//支付金额,单位为分
|
||||
String status = msgJson.getString("status");//固定SUCCESS
|
||||
Long paidAt = msgJson.getLong("paid_at");//支付时间,Unix 时间戳,10 位,整型数
|
||||
if ("SUCCESS".equals(status) && sign.equals(msgSignature)) {
|
||||
//支付成功,修改订单信息
|
||||
Date date = new Date();
|
||||
date.setTime(paidAt*YxConstant.bigDecimal1000);
|
||||
yxOrderService.paymentOrderOver(cpOrderno, DouWayPaymentMethod.getByWay(way), "2", date);
|
||||
yxOrder = yxOrderService.getByOrderCode(cpOrderno);
|
||||
sysUser = sysUserService.getById(yxOrder.getPaymentUserId());
|
||||
|
||||
long createTimeLong = yxOrder.getCreateTime().getTime() / YxConstant.bigDecimal1000;
|
||||
//同步抖音订单
|
||||
DouYinOrderSyncModel douYinOrderSyncModel = new DouYinOrderSyncModel();
|
||||
douYinOrderSyncModel.setOrder_id(cpOrderno);
|
||||
douYinOrderSyncModel.setCreate_time(createTimeLong);
|
||||
douYinOrderSyncModel.setStatus("已支付");
|
||||
douYinOrderSyncModel.setAmount(1);//订单总数
|
||||
douYinOrderSyncModel.setTotal_price(yxOrder.getTotalAmount().longValue());
|
||||
douYinOrderSyncModel.setDetail_url("pages/zyb/order/detail?orderCode="+cpOrderno);
|
||||
List<ItemStruct> itemList=new ArrayList<>();
|
||||
String img="https://mp-7a4eecb1-2a04-4d36-b050-1c4a78cc31a4.cdn.bspapp.com/images/vip.png";
|
||||
if ("1001".equals(yxOrder.getSkuCode())) {
|
||||
img="https://mp-7a4eecb1-2a04-4d36-b050-1c4a78cc31a4.cdn.bspapp.com/images/tiyanka.png";
|
||||
}
|
||||
itemList.add(new ItemStruct(yxOrder.getSkuCode(),img,"艺体志愿宝-"+yxOrder.getSkuName(),null,1,yxOrder.getTotalAmount().longValue()));
|
||||
douYinOrderSyncModel.setItem_list(itemList);
|
||||
DouYinUtil.orderSync(douYinOrderSyncModel,douYinConfig.getAppId(),douYinConfig.getAppSecret(),sysUser.getDyOpenId());
|
||||
response.setStatus(200);
|
||||
map.put("code", "SUCCESS");
|
||||
map.put("message", "SUCCESS");
|
||||
} else {
|
||||
response.setStatus(500);
|
||||
map.put("code", "ERROR");
|
||||
map.put("message", "签名错误");
|
||||
}
|
||||
response.setHeader("Content-type", ContentType.JSON.toString());
|
||||
response.getOutputStream().write(JSONUtil.toJsonStr(map).getBytes(StandardCharsets.UTF_8));
|
||||
response.flushBuffer();
|
||||
response.setStatus(500);
|
||||
map.put("code", "ERROR");
|
||||
map.put("message", "签名错误");
|
||||
}
|
||||
|
||||
response.setHeader("Content-type", ContentType.JSON.toString());
|
||||
response.getOutputStream().write(JSONUtil.toJsonStr(map).getBytes(StandardCharsets.UTF_8));
|
||||
response.flushBuffer();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -69,6 +69,14 @@ public class MiniVipController {
|
|||
List<YxVipSku> list = yxVipSkuService.list(queryWrapper);
|
||||
return Result.OK(list);
|
||||
}
|
||||
@ApiOperation(value = "v1获取vip信息")
|
||||
@GetMapping(value = "/v1/getVipInfo")
|
||||
public Result<?> v1VipInfo() {
|
||||
LoginUser loginUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
|
||||
AssertUtils.notNull(loginUser, "未获取到登录信息");
|
||||
VipDTO userVip = miniUserService.getUserVip(loginUser.getId());
|
||||
return Result.OK(userVip);
|
||||
}
|
||||
|
||||
@ApiOperation(value = "获取vip信息")
|
||||
@GetMapping(value = "/getVipInfo")
|
||||
|
|
|
|||
|
|
@ -48,7 +48,7 @@ public class DouYinUtil {
|
|||
//put("thirdparty_id", "");//tta4bad200000xxxxxx
|
||||
put("out_order_no", orderCode);
|
||||
put("total_amount", totalAmount);
|
||||
put("subject", "艺体志愿宝"+skuName);
|
||||
put("subject", skuName);
|
||||
put("body", description);
|
||||
put("valid_time", 172800);
|
||||
put("notify_url", notifyUrl);
|
||||
|
|
|
|||
Loading…
Reference in New Issue