Files
spacestation/common/libraries/CarHome.php
T
chenrx 6553c5b9b4 111
2024-05-27 14:58:26 +08:00

112 lines
4.5 KiB
PHP

<?php
defined('BASEPATH') or exit('No direct script access allowed');
use GuzzleHttp\Client;
use GuzzleHttp\Exception\GuzzleException;
class CarHome
{
const METHOD_GET = 'GET';
const METHOD_POST = 'POST';
const SAVE_ORDER = 'https://ahohcrm-test.autohome.com.cn/api/community/outOrder/saveOrderInfo';
// const SAVE_ORDER = 'http://127.0.0.1:8000/user/cc';
const KEY = 'ahoh-crm-apiA0EoJwyA';
const SECRET = 'lDMDpzflU3gj';
public function __construct()
{
$this->client = new Client();
}
//outSystemCode int 是 外部系统编号 1001 爱能
//buyerType int 是 购⻋主体 1个⼈ 2公户
//buyerName String 是 客户姓名 不超过50个字符
//buyerPhone String 是 客户⼿机号
//specId int 是 之家⻋型ID 之家提供⻋型数据
//storeId int 是 之家空间站ID 之家提供空间站与⼆⽹城市对应关系
//outOrderId String 是 外部订单号
//outLeadId String 是 外部线索id
//outOrderCreateTime Date 是 订单创建时间 yyyy-MM-dd HH:mm:ss
//registerCityId int 是 城市ID 需确认是否统⼀
//invoiceAmount double 否 开票价格
//isRegisterInStore int 否 是否店内上牌 (0否1是)
//registerAmount double 否 上牌费⽤
//isInsured int 否 是否店内投保商业险 (0否1是)
//isLoan int 否 是否贷款 (0否1是)
//loanAmount double 否 贷款额度
//loanPeriods int 否 贷款期数
//monthlyPayment double 否 ⽉供
//carryCarDate Date 否 提⻋⽇期 yyyy-MM-dd
//payDate Date 否 付款⽇期 yyyy-MM-dd
//contractImg String 否 合同凭证 图⽚URL
//invoiceImg String 否 发票凭证 图⽚URL
//payImg String 否 付款凭证 图⽚URL
//outColor String 否 ⻋身颜⾊
//inColor String 否 内饰颜⾊
//deliveryDate Date 否 期望交付时间 yyyy-MM-dd
//downpaymentType int 否 ⾸付类型 1 现⾦ 2 0⾸付 3按揭
//confirmAmount double 否 定⾦
//discountAmount double 否 ⻋身优惠
//isLocalInvoice int 否 需要开具本地发票 1 是 0 否
//idCardNo String 否 身份证/营业执照号
//carDocumentImg String 否 ⻋辆证件 图⽚URL
//insuranceImg String 否 保险单 图⽚URL
//deliveryPhoto String 否 交⻋合照 图⽚URL
//priceRightsConfirmDoc String 否 买贵必赔权益确认书⽚ 图⽚URL
//返回结果 {"returncode":0,"message":null,"result":{“autohomeOrderId”:3162}}
/**
* 提交订单信息
* @param $data
* @return array|void
* @throws GuzzleException
*/
public function saveOrder($data)
{
try {
$data['outSystemCode'] = 1001;
debug_log("post_data:" . json_encode($data, JSON_UNESCAPED_UNICODE));
$req = $this->send(self::SAVE_ORDER, $data, self::METHOD_POST);
debug_log("result:" . $req);
$reqArr = json_decode($req, true);
if (isset($reqArr['returncode']) && intval($reqArr['returncode']) == 0) {
return ['code' => 1, 'message' => '操作成功', 'data' => $reqArr['result']];
} else {
return ['code' => 0, 'message' => $reqArr['message']];
}
} catch (Exception $e) {
return ['code' => 0, 'message' => $e->getMessage()];
}
}
/**
* 参数
* @return string
*/
public function authorization()
{
$res = "Basic " . base64_encode(self::KEY . ':' . self::SECRET);
return $res;
}
public function send($url, $data = [], $type = self::METHOD_GET)
{
try {
$options = [
'headers' => [
'Content-Type' => 'application/json',
'Authorization' => $this->authorization()
],
];
if ($data) {
$options['json'] = $data;
}
$response = $this->client->request($type, $url, $options);
return $response->getBody()->getContents();
} catch (GuzzleException $e) {
debug_log($e->getMessage() . ' URL: ' . $url . ' Data: ' . json_encode($data));
throw $e;
}
}
}