Zero rate and zero risk : WeChat visa-free payment solution based on wechaty + appreciation code?
As we all know, merchant qualifications are required to access the WeChat payment interface. There is a strict review process and a certain review fee is required. After passing the review, WeChat will also charge a certain handling fee for each transaction. Even if you use visa-free services on other platforms For payment, relevant fees must be paid, and the security of funds cannot be guaranteed. The existing open source visa-free payment is also implemented by monitoring WeChat notifications on the mobile phone, which requires high equipment and easily causes risk control. These solutions Neither is suitable for individual developers and smaller websites.
As a result, WPayment came into being. It is based on the well-known wechaty SDK to monitor WeChat messages, and uses the appreciation code mechanism to collect payments. The appreciation code can have an optional amount and custom remarks, which can be conveniently used for any specified small amount ( The amount of a single appreciation cannot exceed 200 yuan), and there is no need to use the amount to distinguish different users. At the same time, the appreciation code is set up to receive appreciation from netizens from all over the country, so it is not like the payment code It's easy to be controlled by wind.
Install using npm:
npm install --save wpayment
The basic usage process is:
WPayment
object and call login()
method to obtain the WeChat login link. Please convert it into a QR code yourself and then log in with the payee 's WeChat;createOrder()
method to create an order when needed, and note verifyCode
attribute (a four-digit number) of the returned Order
object;verifyCode
in the "Remarks" column, and then pay.onPaid()
callback in the createOrder()
method parameter will be called. In addition, considering the user's misoperation (such as forgetting to enter the wrong amount, entering the wrong verifyCode
, paying after the order times out), the WPayment
object also provides queryOrder
method to ensure that the payer's WeChat nickname, payment amount, and WeChat transfer number can be used. Query order information through other methods. For more detailed instructions, see /docs/document.md
.
A simple Demo is as follows:
const WPayment = require ( 'wpayment' ) . default ;
const qrcode = require ( 'qrcode' ) ;
let intervalID , timeLeft = 300 ;
const payment = new WPayment ( ) ;
payment . login ( ( linkGetter ) => {
// 登录请求回调
const link = linkGetter ( ) ;
qrcode . toString ( link , { type : 'terminal' } , ( error , result ) => {
if ( error ) {
console . log ( error ) ;
return ;
}
console . clear ( ) ;
console . log ( '请扫描二维码登录微信:' , 'n' ) ;
console . log ( result ) ;
} )
} , ( nickname ) => {
// 登录成功回调
console . clear ( ) ;
console . log ( nickname , '已登录' ) ;
const order = payment . createOrder ( '0.02' , ( orderID ) => {
// 订单支付成功回调
clearInterval ( intervalID ) ;
console . log ( 'n订单 ' + orderID + ' 已支付!' ) ;
console . log ( '支付人微信昵称:' , order . payer ) ;
console . log ( '支付时间:' , order . paidTime . toLocaleString ( ) ) ;
console . log ( '微信订单号:' , order . transID ) ;
} , ( error ) => {
// 订单支付失败(系统错误、主动取消或订单超时未支付)回调
console . log ( error ) ;
clearInterval ( intervalID ) ;
} , 300 ) ;
intervalID = setInterval ( ( ) => {
timeLeft -= 1 ;
if ( timeLeft <= 0 ) {
clearInterval ( intervalID ) ;
return ;
}
console . clear ( ) ;
console . log ( '创建了一笔新订单,金额 0.02 元,动态码为 ' + order . verifyCode ) ;
console . log ( '请在' , timeLeft , '秒内完成支付' ) ;
} , 1000 ) ;
} , ( error ) => {
// 登录失败回调
console . log ( error ) ;
} ) ;
This project is completely free and is for education and learning only and may not be used for any illegal purposes.