Python调用纷享销客CRM开放平台API

使用Python调用纷享销客CRM开放平台API接口:

#!/usr/bin/env python
# -*- coding:utf-8 -*-
# Author:[email protected]
import requests
import json

class fxiaoke():

    #构造方法
    def __init__(self, AppID,APPSecret,permanentCode,currentOpenUserId):
        
        self.AppID = AppID
        self.APPSecret = APPSecret
        self.permanentCode = permanentCode
        self.currentOpenUserId = currentOpenUserId
        self.headers = {"Content-Type":"application/json; charset=utf-8"}
        self.getCorpAccessToken()
    
    #获取CorpAccessToken
    def getCorpAccessToken(self):

        url = "https://open.fxiaoke.com/cgi/corpAccessToken/get/V2"
        #请求参数
        postdata = {
            "appId":self.AppID,
            "appSecret":self.APPSecret,
            "permanentCode":self.permanentCode
        } 
        #print(postdata)
        result = json.loads(requests.post(url,data=json.dumps(postdata),headers=self.headers).text)
        self.corpAccessToken = result["corpAccessToken"]
        self.corpId = result["corpId"]

    #根据手机号获取人员信息
    def getByMobile(self,mobile):
        url = "https://open.fxiaoke.com/cgi/user/getByMobile"
        #请求参数
        postdata = {
            "corpId":self.corpId,
            "corpAccessToken":self.corpAccessToken,
            "mobile":mobile
        } 
        #print(postdata)
        result = json.loads(requests.post(url,data=json.dumps(postdata),headers=self.headers).text)
        return result
    
    #查询对象列表
    def getObjList(self,data):
        url = "https://open.fxiaoke.com/cgi/crm/v2/data/query"
        #请求参数
        postdata = {
            "corpId":self.corpId,
            "corpAccessToken":self.corpAccessToken,
            "currentOpenUserId":self.currentOpenUserId,
            "data":data
        } 
        print(postdata)
        result = json.loads(requests.post(url,data=json.dumps(postdata),headers=self.headers).text)
        return result

if __name__ == '__main__':
    fxiaoke = fxiaoke("纷享自建应用的appId","纷享自建应用的appSecret","授权码permanentCode","当前操作人currentOpenUserId")
    data = {
        "dataObjectApiName":"AccountObj",
        "search_query_info":{
            "limit":3,
            "offset":0,
            "filters":[
                {
                    "field_name":"life_status",
                    "field_values":["normal"],
                    "operator":"N"
                }
                
            ],
            "orders":[
                {
                    "fieldName": "create_time",
                    "isAsc": "false"
                }
            ]
        }
    }
    print(fxiaoke.getObjList(data))

纷享销客CRM咨询:[email protected]

你可能感兴趣的:(python,开发语言,后端)