Thenbsp\Wechat\Payment\Unifiedorder::getResponse PHP Méthode

getResponse() public méthode

获取响应结果
public getResponse ( )
    public function getResponse()
    {
        $options = $this->resolveOptions();
        // 按 ASCII 码排序
        ksort($options);
        $signature = urldecode(http_build_query($options));
        $signature = strtoupper(md5($signature . '&key=' . $this->key));
        $options['sign'] = $signature;
        $response = Http::request('POST', static::UNIFIEDORDER)->withXmlBody($options)->send();
        if ($response['return_code'] === 'FAIL') {
            throw new \Exception($response['return_msg']);
        }
        if ($response['result_code'] === 'FAIL') {
            throw new \Exception($response['err_code_des']);
        }
        return $response;
    }

Usage Example

Exemple #1
0
 /**
  * 构造方法
  */
 public function __construct(Wechat $wechat, array $optionsForUnifiedorder)
 {
     // 将 trade_type 强制设为 JSAPI
     $optionsForUnifiedorder['trade_type'] = self::TRADE_TYPE;
     // 去统一下单接口下单
     $unifiedorder = new Unifiedorder($wechat, $optionsForUnifiedorder);
     // 下单结果中的 prepay_id
     $response = $unifiedorder->getResponse();
     $this->wechat = $wechat;
     parent::__construct(array('package' => sprintf('prepay_id=%s', $response['prepay_id'])));
 }
All Usage Examples Of Thenbsp\Wechat\Payment\Unifiedorder::getResponse