Home php教程 PHP源码 thinkPHP和onethink微支付插件

thinkPHP和onethink微支付插件

May 23, 2016 pm 04:33 PM

这篇文章主要为大家详细介绍了Thinkphp和onethink实现微信支付插件,感兴趣的小伙伴们可以参考一下

thinkPHP和微支付实现的微信支付插件,在微信中调用微信jssdk实现支付,这里有详细的代码和教程,具体看这里:

 //实现的Wxpay钩子方法
        public function Wxpay($param){
            require './Addons/Wxpay/WxPayPubHelper/WxPayPubHelper.php';
            $jsApi = new \JsApi_pub(); 
            
            //=========步骤1:网页授权获取用户openid============
            if (!isset($_GET['code']))
            {
                //触发微信返回code码
                $url = $jsApi->createOauthUrlForCode(\WxPayConf_pub::JS_API_CALL_URL.'/order_id/'.$param['order_id']);
                Header("Location: $url");
            }else
            {
                $order_id = $param['order_id'];
                $info = M('Order')->where('id='.$order_id)->find();
                if(empty($info) || $info['is_pay'] == 1){
                    dump('该订单不存在或已支付'.$order_id);
                    exit();
                }
                $this->assign('info', $info);
                $a = $info['money'];
                $b = 100;
                $c = $a * $b;
                
                //获取code码,以获取openid
                $code = $_GET['code'];
                $jsApi->setCode($code);
                $openid = $jsApi->getOpenId();
            }
             
            //=========步骤2:使用统一支付接口,获取prepay_id============
            //使用统一支付接口
            $unifiedOrder = new \UnifiedOrder_pub();
             
            $unifiedOrder->setParameter("openid","$openid");//商品描述
            $unifiedOrder->setParameter("body","在线预订");//商品描述
            //自定义订单号,此处仅作举例
            $timeStamp = time();
//             $out_trade_no = \WxPayConf_pub::APPID."$timeStamp";
            $out_trade_no = $info['ordersn'];
            $unifiedOrder->setParameter("out_trade_no", "$out_trade_no");//商户订单号
            $unifiedOrder->setParameter("total_fee", "$c");//总金额
            $unifiedOrder->setParameter("notify_url",\WxPayConf_pub::NOTIFY_URL.'/order_id/'.$param['order_id']);//通知地址
            $unifiedOrder->setParameter("trade_type","JSAPI");//交易类型
             
            $prepay_id = $unifiedOrder->getPrepayId();
            //=========步骤3:使用jsapi调起支付============
            $jsApi->setPrepayId($prepay_id);
            $jsApiParameters = $jsApi->getParameters();
            $this->assign('jsApiParameters', $jsApiParameters);

            $this->display('pay');
        }
Copy after login

                   

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Roblox: Bubble Gum Simulator Infinity - How To Get And Use Royal Keys
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Nordhold: Fusion System, Explained
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1664
14
PHP Tutorial
1268
29
C# Tutorial
1248
24