PHP code example of iqianfang / yii2alipay

1. Go to this page and download the library: Download iqianfang/yii2alipay 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/ */

    

iqianfang / yii2alipay example snippets


'components' => [
        'alipay' => [
            'class' => 'iqianfang\yii2alipay\Alipay',
            'config' => [
                //↓↓↓↓↓↓↓↓↓↓请在这里配置您的基本信息↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓
                //合作身份者ID,签约账号,以2088开头由16位纯数字组成的字符串,查看地址:https://b.alipay.com/order/pidAndKey.htm
                'partner' => '2088*****',
                //收款支付宝账号,以2088开头由16位纯数字组成的字符串,一般情况下收款账号就是签约账号
                'seller_id' => '2088*****',
                // MD5密钥,安全检验码,由数字和字母组成的32位字符串,查看地址:https://b.alipay.com/order/pidAndKey.htm
                'key' => '',
                // 服务器异步通知页面路径  需http://格式的完整路径,不能加?id=>123这类自定义参数,必须外网可以正常访问
                'notify_url' => 'payment/alipay-asy-notify',
                // 页面跳转同步通知页面路径 需http://格式的完整路径,不能加?id=>123这类自定义参数,必须外网可以正常访问
                'return_url' => "payment/alipay-sy-notify",
                //签名方式
                'sign_type' => strtoupper('MD5'),
                //字符编码格式 目前支持 gbk 或 utf-8
                'input_charset' => strtolower('utf-8'),
                //ca证书路径地址,用于curl中ssl校验
                //'cacert' => getcwd() . '\\cacert.pem',
                //访问模式,根据自己的服务器是否支持ssl访问,若支持请选择https;若不支持请选择http
                'transport' => 'http',
                // 支付类型 ,无需修改
                //'payment_type' => "1",
                // 产品类型,无需修改
                //'service' => "create_direct_pay_by_user",
                //↑↑↑↑↑↑↑↑↑↑请在这里配置您的基本信息↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑
                //↓↓↓↓↓↓↓↓↓↓ 请在这里配置防钓鱼信息,如果没开通防钓鱼功能,为空即可 ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓
                // 防钓鱼时间戳  若要使用请调用类文件submit中的query_timestamp函数
                'anti_phishing_key' => "",
                // 客户端的IP地址 非局域网的外网IP地址,如:221.0.0.1
                'exter_invoke_ip' => "",
                //↑↑↑↑↑↑↑↑↑↑请在这里配置防钓鱼信息,如果没开通防钓鱼功能,为空即可 ↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑
            ],
        ],
    ],
    

Yii::$app->alipay->submit($order);

class PaymentController extends Controller
{
    /**
     * 关闭csrf,以便异步通知可访问
     * @param \yii\base\Action $action
     * @return bool
     * @author WangTao <[email protected]>
     */
    public function beforeAction($action)
    {
        $this->enableCsrfValidation = false;
        return parent::beforeAction($action); // TODO: Change the autogenerated stub
    }

    /**
     * 响应异步通知请求
     * @author WangTao <[email protected]>
     */
    public function actionAlipayAsyNotify()
    {
        Yii::$app->alipay->asyNotify();
    }

    /**
     * 响应同步通知请求
     * @return string
     * @author WangTao <[email protected]>
     */
    public function actionAlipaySyNotify()
    {
        $rs = Yii::$app->alipay->syNotify();

        return $this->render('alipay-notify', [
            'rs' => $rs
        ]);
    }
}