Java支付功能实现

导入依赖

<dependency><groupId>com.alipay.sdk</groupId><artifactId>alipay-sdk-java</artifactId>
</dependency>
<dependency><groupId>cn.hutool</groupId><artifactId>hutool-all</artifactId><version>5.5.8</version>
</dependency>

生成qrCode

@PostMapping("/show")@ApiOperation(value = "添加支付订单", notes = "支付订单添加")public String qrCode(@RequestBody @Validated TradeDTO tradeDTO, BindingResult result) throws AlipayApiException{if (result.hasErrors()) {throw new BindingResultException(result);}AlipayClient alipayClient = new DefaultAlipayClient("https://openapi.alipay.com/gateway.do","2021003108655493","应用私钥","json","UTF-8","应用共钥","RSA2");AlipayTradePrecreateRequest request = new AlipayTradePrecreateRequest();request.setNotifyUrl("");JSONObject bizContent = new JSONObject();bizContent.put("out_trade_no", tradeDTO.getOutTradeNo());bizContent.put("total_amount", tradeDTO.getTotalAmount());bizContent.put("subject", tradeDTO.getSubject());request.setBizContent(bizContent.toString());AlipayTradePrecreateResponse response = alipayClient.execute(request);if(response.isSuccess()){return  response.getBody();} else {throw new BusinessException(ResultCode.ADD_ACCOUNT.getCode(), "二维码生成失败失败");}}

检查是否存在

下载支付宝开放平台开发助手

