PHP code example of yjc / alipay-sdk

1. Go to this page and download the library: Download yjc/alipay-sdk library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

yjc / alipay-sdk example snippets

 php

/**
 * Created by PhpStorm.
 * User: YJC
 * Date: 2018/10/29 029
 * Time: 22:32
 * @see https://docs.open.alipay.com/54/106370/
 */

$aop = new \Yjc\Alipay\Aop\AopClient();
$aop->gatewayUrl = "https://openapi.alipay.com/gateway.do";
$aop->appId = "app_id";
$aop->rsaPrivateKey = '请填写开发者私钥去头去尾去回车,一行字符串';
$aop->format = "json";
$aop->charset = "UTF-8";
$aop->signType = "RSA2";
$aop->alipayrsaPublicKey = '请填写支付宝公钥,一行字符串';
//实例化具体API对应的request类,类名称和接口名称对应,当前调用接口名称:alipay.trade.app.pay
$request = new \Yjc\Alipay\Aop\Request\AlipayTradeAppPayRequest();
//SDK已经封装掉了公共参数,这里只需要传入业务参数
$bizcontent = "{\"body\":\"我是测试数据\","
    . "\"subject\": \"App支付测试\","
    . "\"out_trade_no\": \"20170125test01\","
    . "\"timeout_express\": \"30m\","
    . "\"total_amount\": \"0.01\","
    . "\"product_code\":\"QUICK_MSECURITY_PAY\""
    . "}";
$request->setNotifyUrl("商户外网可以访问的异步地址");
$request->setBizContent($bizcontent);
//这里和普通的接口调用不同,使用的是sdkExecute
$response = $aop->sdkExecute($request);
//htmlspecialchars是为了输出到页面时防止被浏览器将关键参数html转义,实际打印到日志以及http传输不会有这个问题
echo htmlspecialchars($response);//就是orderString 可以直接给客户端请求,无需再做处理。