Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to realize the Development of WeChat Pay and Alipay in PHP

2025-04-09 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article will explain in detail how to achieve background WeChat Pay and Alipay pay development in PHP. The editor thinks it is very practical, so I share it with you as a reference. I hope you can get something after reading this article.

WeChat Pay

Project premise: I use tp framework, PHP language

Download the WeChat Pay interface file provided by Wechat platform and put it in the tp third-party class library vendor, named WxpayAPI

WxpayAPI/lib/WxPay.Api.php interface access class; WxpayAPI/lib/WxPay.Config.php configuration account information; WxpayAPI/lib/WxPay.Data.php data object basic class; WxpayAPI/lib/WxPay.Exception.php WeChat Pay API exception class; WxpayAPI/lib/WxPay.Notify.php callback basic class WxpayAPI/example/WxPay.JsApiPay.php JSAPI payment implementation class

1. Partial changes have been made to the source code

(1) comment out in WxPay.Api.php

/ / require_once "WxPay.Exception.php"

/ / require_once "WxPay.Config.php"

/ / require_once "WxPay.Data.php"

(2) in WxPay.Config.php

APPID, MCHID, KEY and APPSECRET need to be configured according to merchant information.

(3) comment out in WxPay.Data.php

/ / require_once "WxPay.Config.php"

/ / require_once "WxPay.Exception.php"

(4) comment out in WxPay.JsApiPay.php

/ / require_once ".. / lib/WxPay.Api.php"

After configuring these, here is our key part.

two。 There are order function sure () and callback information function Callback_url () in order controller GoodsController.class.php.

/ * submit order function * / public function sure () {$o_model = D ("Wine/Orders"); if (IS_AJAX) {$data = I ("post."); if ($if model-> create ($data)) {if (! sp_check_verify_code ()) {$this- > error ("CAPTCHA error!") ;} # generate random order number $order_code ='O'. Date ('YmdHis'). Get_order_code (4); while ($ostensible model-> findone (array ("order_code" = > $order_code)) {$order_code ='O'. Date ('YmdHis'). $ostatic model-> get_order_code (4);} $data ['order_code'] = $order_code; $addr [0] = $_ POST [' prov']; $addr [1] = $_ POST ['city']; $addr [2] = $_ POST [' dist']; $addr [3] = $_ POST ['area']; $data [' area'] = serialize ($addr); $data ['create_time'] = time () $data ['update_time'] = time (); if ($data [' pay_id'] = = 1) {$data ['order_status'] = 11; / paid $data [' status'] = '1payment;} else {$data [' order_status'] = 10; / pending payment $data ['status'] =' 1payment;} / function call return information $this- > Callback_url ($data) } else {$this- > error ($ostensible model-> getError ());}} else {$this- > error ($oiled model-> getError ());}} / * callback information function * @ param type $data * / public function Callback_url ($data) {$o_model = D ("Wine/Orders"); $add_id = $ostatic model-> add ($data) If (! $add_id) {$this- > error ("order submission failed, please try again later!") ;} if ('4' = = $data ['pay_id']) {if (' 4' = = $data [payout _ id']) {/ / WeChat Pay $msg ='is jumping to the WeChat Pay page for you, please wait …' ; $url = "/ index.php/wine/wxpay/index/?o_id=$add_id";} $this- > success ("order submitted successfully!" . $msg, $url);}

3. [key points!] WxpayController. Class.php WeChat Pay controller to realize the call to Wechat interface

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report