omnipay-alipay-example icon indicating copy to clipboard operation
omnipay-alipay-example copied to clipboard

支付宝 wap 支付回调时 The private_key parameter is required

Open mingyun opened this issue 8 years ago • 8 comments

composer.json 使用的包 "lokielse/omnipay-alipay": "1.0.1", 支付页面

public function aliPayWap($subject, $out_trade_no, $fee){
        $gateway = Omnipay::create('Alipay_WapExpress');
        $gateway->setPartner($partner);//变量从配置文件获取
        $gateway->setKey($key);
        $gateway->setSellerEmail($email);
        $gateway->setNotifyUrl($notify);
        $gateway->setReturnUrl($return);
        $gateway->setCancelUrl($cancel);
        $order = array(
            'out_trade_no' => $out_trade_no, //your site trade no, unique
            'subject'      => $subject, //order title
            'total_fee'    => $fee,
        );
        $response = $gateway->purchase($order)->send();
        $url = $response->getRedirectUrl();
        return $url;
     }

wap 端输入密码支付,成功然后跳转支付同步回调页面

       $gateway = Omnipay::create('Alipay_WapExpress');
        $gateway->setPartner($partner);//变量从配置文件获取
        $gateway->setKey($key);
        $gateway->setSellerEmail($email);
        $options['request_params'] = Input::all();
        $options['ca_cert_path'] = storage_path() . DIRECTORY_SEPARATOR . 'cert' . DIRECTORY_SEPARATOR . 'cacert.pem';
        $options['sign_type'] = 'MD5';
        $request = $gateway->completePurchase($options)->send();// 这行报错The private_key parameter is required
        $debug_data = $request->getData();
        if ($request->isSuccessful()) {
       }

mingyun avatar Jun 20 '17 08:06 mingyun

@lokielse 麻烦指教

mingyun avatar Jun 21 '17 06:06 mingyun

如果回调通知参数sitn_typeRSA时,需要设置商户私钥进行验证:$gateway->setPrivateKey('xxx')

lokielse avatar Jun 21 '17 07:06 lokielse

@lokielse $options['sign_type'] = 'MD5'; 不是RSA,而且提示

Fatal error: Call to undefined method Omnipay\Alipay\WapExpressGateway::setPrivateKey()

mingyun avatar Jun 21 '17 09:06 mingyun

  • setPrivateKey是一个实例方法,不是类方法,你需要在实例上调用
  • 在回调的时候,sign_type需要从支付宝回调的数据中获取

lokielse avatar Jun 21 '17 09:06 lokielse

@lokielse 谢谢回复

  1. 支付宝回调的链接为 xxx.com?out_trade_no=88888&request_token=requestToken&result=success&trade_no=88888&sign=1f5fe402c623b53558b20081c52155e5&sign_type=MD5
  2. setPrivateKey是在实例上调用的
  3. 看完整代码吧
        $gateway = Omnipay::create('Alipay_WapExpress');//这个没问题吧?
        $gateway->setPartner($partner);//变量从配置文件获取
        $gateway->setKey($key);
        $gateway->setSellerEmail($email);
        $gateway->setPrivateKey('xxxx');
        $options['request_params'] = Input::all();
        $options['ca_cert_path'] = storage_path() . DIRECTORY_SEPARATOR . 'cert' . DIRECTORY_SEPARATOR . 'cacert.pem';
        $options['sign_type'] = 'MD5';
        $request = $gateway->completePurchase($options)->send();// 这行报错The private_key parameter is required
        $debug_data = $request->getData();
        if ($request->isSuccessful()) {
           
       }

mingyun avatar Jun 21 '17 10:06 mingyun

你可能用的是老版本,不排除是本库代码有问题。

建议你使用最新版的Alipay_AopWap网关或者Alipay_LegacyWap网关

使用说明见:

https://github.com/lokielse/omnipay-alipay/wiki/Aop-WAP-Gateway

https://github.com/lokielse/omnipay-alipay/wiki/Legacy-WAP-Gateway

lokielse avatar Jun 21 '17 10:06 lokielse

谢谢,因为是 2 年前使用的 1.0.1 分支的 lokielse/omnipay-alipay, 当时没有做 wap 端支付宝支付,现在不能升级使用 2.0 分支的代码,有什么办法?

mingyun avatar Jun 21 '17 10:06 mingyun

用这个吧,是老版本的最后一个版本,bug相对较少。

"lokielse/omnipay-alipay": "dev-legacy"

lokielse avatar Jun 21 '17 11:06 lokielse