当前位置:网站首页>微信实现扫码支付(native)
微信实现扫码支付(native)
2022-08-09 13:07:00 【Richard678】
准备
在微信支付官网下载SDK(Software Development Kit):https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=11_1
目录
一、生成付款码
native模式(扫码支付)只需要配置APPID、MCHID、KEY,这3个在【微信支付】官网里面都能找到,配置好这三个就能生成二维码
第一步:在sdk的example的WxPay.Config.php配置
1、APPID:绑定支付的APPID(必须配置,开户邮件中可查看)
2、MCHID:商户号(必须配置,开户邮件中可查看)
3、KEY:商户支付密钥,参考开户邮件设置(必须配置,登录商户平台自行设置)
4、APPSECRET:公众帐号secert(仅JSAPI支付的时候需要配置, 登录公众平台,进入开发者中心可设置)
第二步:认识native.php文件
native.php接收页面传过来的数据


//生成直接支付的url,支付url有效期2个小时
$notify = new NativePay();
//统一下单输入对象
$input = new WxPayUnifiedOrder();
//商品的名称
$input->SetBody("test");
$input->SetAttach("test");
//订单号
$input->SetOut_trade_no("sdkphp123456789".date("YmdHis"));
//金额
$input->SetTotal_fee("1");
//开始时间
$input->SetTime_start(date("YmdHis"));
//有效期
$input->SetTime_expire(date("YmdHis", time() + 600));
$input->SetGoods_tag("test");
//微信回调返回信息的地址
$input->SetNotify_url("http://paysdk.weixin.qq.com/notify.php");
//支付类型
$input->SetTrade_type("NATIVE");
//产品内部的id
$input->SetProduct_id("123456789");
//进行测试
var_dump($input);
$result = $notify->GetPayUrl($input);
$url2 = $result["code_url"];
二、付款生成订单
新生成的订单送到数据库里面

往数据库里面进行插入

三、处理回调信息
//微信回调返回信息的地址
$input->SetNotify_url("http://paysdk.weixin.qq.com/notify.php");
上面代表回调信息处理的地方
对notify.php文件的NotifyProcess类的 【3、处理业务逻辑】进行处理,其他地方已经被官方被封装好了的
将微信平台返回来的transaction_id字段的信息,写到数据库里面

四、支付完成后完成的跳转
支付成功需要进行页面跳转,不然网站页面一直停留在二维码这个页面
1、在native.php页面添加
![]()

2、新建一个页面

五、订单号查询
直接选用example里面的orderquery.php这个页面就能实现订单查询

六、微信支付关闭订单
微信官网API:https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_3
用官方的orderquery.php改造为orderclose.php,改造后的界面

七、微信支付退款
注意:退款需要安装证书,证书下载地址:在商户微信支付官网的API安全里面下载
1、得到【WxCertUtil.exe】里面的【微信支付商户平台证书工具.exe】
2、复制【请求字符串】到【商户微信支付官网的API安全】得到【证书串】
3、将【证书串】粘贴到【微信支付商户平台证书工具】得到【证书】
将得到证书重命名【cert】放到项目的与exmple目录同级
从哪里来退到哪里去
边栏推荐
- FFmpeg多媒体文件处理(ffmpeg处理流数据的基本概念)
- NFS pays special attention to the problem of permissions
- 周末看点回顾|我国IPv6网络全面建成;2022昇腾AI开发者创享日·南京站成功举办…
- GIN文件上传与返回
- 01_iTween_第一天--小球抛物线
- An Offer 21. Adjust the array in order to make odd in even the front (loop invariant)
- NC53 删除链表的倒数第n个节点
- Record the system calls and C library functions used in this project-2
- The FPGA - work summary recently
- NC15 求二叉树的层序遍历
猜你喜欢

Uni - app - uview Swiper shuffling figure component, click on the links to jump (click to get the item after the row data, remove data operation)

面试攻略系列(三)-- 高级开发工程师面试问些啥?

GIN a preliminary study, the environment is installed

FFmpeg多媒体文件处理(ffmpeg操作目录及list的实现)

render解析

蓝桥历届真题-跑步锻炼

RTSP协议讲解

Periodic sharing of Alibaba Da Tao system model governance

FFmpeg相机花屏花图问题解决方法

eslint语法规则报错
随机推荐
kustomize entry example and basic syntax instructions
error Trailing spaces not allowed no-trailing-spaces 9:14 error Unexpected trailing comma
Time series analysis course lab report
Anta and Huawei Sports Health jointly verify the champion running shoes and lead Chinese sports with innovation
现在40系显卡都快出来了,为何1060型号的显卡还有这么多人用?
Q_04_06 把它放在一起:传送
面试攻略系列(二)-- 秒杀系统
Come and throw eggs.
【NVIDIA】Tesla V100安装NVIDIA-Driver驱动程序适配CUDA-Toolkit-11.6
GIN file upload and return
Q_04_07 进一步探索
音视频录入的pts和dts问题
19、学习MySQL 索引
read stream special attention
力扣解法汇总1413-逐步求和得到正数的最小值
DCT变换与反变换
Periodic sharing of Alibaba Da Tao system model governance
NC192 二叉树的后序遍历
问题系列-如何修改或更新localhost里的值
GIN中GET POST PUT DELETE请求