Home php教程 php手册 TP combined with WeChat scan code payment mode 2

TP combined with WeChat scan code payment mode 2

Sep 23, 2016 am 03:29 AM

tp结合微信扫码支付模式二
首先引入微信下载的类,可以用我打包的,名称我修改了的
TP combined with WeChat scan code payment mode 2
把微信类放到thinkphp核心框架的Library\Vendor\下面
在微信类的Config.php 文件里面配置数据
TP combined with WeChat scan code payment mode 2
然后在要使用的模块中调用
TP combined with WeChat scan code payment mode 2
然后在获取支付二维码的方法中写
TP combined with WeChat scan code payment mode 2$money=1<br> $goodsid=time();<br> $order = time();<br> $notify = new \NativePay();<br> $input = new \WxPayUnifiedOrder(); //调用统一下单类<br> $input->SetBody($body);//这是商品标题<br> $input->SetAttach($body);<br> $input->SetOut_trade_no($goodsid);//这是单号<br> $input->SetTotal_fee($money*100);//这是金额,微信金额是按分计算,所以要   *100<br> //$input->SetTotal_fee("1");<br> $input->SetTime_start(date("YmdHis"));<br> $input->SetTime_expire(date("YmdHis", time() + 7200));<br> $input->SetNotify_url('http://'.$_SERVER['HTTP_HOST'].U('Member/notify'));<br> $input->SetTrade_type("NATIVE");<br> $input->SetProduct_id($goodsid);<br> $out_trade_no = $input->GetOut_trade_no();<br> $result = $notify->GetPayUrl($input);<br> $url = $result["code_url"];//这就是返回的二维码地址,要在前端生成二维码<br> $arr['out_trade_no']=$out_trade_no;<br> $arr['code_url']=$url;<br> $arr['order']=$order; 以下是生成二维码的jquery,先引入生成二维码的js,也可以用其他方法[js文件我会打包]
window.onload = function(){<br>     var c_url="<?php echo $arr[&#039;code_url&#039;];?>";<br>    qr_code(c_url);<br> };<br> //生成二维码<br> function qr_code(url,out_trade_no,order){<br>     if(url){<br>         //参数1表示图像大小,取值范围1-10;参数2表示质量,取值范围'L','M','Q','H'<br>         var qr = qrcode(10, 'M');<br>         qr.addData(url);<br>         qr.make();<br>         var code=document.createElement('DIV');<br>         code.innerHTML = qr.createImgTag();<br>         var element=document.getElementById("code_url");<br>         element.appendChild(code);    <br>     }    <br> }<br> //生成的二维码会出现在这里<br> <div></div>TP combined with WeChat scan code payment mode 2

