PHP code example of mano-code / mini-wechat
1. Go to this page and download the library: Download mano-code/mini-wechat library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
mano-code / mini-wechat example snippets
$application = \ManoCode\MiniWechat\Library\EasyWechatLibrary::getMiniAppPaymentApplication();
$response = $application->getClient()->postJson('/v3/pay/transactions/jsapi',[
'appid'=>ManoCode\MiniWechat\Models\WechatSetting::query()->where([
'type'=>'mini-wechat',
'key'=>'appid'
])->value('value'),
'mchid'=>\ManoCode\MiniWechat\Models\WechatSetting::query()->where([
'type'=>'wechat-payment',
'key'=>'mch_id'
])->value('value'),
'description'=>'demo-test',
'out_trade_no'=>date('YmdHis').time(),
'notify_url'=>'http://api.test.wechat.mini-app.com',
'amount'=>[
'total'=>1,// 一分钱测试调用(单位为分)
],
'payer'=>[
'openid'=>\ManoCode\MiniWechat\Models\WechatBind::query()->where(['user_id'=>$this->getMember($request)->getAttribute('id'),'platform'=>'mini-wechat'])->value('openid')
]
],[
'headers'=>[
'User-Agent'=>'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36',
'Accept'=>'application/json'
]
]);
dump($response);// 下单结果打印
$application = \ManoCode\MiniWechat\Library\EasyWechatLibrary::getMiniAppPaymentApplication();
$server = $application->getServer();
$server->handlePaid(function (Message $message, \Closure $next) {
// $message->out_trade_no 获取商户订单号
// $message->payer['openid'] 获取支付者 openid
// 🚨🚨🚨 注意:推送信息不一定靠谱哈,请务必验证
// 建议是拿订单号调用微信支付查询接口,以查询到的订单状态为准
return $next($message);
});
// 默认返回 ['code' => 'SUCCESS', 'message' => '成功']
return $server->serve();