打印/下载
函数
案例

扩展

dnf install php74-php-bcmath

getPay() : 获取支付参数

static public function getPay(
  string $type //支付方式: 'app','wap','web','transfer'
  array $data //业务数据
  string $notify_url  //异步回调地址
): array

getTransfer() : 转账到支付宝账户

static public function getTransfer(
  array $data //业务数据
): object

getCertSN() : 序列号-证书

static public function getCertSN(
  string $certPath //证书路径
): string

getRootCertSN() : 序列号-根证书

static public function getRootCertSN(
  string $certPath //根证书路径
): string

getSign() : 签名-获取

static public function getSign(
  array $data //数据
): string

getVerify() : 签名-验证

static public function getVerify(
  array $data //数据
): bool
<?php
namespace app\modules\api\controller;

use app\controller\Base;
use app\library\Alipay;

class DemoController extends Base{

  /* 支付宝-支付参数 */
  function alipayAction(){
    $type = $this->request->get('type','string');
    $data = [
      'product_code' => 'QUICK_MSECURITY_PAY',
      'out_trade_no' => date("YmdHis").mt_rand(1000, 9999),
      'total_amount' => 0.01,
      'subject'=> '商品的标题',
      'body' => '商品简单描述',
      'timeout_express' => '15m',
    ];
    $res = Alipay::getPay($type,$data,'https://webmis.vip/api/demo/alipayNotify');
    return self::getJSON(['code'=>0,'url'=>Alipay::$gatewayUrl,'data'=>http_build_query($res)]);
  }

  /* 支付宝-回调 */
  function alipayNotifyAction(){
    $res = $this->request->get();
    /* 验证 */
    unset($res['_url']);
    unset($res['sign_type']);
    if(Alipay::getVerify($res)){
      $order_sn = $res['out_trade_no'];
      // 将参数写入public/tmp.txt文件
      file_put_contents('tmp.txt',json_encode($res));
      // 成功
      echo 'success';
    }else{ echo ''; }
  }

  /* 支付宝-转账到支付宝账户 */
  function alipayTransferAction(){
    $data = [
      'out_biz_no' => date("YmdHis").mt_rand(1000,9999),
      'trans_amount' => 0.1,
      'product_code' => 'TRANS_ACCOUNT_NO_PWD',
      'biz_scene' => 'DIRECT_TRANSFER',
      'order_title' => '提现',
      'payee_info' => ['identity'=>'支付宝预留手机','name'=>'姓名', 'identity_type'=>'ALIPAY_LOGON_ID'],
      'remark' => '现金红包提现',
    ];
    // 转账结果
    $res = Alipay::getTransfer($data);
    print_r($res);
  }

}
{{copy}}