支付SDK:Easywechat 6.17
PayController.php控制器代碼:
<?php
namespace app\api\controller\pay;
use support\Request;
use app\api\logic\pay\PayLogic;
use app\common\server\JsonServer;
use app\common\basics\ApiBase;
class PayController extends ApiBase
{
/**
@author Alex
*/
public function notifyApplet(Request $request) {
try {
// 獲取微信回調(diào)數(shù)據(jù)
$content = $request->rawBody();
$data = json_decode($content, true);
if (!isset($data['resource'])) {
return JsonServer::error('回調(diào)數(shù)據(jù)異常');
}
$result = PayLogic::handleNotify($data);
} catch (\RuntimeException $e) {
return JsonServer::error($e->getMessage());
} catch (\Exception $e) {
return JsonServer::error('系統(tǒng)錯(cuò)誤: '.$e->getMessage());
}
}
}
PayLogic.php代碼:
<?php
namespace app\api\logic\pay;
use support\Request;
use app\common\basics\Logic;
use app\common\server\WechatPayService;
class PayLogic extends Logic
{
/**
class WechatPayService
{
/**
@author Alex
*/
public function __construct($appid, $verify = false)
{
try {
if (!$this->checkCertsExist()) {
throw new \RuntimeException('證書文件不存在,請(qǐng)手動(dòng)下載并放置到指定目錄。');
}
$config = [
'mch_id' => $this->wechat['mch_id'],
'app_id' => $this->wechat['app_id'],
'certificate' => base_path('public'.$this->certUri),
'private_key' => base_path('public'.$this->keyUri), // 商戶API證書私鑰路徑
'secret_key' => $this->wechat['secret_key'],
'platform_certs' => [
file_get_contents(base_path('public'.$this->platformUri)),
],
'http' => [
'throw' => true,
'timeout' => 5.0,
],
'notify_url' => UrlServer::getFileUrl().'/api/pay/pay/notifyApplet',
];
$this->app = new Application($config);
} catch (\Exception $e) {
throw new \RuntimeException('微信支付服務(wù)初始化失敗');
}
}
// 處理支付回調(diào)
public function handleNotify()
{
$server = $this->app->getServer();
$server->handlePaid(function (Message $message, \Closure $next) {
var_dump($message->out_trade_no);
return $next($message);
});
}
}
報(bào)錯(cuò):Invalid request body.
handleNotify方法不會(huì)執(zhí)行打印var_dump,輸出不了訂單號(hào)
什么問題,能否請(qǐng)大神幫忙看看
使用easywechat6.17,webman2.1