<?php
// +----------------------------------------------------------------------
// | 蜜蜂到店
// +----------------------------------------------------------------------
// | Copyright (c) 2017 https://xxxxx All rights reserved.
// +----------------------------------------------------------------------
// | Author: rainfer 季書歌 QQ:568554428 郵箱:[email protected]
// +----------------------------------------------------------------------
// | Description: 金數據的數據API
// +----------------------------------------------------------------------
class JinshujuEntryApi
{
protected $appKey; //API Key 可以在金數據的個人中心找到,https://help.jinshuju.net/articles/api-auth.html
protected $appSecre; //API Secret
protected $urlApi; //這是金數據v1版本的api地址
public function __construct($appKey,$appSecre)
{
$this->appKey=$appKey;
$this->appSecre=$appSecre;
$this->urlApi="https://xxx.jinshuju.com/api/v1/forms/";//企業版本,xxx表示企業版的特有域名
// $this->urlApi="https://jinshuju.net/api/v1/forms/";//個人版本
}
/**
* 向接口發送數據
* @param $formName 這個是表單的ID,比如個人版的地址是:https://jinshuju.net/f/xxxxxxx,這個就是指的xxxxxxx部分,不需要'/'
* @param $sendDataArray 這是傳入的參數,數組格式比如:['field_1'=>"季書歌",'field_2'=>"18684xx8559"];
* @return mixed
*/
public function SendJinshuju($formName,$sendDataArray){
$stringData=http_build_query($sendDataArray);
$url=$this->urlApi.$formName.'?'.$stringData;
$headers=['accept:Application/json','Content-type'=>'application/json'];
$result=$this->https_request($url,$headers);
return $result;
}
/**
* curl 發送函數
* @param $url
* @param $headers
* @param $data 只要不爲null和空就行,隨便填什麼都可以,不然不會成功
* @return mixed
*/
private function https_request($url, $headers,$data="demo")
{
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_USERPWD, "{$this->appKey}:{$this->appSecre}");
if (!empty($data)){
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
}
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($curl);
curl_close($curl);
return $output;
}
}
//調用
//$JinShuJuObj=new JinshujuEntryApi("F65z7hdm******tb4LA","TUPupo6******KiE2AJw");
//
//$array=['field_1'=>"王思琪",'field_2'=>"18184641047"];
//
////假如這是你表單的地址:https://jinshuju.net/f/Wx4T9X,那麼$formName="Wx4TMX";
//
//$formName="Wx4TMX";
//
//$result = $JinShuJuObj->SendJinshuju($formName,$array);
//
//var_dump($result);
//{"form":"Wx4T9X","form_name":"金數據測試接口測試","entry":{"serial_number":59,"field_1":"王思琪","field_2":"18184641047","field_3":"","field_4":"","creator_name":"即刻到店","created_at":"2018-04-27T12:46:29.880Z","updated_at":"2018-04-27T12:46:29.880Z","info_remote_ip":""}}