当前位置: 首页 > news >正文

良匠网站建设网站建设方案书 备案

良匠网站建设,网站建设方案书 备案,软件开发公司介绍怎么写,苏州建设是哪家公司一、支付宝开放平台设置 注册支付宝支付功能需要个体工商户或企业才可以!需要有营业执照才能去申请哦! 1、登录到控制台 进入支付宝开放平台 控制台 2、开发设置 3、产品绑定APP支付 如果没有绑定APP支付就会报商家订单参数异常,请重新发起…

一、支付宝开放平台设置

注册支付宝支付功能需要个体工商户或企业才可以!需要有营业执照才能去申请哦!

1、登录到控制台

进入支付宝开放平台 控制台

在这里插入图片描述

2、开发设置

在这里插入图片描述

3、产品绑定APP支付

如果没有绑定APP支付就会报商家订单参数异常,请重新发起支付的错误

在这里插入图片描述

二、Springboot后端代码

1、pom.xml中导入两个包

在这里插入图片描述

<!-- 支付宝官方 SDK-->
<dependency><groupId>com.alipay.sdk</groupId><artifactId>alipay-sdk-java</artifactId><version>4.22.32.ALL</version>
</dependency>
<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-configuration-processor</artifactId><optional>true</optional>
</dependency>

2、application.yml中添加以下配置

在这里插入图片描述

# 支付宝支付
alipay:server_url: https://openapi.alipay.com/gateway.doapp_id: 你的APPIDprivate_key: 应用私钥format: jsoncharset: utf-8alipay_public_key: 支付宝公钥sign_type: RSA2notifyUrl: 回调地址

在这里插入图片描述

3、新建AlipayConfig类和BizAlipayService类

在这里插入图片描述
AlipayConfig类代码

import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;@Getter
@Setter
@ToString
@Component
@ConfigurationProperties(prefix = "alipay")
public class AlipayConfig extends com.alipay.api.AlipayConfig {private String serverUrl;private String appId;private String privateKey;private String format;private String charset;private String alipayPublicKey;private String signType;private String notifyUrl;
}

在这里插入图片描述
BizAlipayService类代码

import com.alipay.api.AlipayApiException;
import com.alipay.api.DefaultAlipayClient;
import com.alipay.api.domain.AlipayTradeAppPayModel;
import com.alipay.api.request.AlipayTradeAppPayRequest;
import com.alipay.api.response.AlipayTradeAppPayResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;/*** 阿里云支付类*/
@Service
public class BizAlipayService {private static Logger logger = LoggerFactory.getLogger(BizAlipayService.class);@AutowiredAlipayConfig alipayConfig;private DefaultAlipayClient client() throws AlipayApiException {return new DefaultAlipayClient(alipayConfig);}/*** 预下单** @param subject     订单标题* @param outTradeNo  商家生成的订单号* @param totalAmount 订单总价值* @return*/public String appPay(String subject, String outTradeNo, String totalAmount) {String source = "";try {DefaultAlipayClient client = client();AlipayTradeAppPayModel model = new AlipayTradeAppPayModel();model.setSubject(subject);model.setOutTradeNo(outTradeNo);model.setTotalAmount(totalAmount);// alipay 封装的接口调用AlipayTradeAppPayRequest request = new AlipayTradeAppPayRequest();request.setBizModel(model);request.setNotifyUrl(alipayConfig.getNotifyUrl());AlipayTradeAppPayResponse response = client.sdkExecute(request);source = response.getBody();} catch (AlipayApiException e) {logger.error("支付出现问题,详情:{}", e.getErrMsg());e.printStackTrace();}return source;}
}

4、编写接口支付接口和回调接口

在这里插入图片描述

接口代码

@RestController
@CrossOrigin    // @CrossOrigin注解 解决uniapp跨域访问后端问题。
@RequestMapping("/productOrder")
public class UniProductOrderController {@Autowiredprivate AlipayConfig alipayConfig;@Autowiredprivate BizAlipayService alipayService;/*** 发起支付** @return*/@GetMapping("/pay")public Object pay() {System.out.println("正在测试支付宝支付···");String s = alipayService.appPay("测试支付", String.valueOf(System.currentTimeMillis()), new BigDecimal("0.01").toString());System.out.println(s);return s;}/*** 订单回调** @return*/@RequestMapping(method = RequestMethod.POST, value = "/notify")public String orderNotify(HttpServletRequest request) {Map<String, String> params = new HashMap<>();Map<String, String[]> requestParams = request.getParameterMap();for (String name : requestParams.keySet()) {String[] values = requestParams.get(name);String valueStr = "";for (int i = 0; i < values.length; i++) {valueStr = (i == values.length - 1) ? valueStr + values[i] : valueStr + values[i] + ",";}params.put(name, valueStr);}try {boolean flag = AlipaySignature.rsaCheckV1(params, alipayConfig.getAlipayPublicKey(), alipayConfig.getCharset(), alipayConfig.getSignType());if (flag) {System.out.println("支付回调信息:"+ params);return "success";} else {return "error";}} catch (AlipayApiException e) {System.out.println("支付宝错误回调:"+e.getErrMsg());e.printStackTrace();return "error";}}
}

三、UniApp前端代码

1、配置manifest.json的App模块开启支付

在这里插入图片描述

2、编写uni.request请求

在这里插入图片描述
代码

//发起支付
pay(){let that = thisuni.request({url: getApp().globalData.myurl + "/productOrder/pay",data:{},method: 'GET',dataType: 'json',header: {'content-type': 'application/x-www-form-urlencoded'},success(res) {console.log(res);uni.requestPayment({provider: 'alipay',orderInfo: res.data,success(r) {uni.showToast({title:"支付成功",icon: "success"})},fail(e) {uni.showToast({title:"用户取消支付",icon: "error"})},complete: () => {console.log("payment结束")}})}})
},

四、支付功能展示

1、用户确认支付

在这里插入图片描述

2、用户取消支付

在这里插入图片描述

五、退款功能

1、支付成功回调返回结果

在这里插入图片描述

返回结果:

在这里插入图片描述
返回结果里面的trade_no 一会退款需要用到这个!

2、在刚才的BizAlipayService.类中添加以下代码

在这里插入图片描述

代码

/*** 退款** @param tradeNo* @param totalAmount* @return*/
public AlipayTradeRefundResponse refund(String tradeNo, String totalAmount) {try {DefaultAlipayClient client = client();AlipayTradeRefundModel alipayTradeRefundModel = new AlipayTradeRefundModel();alipayTradeRefundModel.setTradeNo(tradeNo);alipayTradeRefundModel.setRefundAmount(totalAmount);AlipayTradeRefundRequest request = new AlipayTradeRefundRequest();request.setBizModel(alipayTradeRefundModel);AlipayTradeRefundResponse response = client.execute(request);return response;} catch (AlipayApiException e) {logger.error("退款出现问题,详情:{}", e.getErrMsg());e.printStackTrace();}return null;
}

3、在接口中添加退款接口

在这里插入图片描述

代码

/*** 订单退款** @return* @TODO 仅实现了全部退款*/
@RequestMapping(value = "/orderRefund", method = RequestMethod.GET)
public AlipayTradeRefundResponse orderRefund() {AlipayTradeRefundResponse refund = alipayService.refund("2022020922001434041429269213", "0.01");return refund;
}

六、支付成功后支付宝异步多次回调问题

