Fixing .gitignore
This commit is contained in:
@@ -1,36 +1,36 @@
|
||||
package com.peanut.modules.pay.applePay.service;
|
||||
|
||||
import com.peanut.common.utils.R;
|
||||
import com.peanut.modules.pay.IOSPay.Result;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
public interface ApplePayService {
|
||||
|
||||
/**
|
||||
* 看是否是己经验证过的该支付收据
|
||||
* @param receiptMd5
|
||||
* @return
|
||||
*/
|
||||
|
||||
public boolean isExistsIOSReceipt(String receiptMd5);
|
||||
|
||||
|
||||
int updateCurrentState(String payId, String userId, int a);
|
||||
|
||||
/**
|
||||
* IOS支付
|
||||
* @param transaction_id 订单号
|
||||
* @param product_id 产品id,也就是支付金额
|
||||
* @param purchase_date_ms 支付时间
|
||||
* @param receiptMd5 拿到收据的MD5
|
||||
* @param moneyId 金额id
|
||||
*/
|
||||
Result<Object> iosChargeSuccess(String transaction_id, String product_id, String purchase_date_ms, String receiptMd5, String moneyId, String userId);
|
||||
|
||||
|
||||
|
||||
R getAppPay(String verifyResult, String transactionID);
|
||||
|
||||
|
||||
}
|
||||
package com.peanut.modules.pay.applePay.service;
|
||||
|
||||
import com.peanut.common.utils.R;
|
||||
import com.peanut.modules.pay.IOSPay.Result;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
public interface ApplePayService {
|
||||
|
||||
/**
|
||||
* 看是否是己经验证过的该支付收据
|
||||
* @param receiptMd5
|
||||
* @return
|
||||
*/
|
||||
|
||||
public boolean isExistsIOSReceipt(String receiptMd5);
|
||||
|
||||
|
||||
int updateCurrentState(String payId, String userId, int a);
|
||||
|
||||
/**
|
||||
* IOS支付
|
||||
* @param transaction_id 订单号
|
||||
* @param product_id 产品id,也就是支付金额
|
||||
* @param purchase_date_ms 支付时间
|
||||
* @param receiptMd5 拿到收据的MD5
|
||||
* @param moneyId 金额id
|
||||
*/
|
||||
Result<Object> iosChargeSuccess(String transaction_id, String product_id, String purchase_date_ms, String receiptMd5, String moneyId, String userId);
|
||||
|
||||
|
||||
|
||||
R getAppPay(String verifyResult, String transactionID);
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1,214 +1,214 @@
|
||||
package com.peanut.modules.pay.applePay.service.impl;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.peanut.common.utils.DateUtils;
|
||||
import com.peanut.common.utils.R;
|
||||
import com.peanut.modules.book.entity.*;
|
||||
import com.peanut.modules.book.service.*;
|
||||
import com.peanut.modules.pay.IOSPay.Result;
|
||||
import com.peanut.modules.pay.applePay.service.ApplePayService;
|
||||
import com.peanut.modules.pay.applePay.utils.*;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.stereotype.Service;
|
||||
import javax.annotation.Resource;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.*;
|
||||
|
||||
|
||||
@Service("ApplePayService")
|
||||
@Slf4j
|
||||
@AllArgsConstructor
|
||||
public class ApplePayServiceImpl implements ApplePayService {
|
||||
|
||||
// 日志记录,系统支付模块记录日志信息输出到sys-pay
|
||||
private static final Logger logger = LoggerFactory.getLogger("sys-pay");
|
||||
|
||||
@Autowired
|
||||
private MyUserService userService;
|
||||
@Autowired
|
||||
private BuyOrderService buyOrderService;
|
||||
@Autowired
|
||||
private TransactionDetailsService transactionDetailsService;
|
||||
@Autowired
|
||||
private ApplePayUtil applePayUtil;
|
||||
@Autowired
|
||||
private BookBuyConfigService bookBuyConfigService;
|
||||
@Autowired
|
||||
private PayPaymentOrderService payPaymentOrderService;
|
||||
@Autowired
|
||||
public static final String TRADE_TYPE_APP = "APP";
|
||||
@Autowired
|
||||
private JdbcTemplate jdbcTemplate;
|
||||
|
||||
@Override
|
||||
public boolean isExistsIOSReceipt(String receiptMd5) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@Resource
|
||||
private TsBillMapper tsBillMapper;
|
||||
/**
|
||||
* 支付成功之后将当前订单的状态改为1
|
||||
*
|
||||
* @param payId
|
||||
* @param userId
|
||||
* @param a
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public int updateCurrentState(String payId, String userId, int a) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* IOS支付
|
||||
* @param transaction_id 订单号
|
||||
* @param product_id 产品id,也就是支付金额
|
||||
* @param purchase_date_ms 支付时间
|
||||
* @param receiptMd5 拿到收据的MD5
|
||||
* @param moneyId 金额id
|
||||
*/
|
||||
@Override
|
||||
public Result<Object> iosChargeSuccess(String transaction_id, String product_id, String purchase_date_ms, String receiptMd5, String moneyId, String userId) {
|
||||
/**
|
||||
* IOS支付
|
||||
* @param transaction_id 订单号
|
||||
* @param product_id 产品id,也就是支付金额
|
||||
* @param purchase_date_ms 支付时间
|
||||
* @param receiptMd5 拿到收据的MD5
|
||||
* @param moneyId 金额id
|
||||
*/
|
||||
|
||||
try {
|
||||
List<Map<String, Object>> queryForList = jdbcTemplate.queryForList("SELECT id,showcoin_num,give_showcoin_num,rmb_price from tsm_payment_config_ios where product_id =? ",
|
||||
moneyId);
|
||||
|
||||
if (queryForList.size() > 0) {
|
||||
String bill_content = "充值";//账单产生方式
|
||||
int bill_state = 1;// 充值
|
||||
int current_state = 1;// 支付成功
|
||||
int payment_method = 3;// IOS
|
||||
String date = DateUtils.DATE_TIME_PATTERN;// 当前时间
|
||||
BigDecimal amountofmoney = new BigDecimal(queryForList.get(0).get("rmb_price").toString());// 金额
|
||||
String uuid = UUID.randomUUID().toString().replaceAll("-", "");
|
||||
// 生成消费订单
|
||||
//String sql = "insert into ts_bill (id,users_id,payment_config_id,bill_num,bill_content,bill_sumofmoney,bill_state,current_state,payment_method,receipt,createtdate) value(?,?,?,?,?,?,?,?,?,?,?);";
|
||||
//jdbcTemplate.update(sql, uuid,userId,moneyId,transaction_id,bill_content,amountofmoney,bill_state,current_state,payment_method,receiptMd5,date);
|
||||
|
||||
String type = "1";// 加
|
||||
long showcoin_num = Long.parseLong(queryForList.get(0).get("showcoin_num").toString()) + Long.parseLong(queryForList.get(0).get("give_showcoin_num").toString());
|
||||
|
||||
|
||||
// 此操作为需求实际场景可根据用户产品需求更改
|
||||
//commonServiceI.updShowcoinNum(type, userId, showcoin_num);
|
||||
|
||||
return Result.ok("支付成功");
|
||||
} else {
|
||||
return Result.error("操作异常,所选金额不存在");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
return Result.error("ios支付异常");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public R getAppPay(String verifyResult, String transactionID) {
|
||||
log.info("##########################苹果支付验证!########################");
|
||||
JSONObject jsonObject = JSONObject.parseObject(verifyResult);
|
||||
String status = jsonObject.getString("status");
|
||||
//判断是否验证成功
|
||||
if ("0".equals(status)) {
|
||||
//app端所提供的收据是有效的,验证成功
|
||||
String receipt = jsonObject.getString("receipt");
|
||||
JSONObject returnJson = JSONObject.parseObject(receipt);
|
||||
String in_app = returnJson.getString("in_app");
|
||||
JSONObject in_appJson = JSONObject.parseObject(in_app.substring(1, in_app.length() - 1));
|
||||
String transactionId = in_appJson.getString("transaction_id");
|
||||
String in_app_ownership_type = in_appJson.getString("in_app_ownership_type");
|
||||
//如果验证后的订单号与app端传来的订单号一致并且状态为已支付状态则处理自己的业务
|
||||
if (transactionID.equals(transactionId) && "PURCHASED".equals(in_app_ownership_type)) {
|
||||
//===================处理自己的业务 ============================
|
||||
BuyOrderEntity order = this.buyOrderService.getOne(new QueryWrapper<BuyOrderEntity>().eq("order_sn", transactionId ));
|
||||
PayWechatOrderEntity wechat = new PayWechatOrderEntity();
|
||||
|
||||
|
||||
|
||||
|
||||
if ("vip".equals(order.getOrderType())) {
|
||||
//会员记录
|
||||
BookBuyConfigEntity bookBuyConfigEntity = bookBuyConfigService.getById(wechat.getBuyOrderId());
|
||||
String month = bookBuyConfigEntity.getMonth();
|
||||
userService.openMember(Integer.valueOf(transactionId),Integer.valueOf(month));
|
||||
buyOrderService.updateOrderStatus(Integer.valueOf(transactionId),order.getOrderSn(),"2");
|
||||
|
||||
|
||||
|
||||
}
|
||||
if ("order".equals(order.getOrderType())) {
|
||||
|
||||
BuyOrderEntity orderEntity = buyOrderService.getBaseMapper().selectOne(new QueryWrapper<BuyOrderEntity>().eq("order_sn", wechat.getOrderId()));
|
||||
BigDecimal realMoney = orderEntity.getRealMoney();
|
||||
//更新 订单 记录
|
||||
|
||||
}
|
||||
if ("point".equals(order.getOrderType())) {
|
||||
|
||||
BookBuyConfigEntity bookBuyConfigEntity = bookBuyConfigService.getById(wechat.getBuyOrderId());
|
||||
String realMoney = bookBuyConfigEntity.getRealMoney();
|
||||
Integer money = Integer.valueOf(realMoney);
|
||||
userService.rechargeHSPoint(Integer.valueOf(order.getUserId()),money);
|
||||
TransactionDetailsEntity transactionDetailsEntity = new TransactionDetailsEntity();
|
||||
transactionDetailsEntity.setUserId(Integer.valueOf(order.getUserId()));
|
||||
transactionDetailsEntity.setChangeAmount(new BigDecimal(money));
|
||||
transactionDetailsEntity.setOrderType("充值");
|
||||
transactionDetailsEntity.setRelationId(wechat.getId().intValue());
|
||||
transactionDetailsEntity.setRemark("充值");
|
||||
|
||||
MyUserEntity user = userService.getById(Integer.valueOf(order.getUserId()));
|
||||
BigDecimal peanutCoin = user.getPeanutCoin();
|
||||
transactionDetailsEntity.setUserBalance(peanutCoin);
|
||||
transactionDetailsEntity.setUserName(user.getNickname());
|
||||
transactionDetailsEntity.setTel(user.getTel());
|
||||
transactionDetailsService.save(transactionDetailsEntity);
|
||||
// 插入 花生币 充值记录
|
||||
PayPaymentOrderEntity payPaymentOrderEntity = new PayPaymentOrderEntity();
|
||||
payPaymentOrderEntity.setUserId(Integer.valueOf(order.getUserId()));
|
||||
payPaymentOrderEntity.setOrderId(String.valueOf(wechat.getId()));
|
||||
payPaymentOrderEntity.setRealAmount(new BigDecimal(bookBuyConfigEntity.getRealMoney()));
|
||||
payPaymentOrderEntity.setRechargeAmount(new BigDecimal(bookBuyConfigEntity.getMoney()));
|
||||
payPaymentOrderEntity.setRechargeChannel(bookBuyConfigEntity.getQudao());
|
||||
payPaymentOrderEntity.setRechargeStatus("success");
|
||||
payPaymentOrderEntity.setSuccessTime(new Date());
|
||||
payPaymentOrderEntity.setUserName(user.getNickname());
|
||||
payPaymentOrderEntity.setTel(user.getTel());
|
||||
payPaymentOrderService.save(payPaymentOrderEntity);
|
||||
buyOrderService.updateOrderStatus(Integer.valueOf(order.getUserId()),order.getOrderSn(),"2");
|
||||
// 插入花生币 变动记录
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
return R.ok();
|
||||
}
|
||||
return R.error("苹果内购验证失败");
|
||||
}}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
package com.peanut.modules.pay.applePay.service.impl;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.peanut.common.utils.DateUtils;
|
||||
import com.peanut.common.utils.R;
|
||||
import com.peanut.modules.book.entity.*;
|
||||
import com.peanut.modules.book.service.*;
|
||||
import com.peanut.modules.pay.IOSPay.Result;
|
||||
import com.peanut.modules.pay.applePay.service.ApplePayService;
|
||||
import com.peanut.modules.pay.applePay.utils.*;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.stereotype.Service;
|
||||
import javax.annotation.Resource;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.*;
|
||||
|
||||
|
||||
@Service("ApplePayService")
|
||||
@Slf4j
|
||||
@AllArgsConstructor
|
||||
public class ApplePayServiceImpl implements ApplePayService {
|
||||
|
||||
// 日志记录,系统支付模块记录日志信息输出到sys-pay
|
||||
private static final Logger logger = LoggerFactory.getLogger("sys-pay");
|
||||
|
||||
@Autowired
|
||||
private MyUserService userService;
|
||||
@Autowired
|
||||
private BuyOrderService buyOrderService;
|
||||
@Autowired
|
||||
private TransactionDetailsService transactionDetailsService;
|
||||
@Autowired
|
||||
private ApplePayUtil applePayUtil;
|
||||
@Autowired
|
||||
private BookBuyConfigService bookBuyConfigService;
|
||||
@Autowired
|
||||
private PayPaymentOrderService payPaymentOrderService;
|
||||
@Autowired
|
||||
public static final String TRADE_TYPE_APP = "APP";
|
||||
@Autowired
|
||||
private JdbcTemplate jdbcTemplate;
|
||||
|
||||
@Override
|
||||
public boolean isExistsIOSReceipt(String receiptMd5) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@Resource
|
||||
private TsBillMapper tsBillMapper;
|
||||
/**
|
||||
* 支付成功之后将当前订单的状态改为1
|
||||
*
|
||||
* @param payId
|
||||
* @param userId
|
||||
* @param a
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public int updateCurrentState(String payId, String userId, int a) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* IOS支付
|
||||
* @param transaction_id 订单号
|
||||
* @param product_id 产品id,也就是支付金额
|
||||
* @param purchase_date_ms 支付时间
|
||||
* @param receiptMd5 拿到收据的MD5
|
||||
* @param moneyId 金额id
|
||||
*/
|
||||
@Override
|
||||
public Result<Object> iosChargeSuccess(String transaction_id, String product_id, String purchase_date_ms, String receiptMd5, String moneyId, String userId) {
|
||||
/**
|
||||
* IOS支付
|
||||
* @param transaction_id 订单号
|
||||
* @param product_id 产品id,也就是支付金额
|
||||
* @param purchase_date_ms 支付时间
|
||||
* @param receiptMd5 拿到收据的MD5
|
||||
* @param moneyId 金额id
|
||||
*/
|
||||
|
||||
try {
|
||||
List<Map<String, Object>> queryForList = jdbcTemplate.queryForList("SELECT id,showcoin_num,give_showcoin_num,rmb_price from tsm_payment_config_ios where product_id =? ",
|
||||
moneyId);
|
||||
|
||||
if (queryForList.size() > 0) {
|
||||
String bill_content = "充值";//账单产生方式
|
||||
int bill_state = 1;// 充值
|
||||
int current_state = 1;// 支付成功
|
||||
int payment_method = 3;// IOS
|
||||
String date = DateUtils.DATE_TIME_PATTERN;// 当前时间
|
||||
BigDecimal amountofmoney = new BigDecimal(queryForList.get(0).get("rmb_price").toString());// 金额
|
||||
String uuid = UUID.randomUUID().toString().replaceAll("-", "");
|
||||
// 生成消费订单
|
||||
//String sql = "insert into ts_bill (id,users_id,payment_config_id,bill_num,bill_content,bill_sumofmoney,bill_state,current_state,payment_method,receipt,createtdate) value(?,?,?,?,?,?,?,?,?,?,?);";
|
||||
//jdbcTemplate.update(sql, uuid,userId,moneyId,transaction_id,bill_content,amountofmoney,bill_state,current_state,payment_method,receiptMd5,date);
|
||||
|
||||
String type = "1";// 加
|
||||
long showcoin_num = Long.parseLong(queryForList.get(0).get("showcoin_num").toString()) + Long.parseLong(queryForList.get(0).get("give_showcoin_num").toString());
|
||||
|
||||
|
||||
// 此操作为需求实际场景可根据用户产品需求更改
|
||||
//commonServiceI.updShowcoinNum(type, userId, showcoin_num);
|
||||
|
||||
return Result.ok("支付成功");
|
||||
} else {
|
||||
return Result.error("操作异常,所选金额不存在");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
return Result.error("ios支付异常");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public R getAppPay(String verifyResult, String transactionID) {
|
||||
log.info("##########################苹果支付验证!########################");
|
||||
JSONObject jsonObject = JSONObject.parseObject(verifyResult);
|
||||
String status = jsonObject.getString("status");
|
||||
//判断是否验证成功
|
||||
if ("0".equals(status)) {
|
||||
//app端所提供的收据是有效的,验证成功
|
||||
String receipt = jsonObject.getString("receipt");
|
||||
JSONObject returnJson = JSONObject.parseObject(receipt);
|
||||
String in_app = returnJson.getString("in_app");
|
||||
JSONObject in_appJson = JSONObject.parseObject(in_app.substring(1, in_app.length() - 1));
|
||||
String transactionId = in_appJson.getString("transaction_id");
|
||||
String in_app_ownership_type = in_appJson.getString("in_app_ownership_type");
|
||||
//如果验证后的订单号与app端传来的订单号一致并且状态为已支付状态则处理自己的业务
|
||||
if (transactionID.equals(transactionId) && "PURCHASED".equals(in_app_ownership_type)) {
|
||||
//===================处理自己的业务 ============================
|
||||
BuyOrderEntity order = this.buyOrderService.getOne(new QueryWrapper<BuyOrderEntity>().eq("order_sn", transactionId ));
|
||||
PayWechatOrderEntity wechat = new PayWechatOrderEntity();
|
||||
|
||||
|
||||
|
||||
|
||||
if ("vip".equals(order.getOrderType())) {
|
||||
//会员记录
|
||||
BookBuyConfigEntity bookBuyConfigEntity = bookBuyConfigService.getById(wechat.getBuyOrderId());
|
||||
String month = bookBuyConfigEntity.getMonth();
|
||||
userService.openMember(Integer.valueOf(transactionId),Integer.valueOf(month));
|
||||
buyOrderService.updateOrderStatus(Integer.valueOf(transactionId),order.getOrderSn(),"2");
|
||||
|
||||
|
||||
|
||||
}
|
||||
if ("order".equals(order.getOrderType())) {
|
||||
|
||||
BuyOrderEntity orderEntity = buyOrderService.getBaseMapper().selectOne(new QueryWrapper<BuyOrderEntity>().eq("order_sn", wechat.getOrderId()));
|
||||
BigDecimal realMoney = orderEntity.getRealMoney();
|
||||
//更新 订单 记录
|
||||
|
||||
}
|
||||
if ("point".equals(order.getOrderType())) {
|
||||
|
||||
BookBuyConfigEntity bookBuyConfigEntity = bookBuyConfigService.getById(wechat.getBuyOrderId());
|
||||
String realMoney = bookBuyConfigEntity.getRealMoney();
|
||||
Integer money = Integer.valueOf(realMoney);
|
||||
userService.rechargeHSPoint(Integer.valueOf(order.getUserId()),money);
|
||||
TransactionDetailsEntity transactionDetailsEntity = new TransactionDetailsEntity();
|
||||
transactionDetailsEntity.setUserId(Integer.valueOf(order.getUserId()));
|
||||
transactionDetailsEntity.setChangeAmount(new BigDecimal(money));
|
||||
transactionDetailsEntity.setOrderType("充值");
|
||||
transactionDetailsEntity.setRelationId(wechat.getId().intValue());
|
||||
transactionDetailsEntity.setRemark("充值");
|
||||
|
||||
MyUserEntity user = userService.getById(Integer.valueOf(order.getUserId()));
|
||||
BigDecimal peanutCoin = user.getPeanutCoin();
|
||||
transactionDetailsEntity.setUserBalance(peanutCoin);
|
||||
transactionDetailsEntity.setUserName(user.getNickname());
|
||||
transactionDetailsEntity.setTel(user.getTel());
|
||||
transactionDetailsService.save(transactionDetailsEntity);
|
||||
// 插入 花生币 充值记录
|
||||
PayPaymentOrderEntity payPaymentOrderEntity = new PayPaymentOrderEntity();
|
||||
payPaymentOrderEntity.setUserId(Integer.valueOf(order.getUserId()));
|
||||
payPaymentOrderEntity.setOrderId(String.valueOf(wechat.getId()));
|
||||
payPaymentOrderEntity.setRealAmount(new BigDecimal(bookBuyConfigEntity.getRealMoney()));
|
||||
payPaymentOrderEntity.setRechargeAmount(new BigDecimal(bookBuyConfigEntity.getMoney()));
|
||||
payPaymentOrderEntity.setRechargeChannel(bookBuyConfigEntity.getQudao());
|
||||
payPaymentOrderEntity.setRechargeStatus("success");
|
||||
payPaymentOrderEntity.setSuccessTime(new Date());
|
||||
payPaymentOrderEntity.setUserName(user.getNickname());
|
||||
payPaymentOrderEntity.setTel(user.getTel());
|
||||
payPaymentOrderService.save(payPaymentOrderEntity);
|
||||
buyOrderService.updateOrderStatus(Integer.valueOf(order.getUserId()),order.getOrderSn(),"2");
|
||||
// 插入花生币 变动记录
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
return R.ok();
|
||||
}
|
||||
return R.error("苹果内购验证失败");
|
||||
}}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user