首页 > 微信 > 详细

关于微信扫码支付的流程

时间:2019-01-15 11:28:52      阅读:274      评论:0      收藏:0      [点我收藏+]

前言:由于没有商户相关的id信息,只能测试这个扫码的功能,但是这个也是我们日常常用到的功能

 

(一) 前期准备

  从微信官方网站下载最新的支付的接口

  1.首先在:https://pay.weixin.qq.com/wiki/doc/api/native_sl.php?chapter=11_1  平台下载第三方接口文件(我下载的是PHP)

  2.把项目放到入口文件中去查看效果(如下)

技术分享图片

  3.点击扫码支付(注意路径问题)

技术分享图片

这是模式二无法显示图片,但是其实也是不影响我们项目的运行的

(二) 集成到我的项目中去

  1.运行会报两个错误

    WxPay.NativePay.php文件报第9行和11行的错误  解决方法是注释第九行文件内容

    WxPay.Config.php文件报第9行错误  解决方法是注释第九行文件内容

  

//到了这里此时订单的相关信息已经完成了
<?php

$notify = new \NativePay();
$input = new \WxPayUnifiedOrder();
$input->SetBody($order->order_name);//商品描述
$input->SetAttach($order->order_name);//附加数据
$input->SetOut_trade_no($order->order_number);
$input->SetTotal_fee($order->price * 100);//微信的单位是分主要为浮点数精度不丢失到了微信那里会转换
$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");
$input->SetProduct_id("123456789");
$result = $notify->GetPayUrl($input);
$url2 = $result["code_url"];
//下面主要是显示二维码 
require_once ‘../example/phpqrcode/phpqrcode.php‘;//引入二维码所在的文件位置
if(substr($url,0,6) == ‘weixin‘){
ob_end_clean();
header(‘Content-Type:image/png‘);
\QRcode::png($url);
}else{
header(‘HTTP/1.1 404 Not Found‘);
}

<?php
//通过弹出层显示二维码,这个操作主要是用户点击了微信支付按钮弹出支付的二维码
public function getqrcode($url2){
        $url = base64_decode($url2);
        require_once ‘../wxpay/example/phpqrcode/phpqrcode.php‘;
        if(substr($url,0,6) == ‘weixin‘){
            ob_end_clean();
            header(‘Content-Type:image/png‘);
            \QRcode::png($url);
        }else{
            header(‘HTTP/1.1 404 Not Found‘);
        }
    }

 

  

<?php
 //怎样知道用户是否支付了,主要是在前端弹出用一个定时器不断请求后台的查询得到的结果
public function wxquery(Order $order){
        require_once "../wxpay/lib/WxPay.Api.php";
        require_once "../wxpay/example/WxPay.Config.php";
        //查询订单是否支付了
        $out_trade_no = $order->order_number;//拿到用户支付的订单号
        $input = new \WxPayOrderQuery();
        $input->SetOut_trade_no($out_trade_no);//把用户订单放到订单中查询
        $config = new \WxPayConfig();
        $res = \WxPayApi::orderQuery($config,$input);//查询订单支付情况
        if($res[‘result_code‘] ==‘SUCCESS‘ && $res[‘trade_state‘] == ‘SUCCESS‘ && $res[‘trade_state_desc‘] == ‘支付成功‘)//判断是否成功return [‘status‘=> true,‘message‘=>‘支付成功‘];
        }
        return [‘status‘=> false,‘message‘=>‘服务器繁忙请稍后-----‘];
    }

 

关于微信扫码支付的流程

原文:https://www.cnblogs.com/learningPHP-students2018/p/10270723.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!