Home > Backend Development > PHP Tutorial > Detailed explanation of TP access to WeChat public account payment

Detailed explanation of TP access to WeChat public account payment

*文
Release: 2023-03-18 10:40:02
Original
3725 people have browsed it

WeChat plays an increasingly important role in life. Places with a large flow of people and a large amount of information are battlegrounds for merchant marketing. There are more and more scenarios where WeChat payment is used in WeChat public accounts. Below, PHP programmer Lei Xuesong explains in detail how ThinkPHP can access WeChat public account payment.


1. Download the official demo and place it under ThinkPHP/Library/Vendor/. It is recommended to create a Wxpay folder. If you want to access Alipay in the future, create another Alipay. This way the catalog may be clearer in the case of multiple payments.


Detailed explanation of TP access to WeChat public account payment


2. Modify WeChat payment-related parameters in the WxPay.Config.php file. And put the certificate downloaded from the WeChat Payment Merchant Platform in the ThinkPHP/Library/Vendor/Wxpay/cert/ folder.


const APPID = '';//开户邮件中可查看或者微信支付后商户平台
const MCHID = '';//开户邮件中可查看或者微信支付商户平台
const KEY = '';//微信支付商户平台自行设置
const APPSECRET = '';//微信公众号secert
// 证书路径,注意应该填写绝对路径(仅退款、撤销订单时需要),可登录商户平台下载,API证书下载地址:https://pay.weixin.qq.com/index.php/account/api_cert,下载之前需要安装商户操作证书)
const SSLCERT_PATH = 'cert/apiclient_cert.pem';
const SSLKEY_PATH = 'cert/apiclient_key.pem';
Copy after login

3. Set up the payment directory in the WeChat official account. The specific steps are: WeChat Payment->Development Configuration-> Enter the WeChat payment address, which must be detailed to Second-level directories, ending with a left slash "/". For example: the link for WeChat payment is: domain name/wxpay/Cart/weixinpay/o_no/20170622164600. The order number after o_no is a random order number. Then the payment directory in the WeChat official account is: domain name/wxpay/Cart/weixinpay/o_no/.


Detailed explanation of TP access to WeChat public account payment


#4. Set the JS interface security domain name setting and web page authorization domain name in the WeChat public account . Specific steps: Official account settings->Function settings.


Detailed explanation of TP access to WeChat public account payment


Note: When paying on WeChat, openID will be obtained first. The process of obtaining openID is to first request WeChat, and WeChat will return the code to the current request link. A simple understanding is that the WeChat payment link will be requested twice. The first time is when we request to call WeChat payment, and the second time is when WeChat callback gets the openID. Is it possible to run the WeChat payment link for the second time? The subsequent parameters will be lost. For the specific code, you can view the GetOpenid method in WeChat WxPay.JsApiPay.php.


If you understand these key points of WeChat payment, the specific code should be easier to write. For payments and notifications, you can refer to the files in the exmaple folder in WeChat Pay.


The above is the detailed content of Detailed explanation of TP access to WeChat public account payment. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template