Then it is judged whether the user has scanned the code to pay
I put an asynchronous code that queries every 3 seconds on the page where the QR code is generated$(function(){<br> setInterval(function(){check()}, 3000); //Execute ajax every three seconds<br> Function check(){<br>         var out_trade_no = $("#code_url").attr('out_trade_no');<br>       var order = $("#code_url").attr('order');<br>           $.ajax({<br>            type: "post",<br>    url: '{:U("Member/orderquery")}', //Request function<br> async: false,<br> Data: {'out_trade_no':out_trade_no,'order':order},<br> DataType: "json",<br> Success: function (data) {<br>                                                                                                                                                                                                                                              if (data.status) {<br> layer.msg(data.info,{btn:'OK'},function(){<br>                                                                                                                                                                                       Parent.location.reload();                                                                                                                                                                                 })<br>                                                                                                                                                                                                                                                                     }else{<br>                    result = false;<br>                  }<br>             }<br>          });<br> }<br> })<br>Here is the requested program code (the actions performed after successful payment can be modified according to your needs)<br>
//Check if payment is completedTP combined with WeChat scan code payment mode 2 Public function orderquery($out_trade_no=null, $orderid=null){         $out_trade_no = $_POST['out_trade_no'];<br>        $order = $_POST['order'];<br> If(isset($out_trade_no) && $out_trade_no != ""){<br>            $out_trade_no = $_REQUEST["out_trade_no"];<br>            $input = new WxPayOrderQuery();<br>               $input->SetOut_trade_no($out_trade_no);<br>            $result = WxPayApi::orderQuery($input);<br>        }<br>         $cash_fee=$result['cash_fee']/100;//Payment amount<br> /*Determine whether payment is successful*/<br>                                                                                                                                                                                                                                                                                                        if (               $data=array('goodsid'=>$result['out_trade_no'],'status'=>1,'pay_type'=>2);<br>                $cz=M('cz_records')->where($data)->find();<br>               if($cz){<br>if(M('cz_records')->where($data)->save(array('money'=>$cash_fee,'transaction_id'=>$result['transaction_id'],'status'= >2))){<br> if($this->set_money($cz['uid'],$cz['type'],C('date'),$cz['money'],$cz['transaction_id'])){ <br> $ This-& gt; success ('Successful payment:'. $ Cash_fee. 'Yuan'); <br>                             }<br>                                                                                               }<br>        }<br> } }<br>Password to decompress the compressed package: www.renweinet.net


WeChat scan code payment.zip TP combined with WeChat scan code payment mode 2( 23.33 KB Download: 0 times )

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 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)

Learn about introductory code examples for Python programming Learn about introductory code examples for Python programming Jan 04, 2024 am 10:50 AM

Learn about Python programming with introductory code examples Python is an easy-to-learn, yet powerful programming language. For beginners, it is very important to understand the introductory code examples of Python programming. This article will provide you with some concrete code examples to help you get started quickly. Print HelloWorldprint("HelloWorld") This is the simplest code example in Python. The print() function is used to output the specified content

Go language programming examples: code examples in web development Go language programming examples: code examples in web development Mar 04, 2024 pm 04:54 PM

"Go Language Programming Examples: Code Examples in Web Development" With the rapid development of the Internet, Web development has become an indispensable part of various industries. As a programming language with powerful functions and superior performance, Go language is increasingly favored by developers in web development. This article will introduce how to use Go language for Web development through specific code examples, so that readers can better understand and use Go language to build their own Web applications. 1. Simple HTTP Server First, let’s start with a

PHP variables in action: 10 real-life examples of use PHP variables in action: 10 real-life examples of use Feb 19, 2024 pm 03:00 PM

PHP variables store values ​​during program runtime and are crucial for building dynamic and interactive WEB applications. This article takes an in-depth look at PHP variables and shows them in action with 10 real-life examples. 1. Store user input $username=$_POST["username"];$passWord=$_POST["password"]; This example extracts the username and password from the form submission and stores them in variables for further processing. 2. Set the configuration value $database_host="localhost";$database_username="username";$database_pa

Java implements simple bubble sort code Java implements simple bubble sort code Jan 30, 2024 am 09:34 AM

The simplest code example of Java bubble sort Bubble sort is a common sorting algorithm. Its basic idea is to gradually adjust the sequence to be sorted into an ordered sequence through the comparison and exchange of adjacent elements. Here is a simple Java code example that demonstrates how to implement bubble sort: publicclassBubbleSort{publicstaticvoidbubbleSort(int[]arr){int

From beginner to proficient: Code implementation of commonly used data structures in Go language From beginner to proficient: Code implementation of commonly used data structures in Go language Mar 04, 2024 pm 03:09 PM

Title: From Beginner to Mastery: Code Implementation of Commonly Used Data Structures in Go Language Data structures play a vital role in programming and are the basis of programming. In the Go language, there are many commonly used data structures, and mastering the implementation of these data structures is crucial to becoming a good programmer. This article will introduce the commonly used data structures in the Go language and give corresponding code examples to help readers from getting started to becoming proficient in these data structures. 1. Array Array is a basic data structure, a group of the same type

Huawei Cloud Edge Computing Interconnection Guide: Java code examples to quickly implement interfaces Huawei Cloud Edge Computing Interconnection Guide: Java code examples to quickly implement interfaces Jul 05, 2023 pm 09:57 PM

Huawei Cloud Edge Computing Interconnection Guide: Java Code Samples to Quickly Implement Interfaces With the rapid development of IoT technology and the rise of edge computing, more and more enterprises are beginning to pay attention to the application of edge computing. Huawei Cloud provides edge computing services, providing enterprises with highly reliable computing resources and a convenient development environment, making edge computing applications easier to implement. This article will introduce how to quickly implement the Huawei Cloud edge computing interface through Java code. First, we need to prepare the development environment. Make sure you have the Java Development Kit installed (

How to use PHP to write inventory management function code in the inventory management system How to use PHP to write inventory management function code in the inventory management system Aug 06, 2023 pm 04:49 PM

How to use PHP to write the inventory management function code in the inventory management system. Inventory management is an indispensable part of many enterprises. For companies with multiple warehouses, the inventory management function is particularly important. By properly managing and tracking inventory, companies can allocate inventory between different warehouses, optimize operating costs, and improve collaboration efficiency. This article will introduce how to use PHP to write code for inventory warehouse management functions, and provide you with relevant code examples. 1. Establish the database before starting to write the code for the inventory warehouse management function.

Guidance and Examples: Learn to implement the selection sort algorithm in Java Guidance and Examples: Learn to implement the selection sort algorithm in Java Feb 18, 2024 am 10:52 AM

Java Selection Sorting Method Code Writing Guide and Examples Selection sorting is a simple and intuitive sorting algorithm. The idea is to select the smallest (or largest) element from the unsorted elements each time and exchange it until all elements are sorted. This article will provide a code writing guide for selection sorting, and attach specific Java sample code. Algorithm Principle The basic principle of selection sort is to divide the array to be sorted into two parts, sorted and unsorted. Each time, the smallest (or largest) element is selected from the unsorted part and placed at the end of the sorted part. Repeat the above

See all articles