当前位置:网站首页>Wechat payment, wechat refund, Alibaba payment
Wechat payment, wechat refund, Alibaba payment
2022-06-12 10:20:00 【Qu Shuai 369】
github Written by the great God in sdk
https://github.com/zoujingli/WeChatDeveloper
Wechat payment
Basic parameters of wechat payment
$config = [
'token' => 'test',
'appid' => $this->appid,
'appsecret' => $this->secret,
'encodingaeskey' => '',
// Configure merchant payment parameters ( Optional , When using the payment function, you need )
'mch_id' => $this->mch_id,
'mch_key' => $this->key,
// Configure merchant payment two-way certificate Directory ( Optional , In use refund | Payment | Required for red envelope )
'ssl_key' => './public/cert/apiclient_key.pem',
'ssl_cer' => './public/cert/apiclient_cert.pem',
// Cache directory configuration ( Optional , Read and write permission is required )
'cache_path' => './runtime',
];Wechat payment
// Create an interface instance
$wechat = new \WeChat\Pay($config);
// Assembly parameters , Refer to the official merchant documentation
$options = [
'body' => ' Test product ',
'out_trade_no' => time(),
'total_fee' => '1',
'openid' => 'o38gpszoJoC9oJYz3UHHf6bEp0Lo',
//JSAPI--JSAPI payment ( Or small program payment )、NATIVE--Native payment 、APP--app payment ,MWEB--H5 payment
'trade_type' => 'JSAPI',
'notify_url' => 'http://a.com/text.html',
'spbill_create_ip' => '127.0.0.1',
];
try {
// Generate advance payment code
$result = $wechat->createOrder($options);
// establish JSAPI Parameter signature
$options = $wechat->createParamsForJsApi($result['prepay_id']);
// @todo hold $options To the front end js Just initiate payment
} catch (Exception $e) {
// Error , Take care of it
echo $e->getMessage() . PHP_EOL;
}Refund parameters
// Create an interface instance
$wechat = new \WePay\Refund($config);
// Assembly parameters , Refer to the official merchant documentation
$options = [
'appid' => $this->appid,
'mch_id' => $this->mch_id,
'nonce_str' => $nonce_str,
'out_refund_no' => $out_refund_no,
'refund_fee' => $refund_fee,
'total_fee' => $total_fee,
'transaction_id'=> $transaction_id,
];
try {
// To refund
$result = $wechat->create($options);
if($result['result_code'] == 'SUCCESS') {
// Refund successful
}
} catch (\Exception $e) {
// Error , Take care of it
echo $e->getMessage() . PHP_EOL;die;
}Alipay pay
Payment parameter configuration ( Available sandbox mode )
$config = [
// Sandbox mode
'debug' => true,
// Signature type (RSA|RSA2)
'sign_type' => "RSA2",
// application ID
'appid' => '2016090900468879',
// Text content of Alipay public key (1 Fill in line , Particular attention : Here is the alipay public key , Not an application public key , It is best to copy from the web page of the developer center )
'public_key' => 'MIIBIjANBgkqhkiG9...',
// Text content of Alipay private key (1 Fill in line )
'private_key' => 'MIIEvQIBADANBgkqh...',
// Complete contents of the application public key certificate ( The new version of capital interface is transferred to app_cert_sn)
'app_cert' => '',
// Pay the complete contents of Baogen certificate ( The new version of capital interface is transferred to alipay_root_cert_sn)
'root_cert' => '',
// Payment success notification address
'notify_url' => '',
// Web payment bounce address
'return_url' => '',
];Alipay launched PC Website Payment
// Refer to the common parameters https://docs.open.alipay.com/203/107090/
$config['notify_url'] = 'http://pay.thinkadmin.top/test/alipay-notify.php';
$config['return_url'] = 'http://pay.thinkadmin.top/test/alipay-success.php';
try {
// Instance payment object
$pay = We::AliPayWeb($config);
// $pay = new \AliPay\Web($config);
// Reference link :https://docs.open.alipay.com/api_1/alipay.trade.page.pay
$result = $pay->apply([
'out_trade_no' => time(), // Merchant order number
'total_amount' => '1', // Pay the amount
'subject' => ' Payment order description ', // Payment order description
]);
echo $result; // Direct output HTML( Submit the form and jump )
} catch (Exception $e) {
// exception handling
echo $e->getMessage();
}Alipay initiated mobile website payment
// Refer to the common parameters https://docs.open.alipay.com/203/107090/
$config['notify_url'] = 'http://pay.thinkadmin.top/test/alipay-notify.php';
$config['return_url'] = 'http://pay.thinkadmin.top/test/alipay-success.php';
try {
// Instance payment object
$pay = We::AliPayWap($config);
// $pay = new \AliPay\Wap($config);
// Reference link :https://docs.open.alipay.com/api_1/alipay.trade.wap.pay
$result = $pay->apply([
'out_trade_no' => time(), // Merchant order number
'total_amount' => '1', // Pay the amount
'subject' => ' Payment order description ', // Payment order description
]);
echo $result; // Direct output HTML( Submit the form and jump )
} catch (Exception $e) {
// exception handling
echo $e->getMessage();
}
边栏推荐
- MYSQL的最左匹配原则的原理讲解
- [CEGUI] resource loading process
- Win10 professional edition user name modification
- 【MySQL】sql_ Model mode
- C language recursive folder code
- Auto. JS learning notes 7: JS file calls functions and variables in another JS file to solve various problems of call failure
- Jump to wechat in app and open wechat
- Circuitbreaker fuse of resilience4j - circuitbreakerevent event
- [Mozilla] basic concept analysis of IPDL
- IoT简介
猜你喜欢

Implementation principle of redisson distributed lock

【MySQL】sql_ Model mode

Raw socket usage

Shen Min, CIO of science and technology innovator Digital China Group: the best practice model is failing, and open source accelerates Distributed Innovation

2021-03-26

Student management system

GNU EFI development environment settings

Qt自定义窗口圆角

性能指标的信仰危机

学生管理系统
随机推荐
MySQL 4 Database table storage structure & tablespace
2021-02-22
Explication du principe d'appariement le plus à gauche de MySQL
在线电路仿真以及开源电子硬件设计介绍
2021-09-15
Circuitbreaker fuse of resilience4j -- Measurement of circuitbreakermetrics index
3. Abstract Factory
Halcon combined with C # to detect surface defects -- affine transformation (III)
Data processing and visualization of machine learning [iris data classification | feature attribute comparison]
Pandorabox uses firewall rules to define non internet time
Student management system
JVM (VI) Virtual machine bytecode execution engine (with stack execution process and bytecode instruction table)
学生管理系统
PLC如何自行构造移位功能块(FC)
远程桌面不能复制粘贴解决办法
2021-09-13
Redis (I) Internal data structure
Raw socket usage
Cookie object
Auto. JS learning note 9: basic methods such as using the script engine, starting the script file with the specified path, and closing