调用【创建代金券批次API】,返回NO_AUTH

微信支付 文章 2021-03-15 21:01 531 0 全屏看文

AI助手支持GPT4.0

调用【创建代金券批次API】,返回NO_AUTHCall [Create voucher batch API], return NO_AUTH

调用【创建代金券批次API】,返回NO_AUTH

商户号:1518669531

wechatpay-guzzle-middleware调用创建代金券api接口(https://api.mch.weixin.qq.com/v3/marketing/favor/coupon-stocks),时返回报错:

Client error: `POST https://api.mch.weixin.qq.com/v3/marketing/favor/coupon-stocks` resulted in a `403 Forbidden` response: {"code":"NO_AUTH","message":"你配置的信息需要开通特殊权限"} 403 Forbidden {"code":"NO_AUTH","message":"你配置的信息需要开通特殊权限"}

请求参数:

array(9) {

  ["stock_name"] => string(6) "测试"

  ["belong_merchant"] => string(10) "1518669531"

  ["available_begin_time"] => string(25) "2021-03-16T16:43:16+08:00"

  ["available_end_time"] => string(25) "2021-04-08T16:43:16+08:00"

  ["stock_use_rule"] => array(5) {

    ["max_amount"] => int(10)

    ["max_coupons"] => int(10)

    ["max_coupons_per_user"] => int(2)

    ["natural_person_limit"] => bool(true)

    ["prevent_api_abuse"] => bool(true)

  }

  ["coupon_use_rule"] => array(2) {

    ["available_merchants"] => array(1) {

      [0] => string(10) "1518669531"

    }

    ["fixed_normal_coupon"] => array(2) {

      ["coupon_amount"] => int(1)

      ["transaction_minimum"] => int(100)

    }

  }

  ["no_cash"] => bool(true)

  ["stock_type"] => string(6) "NORMAL"

  ["out_request_no"] => string(24) "1518669531_20210315_9465"

}

请求代码:


public function test()

{


    $gzh_id = config('database.gzh_id');

    $xcx_id = config('database.xcx_id');


    // 商户相关配置

    $merchantId = config('database.mch_id');

    $merchantSerialNumber = config('database.mch_ser_num');

    $merchantPrivateKey = PemUtil::loadPrivateKey(ADDON_PATH.DS.'wxcard'.DS.'public'.DS.'cert1'.DS.'apiclient_key.pem'); // 商户私钥

    // 微信支付平台配置

    $wechatpayCertificate = PemUtil::loadCertificate(ADDON_PATH.DS.'wxcard'.DS.'public'.DS.'cert1'.DS.'apiclient_cert.pem'); // 微信支付平台证书


    // 构造一个WechatPayMiddleware

    $wechatpayMiddleware = WechatPayMiddleware::builder()

        ->withMerchant($merchantId, $merchantSerialNumber, $merchantPrivateKey) // 传入商户相关配置

        ->withWechatPay([ $wechatpayCertificate ]) // 可传入多个微信支付平台证书,参数类型为array

        ->build();


    // 将WechatPayMiddleware添加到Guzzle的HandlerStack中

    $stack = GuzzleHttpHandlerStack::create();

    $stack->push($wechatpayMiddleware, 'wechatpay');


    // 创建Guzzle HTTP Client时,将HandlerStack传入

    $client = new GuzzleHttpClient(['handler' => $stack]);


    $json = [

        'stock_name' => '测试',

        'belong_merchant' => $merchantId,

        'available_begin_time' => date(DATE_RFC3339, time()+(24*3600)),

        'available_end_time' => date(DATE_RFC3339, time()+(24*24*3600)),

        'stock_use_rule' => [

            'max_amount' => 10,

            'max_coupons' => 10,

            'max_coupons_per_user' => 2,

            'natural_person_limit' => true,

            'prevent_api_abuse' => true,

        ],

        'coupon_use_rule' => [

            'available_merchants' => [

                $merchantId,

            ],

            'fixed_normal_coupon' => [

                'coupon_amount' => 1,

                'transaction_minimum' => 100,

            ],

        ],

        'no_cash' => true,

        'stock_type' => 'NORMAL',

        'out_request_no' => $merchantId.'_'.date('Ymd').'_'.Random::numeric(4),

    ];


    dump($json);



    // 接下来,正常使用Guzzle发起API请求,WechatPayMiddleware会自动地处理签名和验签

    try {

        $resp = $client->request('POST', 'https://api.mch.weixin.qq.com/v3/marketing/favor/coupon-stocks', [ // 注意替换为实际URL

            // JSON请求体

            'json' => $json,

            'headers' => [

                'Accept' => 'application/json',

                'Content-Type' => 'application/json',

            ],

        ]);


        echo $resp->getStatusCode().' '.$resp->getReasonPhrase()."n";

        echo $resp->getBody()."n";

        // return $resp->getBody();

    } catch (RequestException $e) {

        // // 进行错误处理

        echo $e->getMessage()."n";

        if ($e->hasResponse()) {

            echo $e->getResponse()->getStatusCode().' '.$e->getResponse()->getReasonPhrase()."n";

            echo $e->getResponse()->getBody();

        }

        return;

        // return $e->getResponse()->getBody();

    }


}


Merchant No.: 1518669531 wechatpay guzzle middleware call to create voucher API interface( https://api.mch.weixin.qq.com/v3/marketing/favor/coupon-stocks )Client error: ` post https://api.mch.weixin.qq.com/v3/marketing/favor/coupon-stocks ` resulted in a `403 Forbidden` response: {"code":"NO_ Auth, message: the information you configure needs special permission_ "Auth", "message": "the information you configure needs special permission"} request parameters: array (9) {["stock"}_ Name "] = > string (6)" test "[" bell "_ merchant"] => string(10) "1518669531" ["available_ begin_ time"] => string(25) "2021-03-16T16:43:16+08:00" ["available_ end_ time"] => string(25) "2021-04-08T16:43:16+08:00" ["stock_ use_ rule"] => array(5) { ["max_ amount"] => int(10) ["max_ coupons"] => int(10) ["max_ coupons_ per_ user"] => int(2) ["natural_ person_ limit"] => bool(true) ["prevent_ api_ abuse"] => bool(true) } ["coupon_ use_ rule"] => array(2) { ["available_ merchants"] => array(1) { [0] => string(10) "1518669531" } ["fixed_ normal_ coupon"] => array(2) { ["coupon_ amount"] => int(1) ["transaction_ minimum"] => int(100) } } ["no_ cash"] => bool(true) ["stock_ type"] => string(6) "NORMAL" ["out_ request_ no"] => string(24) "1518669531_ 20210315_ 9465 "} request code: public function test () {$GZH_ id = config(' database.gzh_ id'); $xcx_ id = config(' database.xcx_ ID '); / / merchant related configuration $merchantid = config (' database.mch_ id'); $merchantSerialNumber = config(' database.mch_ ser_ num'); $merchantPrivateKey = PemUtil::loadPrivateKey(ADDON_ PATH.DS .'wxcard'.DS.'public'.DS.'cert1'.DS.'apiclient_ key.pem '; / / merchant private key / / wechat payment platform configuration $wechatpaycertificate = pemutil:: loadcertificate (addon)_ PATH.DS .'wxcard'.DS.'public'.DS.'cert1'.DS.'apiclient_ cert.pem '; / / wechat payment platform certificate / / construct a wechatpaymiddleware $wechatpaymiddleware = wechatpaymiddleware:: builder() - > withmerchant ($merchant ID, $merchant serialnumber, $merchant private key) / / transfer in merchant related configuration - > withwechatpay ([$wechatpaycertificate]) / / multiple wechat payment platform certificates can be transferred in, and the parameter type is array - > build(); //Add wechatpaymiddleware to guzzle's handlerstack $stack = guzzlehttp / handlerstack:: create(); $stack - > push ($wechatpaymiddleware, 'wechatpay'); / / when creating guzzle HTTP client, pass the handlerstack into $client = new guzzlehttp / client (['handler '= > $stack]); $JSON = ['stock]_ Name '= >'test','belong '_ merchant' => $merchantId, 'available_ begin_ time' => date(DATE_ RFC3339, time()+(24*3600)), 'available_ end_ time' => date(DATE_ RFC3339, time()+(24*24*3600)), 'stock_ use_ rule' => [ 'max_ amount' => 10, 'max_ coupons' => 10, 'max_ coupons_ per_ user' => 2, 'natural_ person_ limit' => true, 'prevent_ api_ abuse' => true, ], 'coupon_ use_ rule' => [ 'available_ merchants' => [ $merchantId, ], 'fixed_ normal_ coupon' => [ 'coupon_ amount' => 1, 'transaction_ minimum' => 100, ], ], 'no_ cash' => true, 'stock_ type' => 'NORMAL', 'out_ request_ no' => $merchantId.'_ '.date('Ymd').'_ '. Random:: numeric (4),]; dump ($JSON); / / next, normally use guzzle to initiate API requests, and wechatpaymiddleware will automatically process the signature and verification. Try {$resp = $client - > request ('post', ' https://api.mch.weixin.qq.com/v3/marketing/favor/coupon-stocks ', [/ / note to replace with the actual URL / / JSON request body' JSON '= > $JSON, 'headers' = > ['accept' = >'application / JSON ','content type' = >'application / JSON ',]]; echo $resp - > getstatuscode().' '. $resp - > getreasonphase(). " n"; / / return $resp - > getbody();} catch (requestexception $e) {/ / / error handling echo $e - > getmessage(). " n"; echo $resp - >'application / JSON',]; if ($e->hasResponse()) { echo $e->getResponse()->getStatusCode().' '.$e->getResponse()->getReasonPhrase()."n"; echo $e->getResponse()->getBody(); } return; // return $e->getResponse()->getBody(); } }

回答:

微信支付技术社区运营-Tasting:

{

    "stock_name": "GD测批次4",

    "comment": "验证活动",

    "belong_merchant": "xxxxxx",

    "available_begin_time": "2020-02-13T18:00:00.120+08:00",

    "available_end_time": "2020-02-20T23:59:59.120+08:00",

    "stock_use_rule": {

        "max_coupons": 10,

        "max_amount": 100,

        "max_coupons_per_user": 10,

        "natural_person_limit": false,

        "prevent_api_abuse": false

    },

    "coupon_use_rule": {

        "fixed_normal_coupon": {

            "coupon_amount": 10,

            "transaction_minimum": 10

        },

        "available_merchants": [

            "209784532",

            "221003827"

        ]

    },

    "no_cash": false,

    "stock_type": "NORMAL",

    "out_request_no": "207662xxxxxx"

}


按照这个示列传值,并注意:

1.stock_name:最多可填写9个字

2.max_coupons_per_user:单天发放个数上限不能为0

3. coupon_amount:10<=coupon_amount<=100000

4.available_time_after_receive:可用时间:相对时间,按分钟设置,是否1min<=分钟范围<=1440min

5.transaction_minimum校验规则:

a、使用门槛-券面额>=0.01(门槛要大于面额)

b、0.1元<=门槛<=100000

6.stock_type:目前只支持NORMAL

7.out_request_no:校验规则:不可以重复

8.开始时间结束时间控制在90天内

请按照示列跟注意事项进行参考一下

Memory:

belong_merchant 该字段暂未开放

peng:

券金额小于1元(coupon_amount)要申请吧

Memory:他是传参了未开放字段

-EOF-

AI助手支持GPT4.0