@GetMapping("/pay/{id}")@ApiOperation(value = "查询支付订单", notes = "支付订单查询")
public String PayCheck(String id) throws AlipayApiException {//获得初始化的AlipayClientAlipayClient alipayClient = new DefaultAlipayClient("https://openapi.alipay.com/gateway.do", "2021003108655493", "应用私钥", "json", "UTF-8", "支付宝共钥", "RSA2");//创建API对应的request类AlipayTradeQueryRequest request = new AlipayTradeQueryRequest();request.setBizContent("{" +"\"out_trade_no\":\""+id+"\"}");  //设置业务参数//通过alipayClient调用API,获得对应的response类AlipayTradeQueryResponse response = alipayClient.execute(request);return response.getBody();}

添加订单接口

@PostMapping("/add")@ApiOperation(value = "添加支付订单", notes = "支付订单添加")
public Result addTrade(Trade trade, BindingResult result) {if (result.hasErrors()) {throw new BindingResultException(result);}boolean save=tradeRepository.save(trade);if (save) {return Result.ok().message("支付订单添加");} else {throw new BusinessException(ResultCode.ORDER_ADD);}}

前端Vue

安装qrcodejs2

npm install qrcodejs2 --save
<el-button class="btn" type="text" @click="dialogVisible = true">立即支付</el-button>
<el-dialogtitle="支付":visible.sync="dialogVisible"width="30%"><div style="margin-left: 150px" id="code"></div><span slot="footer" class="dialog-footer"><el-button @click.once="getQRCode">生成二维码</el-button><el-button type="success" @click="testSuccess">检查成功</el-button></span></el-dialog>
import QRCode from 'qrcodejs2'
data() {return {successInfo: {},dialogVisible: false,TradeForm: {//订单编号outTradeNo: undefined,//价格totalAmount: undefined,//订单名称subject: undefined},payForm: {id: undefined,houseId: undefined,houseName: undefined,userId: undefined,userPhone: undefined,leaseTerm: undefined,price: undefined,touristId: undefined,touristName: undefined,touristPhone: undefined}}}

参考QRCode.js:使用 JavaScript 生成二维码 | 菜鸟教程 (runoob.com)

getQRCode() {let qr;this.TradeForm.outTradeNo = this.getProjectNum();console.log(this.TradeForm.outTradeNo)this.TradeForm.totalAmount = this.orderInfo();this.TradeForm.subject = this.describeInfo();qrCode(this.TradeForm).then(response => {this.page = response;qr = new QRCode("code", {text: this.page.alipay_trade_precreate_response.qr_code,width: 128,height: 128,colorDark: "#000000",colorLight: "#ffffff",correctLevel: QRCode.CorrectLevel.H});})},

检测成功

testSuccess() {console.log(this.TradeForm.outTradeNo)payCheck(this.TradeForm.outTradeNo).then(response => {this.successInfo = response;console.log(this.successInfo)if (this.successInfo.alipay_trade_query_response.code == 10000) {this.payForm.id = this.TradeForm.outTradeNo;this.payForm.houseId=this.oInfo().id;this.payForm.houseName=this.oInfo().address+this.oInfo().addressInfo;this.payForm.userId=this.oInfo().userId;this.payForm.userPhone=this.oInfo().phoneNumber;this.payForm.leaseTerm=this.oInfo().leaseTerm;this.payForm.price=this.oInfo().price;this.payForm.touristId=this.loginInfo().id;this.payForm.touristName=this.loginInfo().username;this.payForm.touristPhone=this.loginInfo().phone;addTrade(this.payForm).then(response => {if(response.code===200){clearOrder(this.payForm.touristId).then(response => {if(response.code===200) {leaseHouseInfo(this.payForm.houseId).then(response => {if(response.code===200) {this.$router.push({path:'/paysuccess'})}else {this.$notify({title: '警告',message: response.message,type: 'warning'});}})}else {this.$notify({title: '警告',message: response.message,type: 'warning'});}})}else {this.$notify({title: '警告',message: response.message,type: 'warning'});}})} else {this.$notify({title: '警告',message: '交易不存在,请重新交易',type: 'warning'});}})}

Java支付功能实现相关推荐

  1. java在线支付---01_在线支付功能的演示与概述

    2013/5/30 ----------------- 01_在线支付功能的演示与概述 Java技术qq交流群:JavaDream:251572072 ------------------------ ...

  2. Stripe 银行卡支付功能初步指南(Java)

    Stripe 国外银行卡支付功能指南(Java) 简介 编写这篇文章的目的就是~~没有什么目的.网上关于stripe银行卡支付代码很多,有写得很好的,但是太多太杂了,不系统.所以我就结合项目中实际应用 ...

  3. Java开发对接招行一网通支付功能的总结

    招商银行一网通支付JAVA开发 最近对接了招行一网通的支付功能,记录一下. 一.一网通支付方式主要分为6种:APP支付,H5支付,PC扫码支付,二维码支付,小程序支付,Apple Pay支付.本次开发 ...

  4. 聊一聊Java如何接入招行一网通支付功能

    1.前提条件 相比较于支付宝和微信的支付功能接入这一块,银行相对来说更加严格,比如说支付宝,在你签约之前可以进行一些测试.但是银行来说就不是这样了,如果您现在要进行招行的支付功能开发的话,请务必先让相 ...

  5. 微信小程序-JAVA实现微信支付功能(微信支付2.0)

    微信小程序-JAVA实现微信支付功能(微信支付2.0) 一.前言 本博客主要介绍JAVA后台与微信小程序(UNI-APP或者原生微信小程序)的微信支付的实现,如果是APP或者H5的开发暂时不支持,具体 ...

  6. 非智能手机斗破苍穹Java_支付宝推JAVA版 非智能手机增支付功能

    泡泡网手机频道6月16日 日前,支付宝与曜硕科技联合发布国内首个非智能手机支付方案--嵌入式安全支付系统解决方案.通过该方案,非智能型手机将拥有手机支付功能,从而可以让用户的手机新增网购.游戏及话费充 ...

  7. java对接支付宝实现支付功能

    ** java对接支付宝实现支付功能 ** Controller /*** 支付功能* @return*/ @RequestMapping("/test") public Mode ...

  8. 哈哈!没想到吧!Java也可以 实现微信和支付宝支付功能(附代码)

    一.前期准备 1.申请好微信商户号appid,拿到商户id和商户秘钥,退款的话需要商户证书 2.申请好支付宝商户号appid,商户公钥和秘钥(需要用支付宝工具自己生成),支付宝退款不需要证书 二.数据 ...

  9. AndroidSDK结合SpringBoot实现支付宝支付功能

    开发者注册: 1. 创建应用,获取AppID:开发者可在沙箱中完成. 沙箱应用网址:https://openhome.alipay.com/platform/appDaily.htm 2. 在支付宝助 ...

最新文章

  1. 8)排序④排序算法之归并排序
  2. In terms of 的用法总结
  3. 常见字符串拼接性能比较
  4. 用sqlplus为oracle创建用户和表空间
  5. linux系统串口设置参数,linux 串口编程记录(一)串口参数设置(示例代码)
  6. mysql 跳过一个事物_MYSQL GTID跳过指定事务
  7. linux的O的字体让我满意那些
  8. 固定td 样式 随 内容 溢出
  9. 百度地图API基本使用(二)
  10. 外盘琪貨正大国际:别放弃勤奋,再难,别丢掉善良
  11. vector函数总结
  12. 一张图告诉你三大运营商2G/3G/4G频率分配和网络制式
  13. egret eui.Scroller 怎么禁止左右或上下滑动
  14. 关于利用51单片机实现篮球记分牌功能的概述
  15. 组合Combination 分布数组计算
  16. 腾讯云轻量8核16G18M服务器带宽CPU流量性能测评
  17. 初窥MySQL的索引与事务
  18. 安装caffe依赖库时,出现“您希望继续执行吗? [Y/n] y 中止。”的解决办法
  19. 计算机基础_001_栈是什么
  20. 将字符串中的换行替换成空

热门文章

  1. 《520之前脱单》单身的兄弟们看这里教你如何快速找到女朋友并发生故事 当然是选动态规划呀 听说看完的人都脱单了
  2. oracle 覆盖 impdp,oracle的expdp/impdp的使用
  3. Nodecache CDN初体验,注册送1TB流量,有香港CDN节点!
  4. HTTP是不保存状态的协议,如何保存用户状态?
  5. 学习Python面向对象编程(廖雪峰老师的博客)
  6. 11月23日云栖精选夜读:阿里AI Labs王刚解读9小时卖出百万台的“天猫精灵” | 高山大学(GASA)
  7. backlog配置_redis的tcp-backlog配置
  8. 2022中国北京国际老龄产业博览会
  9. Blender 建模练习-锁链
  10. 【C语言】作业:统计字符串中元音字母a,e,i,o,u的个数并输出