张 永 一个梦想自由的程序员

——————————————— 让科技和智能使人更便捷 ———————————————
  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

使用PHP语言, 如何 只需一步调用,创建支付宝代扣

Posted on 2024-03-26 14:05  hylas  阅读(17)  评论(0编辑  收藏  举报
使用php语言, 如何 只需一步调用,创建支付宝代扣
 
 


  在很多场景下, 支付不是需要立即支付; 而是按月分期支付。 如何创建为期一年的按月的支付宝代扣呢。 经过搜索有,发现网上有提供 API。 
只需要一个 API 调用就能实现创建按期支付。 消费客户用户,通过链接,签名授权,即可。 这也使很多 saas 还有会员制的收费方式更加便捷。 
https://www.cnblogs.com/xiaoxuebiye/articles/18096498

目标

原理

"# alilite_php"


<?php

require_once 'GatewaySdk.php';

$appId = "999999"; //   App ID  向客户经理申请

$sdk = new GatewaySdk($appId);




$payload = [
    'timestamp' => 1711347382,
    'content' => [
        'extTradeNo' => '1711347382',
        'redirectUrl' => 'https://host/your_success_webpage.php',  //回跳地址
        'company' => [
            'id' => 'cnogda7i2dkqvfosk',  //收款公司信息
            'name' => '浙江某科技有限公司',
        ],
        'customer' => [
            'extId' => 'user_002',  //付款用户信息
            'name' => '张某',  //付款用户信息
            'addr' => '杭州市西湖区', //付款用户信息
            'phone' => '13958040000', //付款用户信息
            'idCard' => '331002190000000', //付款用户信息,支付宝用此帐号签约收款
        ],
        'product' => [
            'extId' => 'product_002', //产品信息,
            'name' => '恰恰香瓜子',  
            'price' => '1.00',
            'Content' => '好吃',
        ],
        'installment' => [   //付款信息,
            'limit' => 1.00, //总金额
            'first' => 0.01, //暂无效
            'num' => 2,      //分2个月支付
            'type' => 'SDI', //固定
        ],
    ],
];

try {
    $sdk->post('gate/liteContract/create', $payload);
    echo "POST request successful.\n";
} catch (\RuntimeException $e) {
    echo "Failed to send POST request: " . $e->getMessage() . "\n";
}

请求与返回

curl -X POST \
     -H "Content-Type: application/json" \
     -H "X-Gateway-AppId: 999999" \
     -d '{"timestamp":1711347382,"content":{"extTradeNo":"1711347382","redirectUrl":"https://geekland.cc","company":{"id":"cnogda7i2dkqvf","name":"浙江某科技有限公司"},"customer":{"extId":"user_002","name":"张某","addr":"杭州市西湖区","phone":"13958040000","idCard":"3310021981000000"},"product":{"extId":"product_002","name":"恰恰香瓜子","price":"1.00","Content":"好吃"},"installment":{"limit":1.00,"first":0.01,"num":2,"type":"SDI"}}}' \
     https://open.xiadandt.com/gate/liteContract/create


{
  "code": 0,
  "content": {
    "contractId": "co0hdgni2dkrn7or4m8g",
    "customer": {
      "extId": "user_002",
      "name": "张某",
      "addr": "杭州市西湖区",
      "phone": "13958040000",
      "idCard": "33100219810412251X"
    },
    "bill": [
      {
        "index": 1,
        "days": "2024-03-25T08:00:00+08:00",
        "amount": 0.5
      },
      {
        "index": 2,
        "days": "2024-04-25T08:00:00+08:00",
        "amount": 0.5
      }
    ],
    "signUrl": "https://u.alipay.cn/_eLriCTVod5djaQX9hEFxd",
    "status": 12
  },
  "msg": "创建成功"
}

申请 APPID

联系客服