收藏
回答

微信商家转账接口 报备场景信息 不填还能正常提示错误信息,填了直接403 ?

$resp = $instance->chain('v3/fund-app/mch-transfer/transfer-bills')->post(['json' => [

            'appid' => 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxx',

            'out_bill_no' => 'TEST'.date('YmdHis').rand(1000,9999),

            'transfer_scene_id' => '1005',

            'openid' => $touser,

            'transfer_amount' => 1000,

            'transfer_remark' => '转账测试',

            'notify_url' => 'https://www.xxxx.net',

            'user_recv_perception' => '劳务报酬',

            'transfer_scene_report_infos' => [

                [

                    'info_type' => '岗位类型',

                    'info_content' => '分销商',

                ],

                [

                    'info_type' => '报酬说明',

                    'info_content' => '佣金提现',

                ]

            ],

]]);


Client error: `POST https://api.mch.weixin.qq.com/v3/fund-app/mch-transfer/transfer-bills` resulted in a `403 Forbidden` response


回答关注问题邀请回答
收藏

2 个回答

  • 北望沣渭
    北望沣渭
    1天前

    微信支付APIv3充分复用了HTTP状态码来反馈接口响应状态,PHP SDK readme上有写,对于同步代码,需要用try {} catch(){} 语句包裹,异步可以用otherwise捕获,例如:

    try {
    
    $response = $instance->chain('v3/fund-app/mch-transfer/transfer-bills')->post([
      'json' => [
        'appid'                       => 'wxf636efh567hg4356',
        'out_bill_no'                 => 'plfk2020042013',
        'openid'                      => 'o-MYE42l80oelYMDE34nYD456Xoy',
        'user_name'                   => '757b340b45ebef5467rter35gf464344v3542sdf4t6re4tb4f54ty45t4yyry45',
        'transfer_amount'             => 400000,
        'transfer_remark'             => '2020年4月报销',
        'notify_url'                  => 'https://www.weixin.qq.com/wxpay/pay.php',
        'user_recv_perception'        => '现金奖励',
        'transfer_scene_id'           => '1000',
        'transfer_scene_report_infos' => [[
          'info_type'    => '活动名称',
          'info_content' => '注册会员有礼',
        ],],
      ],
      'headers' => [
        'Wechatpay-Serial' => 'PUB_KEY_ID_0114232134912410000000000000',
      ],
    ]);
    print_r(json_decode((string) $response->getBody(), true));
    
    } catch (\Exception $e) {
        // 进行错误处理
        echo $e->getMessage(), PHP_EOL;
        if ($e instanceof \GuzzleHttp\Exception\RequestException && $e->hasResponse()) {
            $r = $e->getResponse();
            echo $r->getStatusCode() . ' ' . $r->getReasonPhrase(), PHP_EOL;
            echo (string) $r->getBody(), PHP_EOL, PHP_EOL, PHP_EOL;
        }
        echo $e->getTraceAsString(), PHP_EOL;
    }
    


    异步方式

    $instance->chain('v3/fund-app/mch-transfer/transfer-bills')->postAsync([
      'json' => [
        'appid'                       => 'wxf636efh567hg4356',
        'out_bill_no'                 => 'plfk2020042013',
        'openid'                      => 'o-MYE42l80oelYMDE34nYD456Xoy',
        'user_name'                   => '757b340b45ebef5467rter35gf464344v3542sdf4t6re4tb4f54ty45t4yyry45',
        'transfer_amount'             => 400000,
        'transfer_remark'             => '2020年4月报销',
        'notify_url'                  => 'https://www.weixin.qq.com/wxpay/pay.php',
        'user_recv_perception'        => '现金奖励',
        'transfer_scene_id'           => '1000',
        'transfer_scene_report_infos' => [[
          'info_type'    => '活动名称',
          'info_content' => '注册会员有礼',
        ],],
      ],
      'headers' => [
        'Wechatpay-Serial' => 'PUB_KEY_ID_0114232134912410000000000000',
      ],
    ])
    ->then(static function(\Psr\Http\Message\ResponseInterface $response) {
      print_r(json_decode((string) $response->getBody(), true));
    })
    ->otherwise(static function($e) {
        // 异常错误处理
        echo $e->getMessage(), PHP_EOL;
        if ($e instanceof \GuzzleHttp\Exception\RequestException && $e->hasResponse()) {
            $r = $e->getResponse();
            echo $r->getStatusCode() . ' ' . $r->getReasonPhrase(), PHP_EOL;
            echo (string) $r->getBody(), PHP_EOL, PHP_EOL, PHP_EOL;
        }
        echo $e->getTraceAsString(), PHP_EOL;
    });
    ->wait();
    


    代码可以从 https://wechatpay.im/openapi/v3/fund-app/mch-transfer/transfer-bills CV

    1天前
    有用 1
    回复
  • Memory
    Memory
    2天前

    403是没有权限,把返回的body打印出来,里面有具体错误

    2天前
    有用 1
    回复 12
    • 陆龙飞
      陆龙飞
      2天前
      就是没有body,之前提示过权限问题,已经配置了IP权限,不传报备信息能正常提示错误body,传了反而403 错误信息都没有
      2天前
      回复
    • Memory
      Memory
      2天前回复陆龙飞
      很明显你没捕获,并不是没有给你返回
      2天前
      回复
    • 陆龙飞
      陆龙飞
      2天前
      Client error: `POST https://api.mch.weixin.qq.com/v3/fund-app/mch-transfer/transfer-bills` resulted in a `400 Bad Request` response: {"code":"PARAM_ERROR","message":"未传入完整且对应的转账场景报备信息,请根据接口文档检查"}
      错误位置
      2天前
      回复
    • 陆龙飞
      陆龙飞
      2天前回复Memory
      看清楚,这才是符合的错误,什么叫很明显没有捕获,不懂就不要回答
      2天前
      回复
    • Memory
      Memory
      1天前回复陆龙飞
      写代码水平有嘴一半硬也行啊
      1天前
      回复
    查看更多(7)
登录 后发表内容