关于向金数据的表单通过开发接口添加数据代码

<?php
// +----------------------------------------------------------------------
// | 蜜蜂到店
// +----------------------------------------------------------------------
// | Copyright (c) 2017 https://xxxxx All rights reserved.
// +----------------------------------------------------------------------
// | Author: rainfer 季书歌  QQ:568554428   邮箱:568554428@qq.com
// +----------------------------------------------------------------------
// | 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":""}}

 

转载于:https://my.oschina.net/jishuge/blog/1815200

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值