国产+高潮+在线,国产 av 仑乱内谢,www国产亚洲精品久久,51国产偷自视频区视频,成人午夜精品网站在线观看

Webman v2.1+Easywechat 6.17微信支付回調(diào)報(bào)錯(cuò)

Alex-9930

框架:Webman v2.1

支付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
{
/**

  • Notes: 微信支付回調(diào)
  • @NotNeedLogin
  • @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
    {
    /**

  • Notes: 微信支付回調(diào)
  • @param $data
  • @author Alex
  • @return mixed
    */
    public static function handleNotify($data)
    {
    try {
    $data['appid'] = ConfigServer::get('WeChat', 'appId', '2');
    $wechatPay = new WechatPayService($data['appid']);
    $wechatPay->handleNotify($data);
    } catch (\Exception $e) {
    throw new \RuntimeException($e->getMessage());
    }
    }
    }
    WechatPayService.php代碼:
    <?php
    namespace app\common\server;
    use EasyWeChat\Pay\Application;
    use app\common\server\UrlServer;

class WechatPayService
{
/**

  • 初始化微信支付應(yīng)用
  • @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ò)信息

報(bào)錯(cuò):Invalid request body.
handleNotify方法不會(huì)執(zhí)行打印var_dump,輸出不了訂單號(hào)
什么問題,能否請(qǐng)大神幫忙看看

截圖報(bào)錯(cuò)信息里報(bào)錯(cuò)文件相關(guān)代碼

截圖
截圖
截圖

操作系統(tǒng)及workerman/webman等框架組件具體版本

使用easywechat6.17,webman2.1

133 2 0
2個(gè)回答

TM

http://wtbis.cn/a/1556 這里面有解決方案

  • Alex-9930 4天前

    參照這個(gè)寫法依舊問題還是存在

efnic

直接安裝這個(gè)包,專門封裝適配webman的
composer require ledc/easywechat

  • 暫無評(píng)論
??