


Share the implementation of payment function (front-end) developed by WeChat
This article mainly introduces the relevant information about the implementation of the WeChat Mini Program payment function (front-end). Friends in need can refer to
The implementation of the WeChat Mini Program payment function (front-end)
Only provides WeChat applet code:
var app = getApp(); Page({ data: {}, onLoad: function (options) { // 页面初始化 options为页面跳转所带来的参数 var that = this //登陆获取code wx.login({ success: function (res) { console.log(res.code) //获取openid that.getOpenId(res.code) } }); }, getOpenId: function (code) { var that = this; wx.request({ url: "https://api.weixin.qq.com/sns/jscode2session?appid=小程序appid&secret=小程序应用密钥&js_code=" + code + "&grant_type=authorization_code", data: {}, method: 'GET', success: function (res) { that.generateOrder(res.data.openid) }, fail: function () { // fail }, complete: function () { // complete } }) }, /**生成商户订单 */ generateOrder: function (openid) { var that = this //统一支付 wx.request({ url: '后台路径', method: 'GET', data: { gfee: '商品价钱', gname: '商品名称', openId:openid (商品价钱和商品名称根据自身需要是否传值,openid为必传) }, success: function (res) { var pay = res.data //发起支付 var timeStamp = pay[0].timeStamp; var packages = pay[0].package; var paySign = pay[0].paySign; var nonceStr = pay[0].nonceStr; var param = { "timeStamp": timeStamp, "package": packages, "paySign": paySign, "signType": "MD5", "nonceStr": nonceStr }; that.pay(param) }, }) }, /* 支付 */ pay: function (param) { console.log("支付") console.log(param) wx.requestPayment({ timeStamp: param.timeStamp, nonceStr: param.nonceStr, package: param.package, signType: param.signType, paySign: param.paySign, success: function (res) { // success wx.navigateBack({ delta: 1, // 回退前 delta(默认为1) 页面 success: function (res) { wx.showToast({ title: '支付成功', icon: 'success', duration: 2000 }) }, fail: function () { // fail }, complete: function () { // complete } }) }, fail: function (res) { // fail }, complete: function () { // complete } }) } })
[Related recommendations]
1. WeChat public account platform source code download
3. WeChat LaLa Takeout 2.2.4 decrypted open source version of WeChat Rubik’s Cube source code
The above is the detailed content of Share the implementation of payment function (front-end) developed by WeChat. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

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

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











PHP is an open source scripting language that is widely used in web development and server-side programming, especially in WeChat development. Today, more and more companies and developers are starting to use PHP for WeChat development because it has become a truly easy-to-learn and easy-to-use development language. In WeChat development, message encryption and decryption are a very important issue because they involve data security. For messages without encryption and decryption methods, hackers can easily obtain the data, posing a threat to users.

Design and development guide for UniApp to realize the connection between payment function and payment interface 1. Introduction With the rapid development of mobile payment, payment function has become one of the necessary functions in mobile application development. UniApp is a cross-platform application development framework that supports writing once and publishing on multiple platforms, and can efficiently implement payment functions. This article will introduce how to implement the payment function in UniApp and connect it with the payment interface. 2. Design and Development of Payment Function 1. Preparation Before starting, please make sure that you have completed the following preparations

How to handle payment and settlement functions in accounting systems - development methods to implement accounting payment and settlement, specific code examples are required. With the development of Internet technology and cloud computing, accounting systems have become an indispensable and important tool for many enterprises. In a complete accounting system, payment and settlement are two core functions, and the development methods and specific code examples to achieve these two functions will be discussed in detail in this article. 1. Payment function development method To realize the payment function in the accounting system, it first needs to be connected with the payment platform to ensure smooth payment.

With the popularity of WeChat, more and more companies are beginning to use it as a marketing tool. The WeChat group messaging function is one of the important means for enterprises to conduct WeChat marketing. However, if you only rely on manual sending, it is an extremely time-consuming and laborious task for marketers. Therefore, it is particularly important to develop a WeChat mass messaging tool. This article will introduce how to use PHP to develop WeChat mass messaging tools. 1. Preparation work To develop WeChat mass messaging tools, we need to master the following technical points: Basic knowledge of PHP WeChat public platform development Development tools: Sub

How to use Alipay payment function in uniapp Alipay is one of the largest mobile payment platforms in China. In order to facilitate developers to use Alipay payment function in uniapp, Alipay provides a set of convenient API interfaces. This article will introduce how to use Alipay payment function in uniapp and provide corresponding code examples. 1. Apply for an Alipay open platform account and key. First, you need to apply for a developer account on the Alipay open platform and obtain the corresponding AppID and key. The specific steps are as follows: 1.

In the development of WeChat public accounts, user tag management is a very important function, which allows developers to better understand and manage their users. This article will introduce how to use PHP to implement the WeChat user tag management function. 1. Obtain the openid of the WeChat user. Before using the WeChat user tag management function, we first need to obtain the user's openid. In the development of WeChat public accounts, it is a common practice to obtain openid through user authorization. After the user authorization is completed, we can obtain the user through the following code

How to use PHP to develop WeChat public accounts WeChat public accounts have become an important channel for promotion and interaction for many companies, and PHP, as a commonly used Web language, can also be used to develop WeChat public accounts. This article will introduce the specific steps to use PHP to develop WeChat public accounts. Step 1: Obtain the developer account of the WeChat official account. Before starting the development of the WeChat official account, you need to apply for a developer account of the WeChat official account. For the specific registration process, please refer to the official website of WeChat public platform

As WeChat becomes an increasingly important communication tool in people's lives, its agile messaging function is quickly favored by a large number of enterprises and individuals. For enterprises, developing WeChat into a marketing platform has become a trend, and the importance of WeChat development has gradually become more prominent. Among them, the group sending function is even more widely used. So, as a PHP programmer, how to implement group message sending records? The following will give you a brief introduction. 1. Understand the development knowledge related to WeChat public accounts. Before understanding how to implement group message sending records, I
