thinkphp3.2新版支付宝集成_可沙箱测试

沙箱会在每周日中午12点至周一中午12点维护

Tip: SDK需要php5.5及以上. 

  1. 下载 SDK 将文件将重命名AlipaySdk后放至文件夹 Vendor,
  2. 打开\AlipaySdk\lotusphp_runtime\shortcut.php 将 C函数变更为CC(由于函数与TP的C函数重复)
  3. Vendor(‘AlipaySdk.AopSdk’);
  4. 调用示例;
Vendor('AlipaySdk.AopSdk');
$aop = new \AopClient ();
$aop->gatewayUrl = 'https://openapi.alipaydev.com/gateway.do';
$aop->appId = '3333333333';
$aop->rsaPrivateKey = '见密钥生成工具';
$aop->apiVersion = '1.0';
$aop->signType = 'RSA2';
$aop->postCharset= 'utf-8';
$aop->format='json';
$request = new \AlipayTradePagePayRequest ();
$request->setReturnUrl('http://v1.xxxx.com/Home/Test/order');
$request->setNotifyUrl('http://v1.xxxxx.com');
$request->setBizContent('{"product_code":"FAST_INSTANT_TRADE_PAY","out_trade_no":"20170320010101002","subject":"Iphone7 16G","total_amount":"18.88","body":"Iphone6 16G"}');

相关资料

RSA签名工具 选择 PKCS1 2048

在新版本的即时到账支持沙箱测试,也就是说不用真正付钱也可以测试支付功能。

沙箱环境

即时到账

电脑网站支付demo

生成RSA密钥