  • 当订单的状态发生改变后,支付宝通常会以异步的方式通知商家服务器。
  • 商家服务器需要返回success这 7 个字符,如果不是,则支付宝则会不断重复通知商家服务器。

但是有时即使返回“success”,支付宝还是继续回发异步通知!!!

我们需要在本地加点验证来解决这个问题,根据当前订单编号去查他的状态,如果状态是0我们就去存储,如果状态是1了则不存!




本文仅供学习使用,本文参考博客园作者奔跑的砖头的文章感谢作者的详细说明以及代码 (*╯3╰) (*╯3╰) (*╯3╰)

http://www.yayakq.cn/news/908041/

相关文章:

  • 网站上的用户注册怎么做的怎么做购物车网站
  • 品牌网站建设重點大蝌蚪用extjs做的网站
  • 互联网网站解决方案网站都需要备案吗
  • 工信部网站原来是无版权视频素材网站
  • 汶上县建设局官方网站软件工程师c语言面试题
  • 建立网站后怎么维护wordpress phpstudy
  • 好看的网站排版怎样建立营销网站
  • 手机网站修改做网站怎么切片
  • 可视化网站设计工具东莞网络建设
  • 水头做网站的公司开发平台指的是什么
  • 网站改版说明沧州网站制作报价
  • dedecms 网站首页标签千锋培训机构官网
  • 个人网站建设简历低学历吃香的十大职业
  • 网站做百度竞价利于百度优化公司简介ppt模板素材
  • 网站建设中销售人员会问客户的问题潍坊制作网站公司
  • 郑州高端网站定制公共信息服务平台官网
  • 网站的黄金看盘软件网站服务器怎么收费
  • 网站首页适配规则成都 网站建设 app 开发
  • 免费建网站哪个模板多一个简单网页的代码
  • 电子商务网站建设与管理感想和收获免费网站建站排行榜
  • 必须在当地网站备案东莞视频网站制作
  • 建站模板 discuz游戏网站怎么做seo
  • 金山做网站建站时候源码有验证怎么办
  • 百度seo优化排名软件网站优化优化怎么做
  • 黄圃网站建设中高风险区域最新名单
  • 做设计在哪个网站上找高清图片岳阳建设局网站
  • 网站建站的尺寸seo诊断书案例
  • 网站一级域名和二级域名wordpress会员制
  • 龙岗网站建设哪家便宜深圳交易服务中心官网
  • j动态加载网站开发温州网站开发