php 百度有钱花分期API

百度分期还没有公开

PHP DEMO

<?php

  $url = 'https://umoney.baidu.com/edu/openapi/post';      // 线上环境

// RSA加密数据

$userInfo = array(
    'username' => '姓名',
    'mobile' => '手机',
    'email' => '180069002@qq.com',
);

$userInfo = enrsa($userInfo);

 $corpid = '申请到机构ID';
 $arrParams = array(
     'action' => 'sync_order_info',
     'tpl' => $corpid,// 分配的tpl   duiawang
     'corpid' => $corpid,// 分配的corpida   duiawang
     'orderid' => 'order'.rand(13,900000),// 机构订单号2a
     'money' => 332200,// 期望贷款额度(分单位)  最低1000元
     'period' => 3,// 期数
     'courseid' =>  'xxxx4402006',//需要申请,通过后能用
     'coursename' => '课程A',// 课程名称
     'oauthid' => '1aa23',// 用户id 机构方提供
     'data' => $userInfo,
     'dealmoney' => 424000,
     'addrtype' => 1,
 );


$_keyConf = array(
       $corpid  => 'Av2ghfhf7xue',
);


$strSecretKey = $_keyConf[$corpid];// 分配的key
$arrParams['sign'] = createBaseSign($arrParams, $strSecretKey);
 print_r($arrParams);


//print_r($arrParams);die;

// 发送请求post(form)
$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($arrParams));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_URL, $url);
$ret = curl_exec($ch);

$http_status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
$result = json_decode($ret, true);

$result['from'] = $url;
echo "<pre>";
print_r($result);



/**
 * @param $data
 * @return string
 * rsa 加密
 */
function enrsa($data){

    $public_key = '-----BEGIN PUBLIC KEY-----
MIGfMA0G/IghfjghfghfRia3zQfxGv/qEkyGOx+XALVoOlZqDwh76o
2n1vP1D+gfhmHsK7QIDAQAB
-----END PUBLIC KEY-----';

    $pu_key = openssl_pkey_get_public($public_key);
    $str	= json_encode($data);
    $encrypted = "";

    // 公钥加密  padding使用OPENSSL_PKCS1_PADDING这个
    if (openssl_public_encrypt($str, $encrypted, $pu_key, OPENSSL_PKCS1_PADDING)){
        $encrypted = base64_encode($encrypted);
    }

    return $encrypted;
}

/**
 * @param $param
 * @param string $strSecretKey
 * @return bool|string
 * 生成签名
 */
function createBaseSign($param, $strSecretKey){
    if (!is_array($param) || empty($param)){
        return false;
    }
    ksort($param);
    $concatStr = '';
    foreach ($param as $k=>$v) {
        $concatStr .= $k.'='.$v.'&';
    }
    $concatStr .= 'key='.$strSecretKey;
    echo $concatStr;
    return strtoupper(md5($concatStr));
}

1.     机构IDcorpid :xxxxx

2.     产品编码(tpl : xxxxxx

3.     生成sign使用的key :  xxxxx

4.     RSA公钥在代码demo

注意:

1、订单ID,是唯一的,如果在百度APP中已经填写了资料,但是需要修改资料或者金额之类的,只能重新生成订单

2、课程编码ID  这个要自己公司定义好,然后再通过百度生成对应的ID,这个课程ID才能,

实际上就是用来定义申请的金额和分期期数。相当先要在百度那里申请好额度然后才能用。

联调环境地址为:http://rdtest.umoney.baidu.com/edu/openapi/post
沙盒环境地址为:http://test.umoney.baidu.com/edu/openapi/post
正式环境地址为:http://umoney.baidu.com/edu/openapi/post

 

官方文档下载:https://download.csdn.net/download/haibo0668/10744493

 

 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值