1. 程式人生 > >php 百度分期API

php 百度分期API

百度分期還沒有公開

PHP DEMO

<?php

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

// RSA加密資料

$userInfo = array(
    'username' => '沈XX',
    'mobile' => '18739082520',
    'email' => '[email protected]',
);

$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(
       'zhongda'  => 'Av2VRt7xue',
);


$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、