当前位置:网站首页>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();
}
边栏推荐
- 不需要安装防毒软件的系统Chromebook
- JVM (V) Virtual machine class loading (parental delegation mechanism)
- GNU EFI development environment settings
- 3. Abstract Factory
- The difference between static method locking and non static method locking
- 2021-09-13
- [Wayland] Weston startup process analysis
- 93. obtain all IP addresses of the Intranet
- 【ParquetEncodingException: empty fields are illegal, the field should be ommited completely instead
- Explanation of the principle of MySQL's leftmost matching principle
猜你喜欢

IoT简介

在线电路仿真以及开源电子硬件设计介绍

【926. 将字符串翻转到单调递增】

conda 安装tensorflow 测试tensorflow
![Data processing and visualization of machine learning [iris data classification | feature attribute comparison]](/img/a3/1d181b9dd5268e13cc276a78862d1f.png)
Data processing and visualization of machine learning [iris data classification | feature attribute comparison]

Web3.0与数字时尚,该如何落地?

容器江湖的爱恨情仇

Qt自定义窗口圆角

远程桌面不能复制粘贴解决办法

Circuitbreaker fuse of resilience4j -- Measurement of circuitbreakermetrics index
随机推荐
Research on autojs wechat: the control IP in wechat on different versions of wechat or simulators is different.
看看你有没有陷入“标签化”客户和 用户 的陷阱?
Chromebook system without anti-virus software
Yarn scheduling
Circuitbreaker fuse of resilience4j - Summary
Web3.0与数字时尚,该如何落地?
Auto. JS learning notes 8: some common and important APIs
1268_FreeRTOS任务上下文切换的实现
Checkpoint of the four cornerstones of Flink
容器江湖的爱恨情仇
Auto. JS learning note 10: instantiate a custom object and use json The stringify() method causes an error (resolved)
机器学习不是你想用,想用就能用
Auto. JS learning note 9: basic methods such as using the script engine, starting the script file with the specified path, and closing
[926. flip the string to monotonic increment]
2021-03-26
Clickhouse column basic data type description
ServletContext object
Strange error -- frame detected by contour detection, expansion corrosion, and reversal of opening and closing operation effect
Introduction to IOT
Auto. JS learning notes 7: JS file calls functions and variables in another JS file to solve various problems of call failure