苹果内购、支付宝微信app支付H5支付、退款
/*** @author: tjr* @Date: 2021/4/20 15:11* @Description: 支付接口*/
@Slf4j
@RestController
@RequestMapping(value = "/pay")
@Api(value = "支付", tags = "支付模块")
public class PayController {private final AliPayService aliPayService;private final WxPayService wxPayService;private final CacheService cacheService;private final IosPayService iosPayService;private final DistributedLocker distributedLocker;private final static String SUCCESS = "SUCCESS";private final static String FAIL = "FAIL";private final static String key = "pay:";private final static Long lastTime = 5 * 60L;private final static String CHECK_MWEB_URL = "https://wx.tenpay.com/cgi-bin/mmpayweb-bin/checkmweb?";public PayController(AliPayService aliPayService, WxPayService wxPayService, CacheService cacheService, IosPayService iosPayService, DistributedLocker distributedLocker) {this.aliPayService = aliPayService;this.wxPayService = wxPayService;this.cacheService = cacheService;this.iosPayService = iosPayService;this.distributedLocker = distributedLocker;}@ApiOperation(value = "苹果内购支付接口")@PostMapping("/iosPay")public boolean iosInAppPurchase(@RequestBody @Valid IosPayEntity iosPayEntity) {String key = "IosPay:" + WebUtils.getAppUserId();Lock lock = distributedLocker.getLock(key);boolean result = false;boolean hasLock = lock.tryLock();if (hasLock) {try {// 先清除缓存,再查JpaUtils.clear();result = iosPayService.buyAccountDetails(iosPayEntity);} catch (Exception e) {log.error("苹果内购支付失败" + e);e.printStackTrace();} finally {lock.unlock();}}return result;}@ApiOperation(value = "统一H5支付接口")@PostMapping("/h5Pay")public AliPayEntityVo h5Pay(@RequestBody AliWxPayEntity entity) throws AlipayApiException {if (entity.getMoney() == null || entity.getChannel() == null) {throw BaseException.of(2000, "请输入参数");}if (entity.getChannel() == OrderConstants.PAY_CHANNEL_WX) {WxPayEntity wxPayEntity = new WxPayEntity();String ip = WebUtils.getIp();BigDecimal bigDecimal = new BigDecimal(entity.getMoney());int i = bigDecimal.multiply(new BigDecimal(100)).intValue();wxPayEntity.setTotalMoney(String.valueOf(i));wxPayEntity.setOrderId(entity.getOrderId());wxPayEntity.setIp(ip);wxPayEntity.setBody(entity.getBody());//微信支付ResultMap resultMap = wxPayService.h5Pay(wxPayEntity);AliPayEntityVo payEntity = new AliPayEntityVo();payEntity.setOrderId(entity.getOrderId());Map<String, String> data = (Map<String, String>) resultMap.get("data");log.info("wei xin pay info : {}", data);String wxString = CHECK_MWEB_URL + "prepay_id=" + data.get("prepayid") + "&package=" + data.get("package");cacheService.set(key + payEntity.getOrderId(), wxString, lastTime);return payEntity;}if (entity.getChannel() == OrderConstants.PAY_CHANNEL_ZFB) {//发起支付,支付宝//获取支付AlipayTradeWapPayResponse response = aliPayService.h5Pay(entity);if (response.isSuccess()) {log.debug("调用成功" + response.getBody());AliPayEntityVo payEntity = new AliPayEntityVo();payEntity.setOrderId(entity.getOrderId());cacheService.set(key + payEntity.getOrderId(), response.getBody(), lastTime);return payEntity;} else {log.error("调用失败" + response.getBody());throw BaseException.of(2000, response.getBody());}}throw BaseException.of(2000, "下单失败");}@ApiOperation(value = "统一app支付接口")@PostMapping("/appPay")public ApiResponse<PayEntity> appPay(@RequestBody AliWxPayEntity entity) {ApiResponse<PayEntity> apiResponse = new ApiResponse<>();if (entity.getMoney() == null || entity.getChannel() == null|| entity.getOrderId() == null) {throw BaseException.of(2000, "请输入参数");}if (entity.getChannel() == OrderConstants.PAY_CHANNEL_ZFB) {//发起支付,支付宝//获取支付AlipayTradeAppPayResponse response = aliPayService.tradeAppPay(entity);if (response.isSuccess()) {log.debug("调用成功" + response.getBody());PayEntity payEntity = new PayEntity();payEntity.setOrderId(String.valueOf(entity.getOrderId()));payEntity.setPay(response.getBody());if (ObjectUtils.isEmpty(response.getBody())) {apiResponse.setCode(500);apiResponse.setMessage("支付宝下单失败!");}apiResponse.setData(payEntity);return apiResponse;} else {log.error("调用失败" + response.getBody());throw BaseException.of(2000, response.getBody());}}if (entity.getChannel() == OrderConstants.PAY_CHANNEL_WX) {WxPayEntity wxPayEntity = new WxPayEntity();String ip = WebUtils.getIp();BigDecimal bigDecimal = new BigDecimal(entity.getMoney());int i = bigDecimal.multiply(new BigDecimal(100)).intValue();wxPayEntity.setTotalMoney(String.valueOf(i));wxPayEntity.setOrderId(entity.getOrderId());wxPayEntity.setIp(ip);wxPayEntity.setBody(entity.getBody());//微信支付ResultMap resultMap = wxPayService.unifiedOrder(wxPayEntity);PayEntity payEntity = new PayEntity();payEntity.setOrderId(entity.getOrderId());payEntity.setResultMap(resultMap);apiResponse.setData(payEntity);apiResponse.setCode(Integer.parseInt(resultMap.get("code").toString()));apiResponse.setMessage(resultMap.get("msg").toString());return apiResponse;}throw BaseException.of(2000, "下单失败");}@ApiOperation(value = "统一查询订单接口")@PostMapping("/queryPay")public QueryPayResult queryPay(@RequestBody QueryPayEntity entity) throws Exception {if (entity.getOrderId() == null || entity.getChannel() == null) {throw BaseException.of(2000, "请输入参数");}log.info("query pay : {}", entity);QueryPayResult payResult = new QueryPayResult();if (entity.getChannel() == OrderConstants.PAY_CHANNEL_WX) {//微信Map map = wxPayService.queryPay(entity);log.info("weixin : {}", map);String trade_state = map.get("result_code").toString();if (FAIL.equals(trade_state)) {return payResult;}if (SUCCESS.equals(map.get("trade_state").toString())) {payResult.setStatus(true);}} else if (entity.getChannel() == OrderConstants.PAY_CHANNEL_ZFB) {//支付宝AlipayResponse response = aliPayService.queryPay(entity);log.info("alipay : {}", response);if (response.isSuccess()) {payResult.setStatus(true);}}return payResult;}@ApiOperation(value = "统一H5查询串接口")@PostMapping("/queryOrderId")public String queryPay(@RequestBody AliPayEntityVo entity) {String s = cacheService.get(key + entity.getOrderId(), String.class);log.info(s + "====" + entity.getOrderId());if (StringUtils.isEmpty(s)) {throw BaseException.of(2000, "订单失效,请重新下单!");}return s;}@PostMapping("/refund")@ApiOperation(value = "支付宝退款", notes = "退款")public String refund(@RequestParam String orderNo, @RequestParam String amount) throws AlipayApiException {return aliPayService.refund(orderNo, amount);}@Autowiredprivate WXPayConfig wxPayConfig;@ApiOperation(value = "微信退款", notes = "退款")@PostMapping("/wxRefund")public boolean wxRefund(@RequestParam String orderNo, @RequestParam String amount) throws Exception {Map<String, String> data = new HashMap<String, String>();System.err.println("进入微信退款申请");Date now = new Date();SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmss");//可以方便地修改日期格式String hehe = dateFormat.format(now);int pay = (int) (Double.parseDouble(amount) * 100); //需要*100String out_refund_no = hehe + "wxrefund";//String transaction_id = "微信支付时生成的流水号";//String total_fee = "微信支付时支付的钱(单位为分)";data.put("out_refund_no", out_refund_no);data.put("out_trade_no", orderNo);data.put("total_fee", String.valueOf(pay));data.put("refund_fee", String.valueOf(pay));WXPay wxpay = new WXPay(wxPayConfig);data.put("appid", wxPayConfig.getAppID());data.put("mch_id", wxPayConfig.getMchID());data.put("nonce_str", WXPayUtil.generateNonceStr());data.put("sign", MD5Util.getSign(data));Map<String, String> resp = null;try {resp = wxpay.refund(data);} catch (Exception e) {e.printStackTrace();}System.err.println("返回信息:\n" + resp);String return_code = resp.get("return_code"); //返回状态码String return_msg = resp.get("return_msg"); //返回信息String resultReturn = null;if ("SUCCESS".equals(return_code)) {String result_code = resp.get("result_code"); //业务结果String err_code_des = resp.get("err_code_des"); //错误代码描述if ("SUCCESS".equals(result_code)) {//表示退款申请接受成功,结果通过退款查询接口查询//修改用户订单状态为退款申请中(暂时未写)resultReturn = "退款申请成功";System.out.println(resultReturn);return true;} else {log.info("订单号:{}错误信息:{}", err_code_des);resultReturn = err_code_des;return false;}} else {log.info("订单号:{}错误信息:{}", return_msg);resultReturn = return_msg;return false;}}}
苹果内购、支付宝微信app支付H5支付、退款相关推荐
- iOS内购(IAP,In App Purchases-在APP内部支付),设置及使用
项目中使用到了中间货币(金币)的形式来进行功能使用,模式是使用RMB换成-金币比如:(1RMB = 10金币),所以会集成第三方的支付平台,使用了微信和支付宝的第三方平台过后,发现审核失败,被苹果拒绝 ...
- 记录一次内购+支付宝/微信支付的上架被拒经历
第一.二次被拒 1.Guideline 2.3.1 - PerformanceWe discovered that your app contains hidden features. Attempt ...
- Springboot 对接苹果内购代码
Springboot 对接苹果内购代码 苹果内购和微信.支付宝支付流程有所不同,微信和支付宝都是通过各自的统一下单接口,拿到客户端所要的参数,之后返回给客户端,客户端支付完成进行回调并进行业务操作,而 ...
- 虚拟产品之苹果内购支付/支付宝支付/微信支付的区别
1.支付宝支付: 同步通知,异步业务逻辑处理. 直接配置异步请求接口. 2.微信支付: 同步通知,异步业务逻辑处理. 直接配置异步请求接口. 3.苹果内购支付: 同步通知,同步业务逻辑处理. 需要io ...
- 苹果内购验证(熟称苹果支付回调)java版
简介: 苹果支付是直接由ios客户端调起苹果支付并支付完成后,java后台提供一个支付回调接口供ios客户端进行同步回调,只需要在该接口进行进行验证苹果支付是否支付成功,跟微信支付和支付宝支付不一样, ...
- 【iOS内购支付】Uniapp拉起苹果内购支付注意事项、实现步骤以及踩过的坑(手把手教程)
前言 Hello!又是很长时间没有写博客了,因为最近又开始从事新项目,也是第一次接触关于uniapp开发原生IOS应用的项目,在这里做一些关于我在项目中使用苹果内购支付所实现的方式以及要注意的事项,希 ...
- Java支付--苹果内购
一.苹果支付 ①逻辑流程图 二.苹果支付流程介绍 ①用户购买产品下发支付请求到app端; ②app端收到请求后调用苹果服务进行支付扣款; ③苹果服务扣款成功后返回receipt_data加密数据和支付 ...
- uni app ios 苹果内购
app ios 苹果内购 的步骤 1,准备工作先要uniapp 开发ios 内购需要准备的沙盒 测试账号,在苹果手机登录沙盒账号 也就是把自己的Apple ID退出登录沙盒账号,manifest.js ...
- 丁香医生APP被App Store拒绝更新:违反苹果内购系统规定
5月25日消息,苹果App Store以其构建戒备森严的生态圈,在安全系数上比其他应用商城要高出不少.苹果也因这个封闭生态,躺着赚了不少钱. 这因为苹果要求登陆App Store的APP,都要经过苹果 ...
最新文章
- latex调整caption图表标题行间距、字体大小、左对齐
- python实现快排算法_Python实现快速排序算法
- java返回泛型_Java泛型从泛型方法返回持有者对象
- 查看oracle中各个表空间的已使用空间和最大分配空间
- Ruby On Rails --环境搭建之回眸一笑
- Vue中Object和Array数据变化侦测原理
- 社群商业模式设计方案
- MySQL Innodb引擎和MyIASM引擎的区别
- vue 第五天 (事件监听基础)
- 面试官:这货一听就是一个水货...
- CSDN积分赚取方法
- IOT [01] -- 物联网平台架构
- linux系统的日历如何改,linux下实现农历的日历
- 单点登录系统和传统登录的区别
- 【BZOJ3162】独钓寒江雪(树哈希,动态规划)
- 由C注释向C++注释转换简单实现
- 美国人在世界各地随意干扰别国内政,发动战争,你认为这样做得对吗?
- hp服务器不显示错误代码,惠普服务器开启不了
- AutoDL论文解读(五):可微分方法的NAS
- 威眼局域网监控软件3.7.2发布
热门文章
- configure: error: Curl library not found
- 【移动端网页布局】移动端网页布局基础概念 ⑤ ( 视网膜屏技术 | 二倍图概念 | 代码示例 )
- 2018dnf服务器维护时间,dnf2018年5月电脑管家活动_2018dnf5月电脑管家活动网址_快吧游戏...
- Blender花季老将,16岁赢得全网最强渲染大赛国际组冠军,分享创作全过程
- systemctl disable firewalld Failed to disable unit: Access denied
- 用树莓派 + aria2 做一个下载机
- OpenCV中Mat 与 imshow
- Gluten 首次开源技术沙龙成功举办,更多新能力值得期待
- WebService接口登录验证代码生成调用
- 淘宝如何发布源码和模板