15 Replies to “thinkphp3.2新版支付宝集成_可沙箱测试”

      1. 很不错,AopSdk,web、wap、app支付都能用,判断一下改改参数就可以了

        case ‘web’:
        $productcode = ‘FAST_INSTANT_TRADE_PAY’;
        $request = new \AlipayTradePagePayRequest();
        break;
        case ‘wap’:
        $productcode = ‘QUICK_WAP_PAY’;
        $request = new \AlipayTradeWapPayRequest();
        break;
        case ‘mobile’:
        $aop->alipayrsaPublicKey = file_get_contents(“./xxx/xxx/xxx/alipay/alipay_public_key.txt”);
        $productcode = ‘QUICK_MSECURITY_PAY’;
        $request = new \AlipayTradeAppPayRequest();
        break;
        case ‘refund’:
        $aop->alipayrsaPublicKey = file_get_contents(“./xxx/xxx/xxx/alipay/alipay_public_key.txt”);
        $request = new \AlipayTradeRefundRequest();
        break;

  1. public function setBizContent($bizContent)
    {
    $this->bizContent = $bizContent;
    $this->apiParas[“biz_content”] = $bizContent;
    }
    关键是这样就实现支付宝的支付了么,好像还少点步骤吧,官方给出的例子最后是:

    $response = $aop->pagePay($payRequestBuilder,$config[‘return_url’],$config[‘notify_url’]);
    //输出表单
    var_dump($response);

    能给点完整的例子么,大神?

  2. 刚又仔细看了下,我知道了,就少了一句而已:
    $response = $aop->Execute($request);

    //输出表单
    var_dump($response);

    谢谢楼上两位大神指点迷津,小弟正好用上。

    1. public function ordersuc(){
      Vendor(‘Alipay.AopSdk’);
      $aop = new \AopClient ();
      $aop->gatewayUrl = ‘https://openapi.alipaydev.com/gateway.do’;
      $aop->appId = ‘2016080600179616’;
      $aop->rsaPrivateKey = ‘MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAgvpGdKl0YgJkak8pYpxpFjb9/F3U9Ic2SpXGPcGO8i1mfGtgeHQaAMQRo/XMilFlnUrUVwJZFMIm3hqyzH/ZH+d+p8vWVhnNhj/Xi4kCjyXGALjC7aYGfPx6Pa98BXnH5haQFeNpJQ0nwVvrzBIl+NmANa+DRRRoCv5m/lrWrEXvjzQVlcQMqjucecVOD4SKF5ElFUalYxvB7hjpBclQTm6grWpfLQcEclhsyda5UInQ8vPtzm0Q8cA7ASNH4qDrmZjTFPeEuxiefX4wMMhzaw3Owl3672uWHjPoXk54gMZ2eY5TgDB2D7xlQqD4qiZbVFTBaqFHhKAkgzuPkkEocwIDAQAB’;
      $aop->apiVersion = ‘1.0’;
      $aop->signType = ‘RSA2’;
      $aop->postCharset= ‘utf-8′;
      $aop->format=’json’;
      $request = new \AlipayTradePagePayRequest ();
      $request->setReturnUrl(‘http://www.dcb.com/Home/Cart/order_ok’);
      $request->setNotifyUrl(‘http://www.dcb.com/Home/Cart/order_ok’);
      $request->setBizContent(‘{“product_code”:”FAST_INSTANT_TRADE_PAY”,
      “out_trade_no”:”20170320010101002″,
      “subject”:”Iphone7 16G”,”total_amount”:”18.88″,
      “body”:”Iphone6 16G”}’);

      // $productcode = ‘QUICK_WAP_PAY’;
      $response = $aop->Execute($request);
      var_dump($response);

      $this->setPageInfo(‘下单成功’, ‘下单成功’, ‘下单成功’, 1, array(‘success’));
      $this->display();
      }

      我在tp中这样执行,,但是报错误
      🙁
      Call to undefined function openssl_sign()
      错误位置
      FILE: C:\AppServ\www\dcb\ThinkPHP\Library\Vendor\Alipay\aop\AopClient.php  LINE: 104
      我已经把PHP的配置文件 extension=php_openssl.dll修改过了,,但还是不行。。。。

  3. alipay_public_key.txt 是支付宝应用公钥
    setBizContent 中的参数之间不要有空格
    /**
    * 新版支付宝接口调用
    * */
    public function newbuildRequestForm() {
    Vendor(‘Alipay.AopSdk’);
    $aop = new \AopClient();
    $aop->appId = ‘xxxxxxxxxxxxxxx’;
    $aop->signType = ‘RSA2’;
    $aop->rsaPrivateKey = file_get_contents(“./xxx/xxx/rsa_private_key.txt”);
    $type = $vo->getPayMethod();
    switch ($type) {
    case ‘web’://web支付
    $productcode = ‘FAST_INSTANT_TRADE_PAY’;
    $request = new \AlipayTradePagePayRequest();
    $request->setReturnUrl(‘http://www.xxx.com/xxx/return’);
    break;
    case ‘wap’://wap支付
    $productcode = ‘QUICK_WAP_PAY’;
    $request = new \AlipayTradeWapPayRequest();
    $request->setReturnUrl(‘http://www.xxx.com/xxx/return’);
    break;
    case ‘app’://app支付
    $aop->alipayrsaPublicKey = file_get_contents(“./xxx/xxx/alipay_public_key.txt”);
    $productcode = ‘QUICK_MSECURITY_PAY’;
    $request = new \AlipayTradeAppPayRequest();
    break;
    case ‘refund’://退款
    $aop->alipayrsaPublicKey = file_get_contents(“./xxx/xxx/alipay_public_key.txt”);
    $request = new \AlipayTradeRefundRequest();
    break;
    default:
    $productcode = ‘FAST_INSTANT_TRADE_PAY’;
    $request = new \AlipayTradePagePayRequest();
    break;
    }
    $request->setNotifyUrl(‘http://www.xxx.cpm/xxx/notify’);

    switch ($type) {
    case ‘web’:
    $request->setBizContent(‘{“product_code”:”‘.$productcode.'”,”body”:”‘.$body.'”,”subject”:”‘.$subject.'”,”total_amount”:”‘.$total_amount.'”,”out_trade_no”:”‘.$out_trade_no.'”}’);
    return $aop->pageExecute ($request,’POST’);
    break;
    case ‘wap’:
    /*参数 out_trade_no:系统订单号*/
    $request->setBizContent(‘{“product_code”:”‘.$productcode.'”,”body”:”‘.$body.'”,”subject”:”‘.$subject.'”,”total_amount”:”‘.$total_amount.'”,”out_trade_no”:”‘.$out_trade_no.'”}’);
    return $aop->pageExecute ($request,’GET’);
    break;
    case ‘app’:
    /*参数 out_trade_no:系统订单号*/
    $request->setBizContent(‘{“body”:”‘.$body.'”,”subject”:”‘.$subject.'”,”out_trade_no”:”‘.$out_trade_no.'”,”timeout_express”:”30m”,”total_amount”:”‘.$total_amount.'”,”product_code”:”‘.$productcode.'”}’);
    $response = $aop->sdkExecute($request);
    return $response;
    break;
    case ‘refund’:
    /*参数 out_trade_no:系统订单号 trade_no:支付宝订单号 refund_amount:退款金额 out_request_no:退款请求号 refund_reason:退款原因*/
    $request->setBizContent(‘{“out_trade_no”:””,”trade_no”:”‘.$trade_no.'”,”refund_amount”:”‘.$refund_amount.'”,”out_request_no”:””,”refund_reason”:”调单”}’);
    $result = $aop->execute($request);
    $responseNode = str_replace(“.”, “_”, $request->getApiMethodName()) . “_response”;
    $resultCode = $result->$responseNode->code;
    if(!empty($resultCode)&&$resultCode == 10000){
    return “退款成功”;
    } else {
    return “退款失败”;
    }
    break;
    }

    }

发表评论

电子邮件地址不会被公开。 必填项已用*标注