Python教程

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

本文主要是介绍Python调用纷享销客CRM开放平台API,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

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

#!/usr/bin/env python
# -*- coding:utf-8 -*-
# Author:wangzhifeng@tongdog.com.cn
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咨询:wangzhifeng@tongdog.com.cn

这篇关于Python调用纷享销客CRM开放平台API的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!