婷婷综合国产,91蜜桃婷婷狠狠久久综合9色 ,九九九九九精品,国产综合av

主頁 > 知識庫 > python公司內項目對接釘釘審批流程的實現

python公司內項目對接釘釘審批流程的實現

熱門標簽:西青語音電銷機器人哪家好 百應電話機器人總部 宿州電話機器人哪家好 旅游廁所地圖標注怎么弄 南昌地圖標注 電梯新時達系統外呼顯示e 無錫智能外呼系統好用嗎 地圖標注與注銷 成都呼叫中心外呼系統哪家強

最近把組內的一個項目對接釘釘審批接口,通過python3.6。

釘釘官方文檔

廢話不多說了,上代碼:

import requests
import json
import time
from dingtalk.crypto import DingTalkCrypto

from django.conf import settings
# settings.BASE_DIR


class Crypto(object):
    def __init__(self, token):
        # 隨便填的字符串
        self.token = token
        # 自己生成的43位隨機字符串
        self.aes_key = settings.DINGDING.get("DINGTALK_AES_TOKEN")
        # 釘釘企業ID
        self.corp_id = settings.DINGDING.get("CorpId") #
        print("corp_id:", self.corp_id)
        self.nonce = settings.DINGDING.get("nonce")
        self.crypto = DingTalkCrypto(
            token=self.nonce,
            encoding_aes_key=self.aes_key,
            corpid_or_suitekey=self.corp_id
        )

    def encrypt_success(self):
        # 返回加密success
        result = self.crypto.encrypt_message(
            msg="success",
            nonce=self.nonce,
            timestamp=int(time.time()*1000)
        )
        return result


class DING(object):
    def __init__(self, approve_process):
        self.AgentId = settings.DINGDING.get("AgentId")
        self.AppKey = settings.DINGDING.get("AppKey")
        self.AppSecret = settings.DINGDING.get("AppSecret")
        self.dingding_url = settings.DINGDING.get("URL")
        self.process_code = settings.DINGDING.get("APPROVE_PROCESS").get(approve_process)['process_code']
        self.aes_key = settings.DINGDING.get("DINGTALK_AES_TOKEN")
        self.nonce = settings.DINGDING.get("nonce")

    def get_token(self):
        '''
        獲取釘釘的token
        :return: 釘釘token
        '''
        url = self.dingding_url + '/gettoken?appkey={}appsecret={}'.format(self.AppKey, self.AppSecret)
        req = requests.get(url)
        req = json.loads(req.text)
        return req['access_token']

# def createCallbackDd():
#     '''
#     注冊釘釘回調函數
#     :return:
#     '''
#     url = 'https://oapi.dingtalk.com/call_back/register_call_back?access_token=' + self.getToken()
#     data = {
#         "call_back_tag": ["bpms_task_change", "bpms_instance_change"],  #這兩個回調種類是審批的
#         "token": TOKEN,  #自定義的字符串
#         "aes_key": AES_KEY, #自定義的43位字符串,密鑰
#         "url": URL  #回調地址
#     }
#     requests.post(url, data=json.dumps(data))
#     return ('OK')

    def create_process(self, originator_user_id, dept_id, form_component_value_vo, approvers, cc_list, has_cc=0):
        '''
        創建釘釘審批
        approvers為list 元素為釘釘userid   cc_list同理
        '''
        url = self.dingding_url + '/topapi/processinstance/create?access_token=' + self.get_token()
        print("form_component_value_vo:", form_component_value_vo)
        if has_cc == 0:
            data = {
                'agent_id': self.AgentId,
                'process_code': self.process_code,  #工單id
                'originator_user_id': originator_user_id,
                'dept_id': dept_id,  #創建人的釘釘部門id
                'form_component_values': str(form_component_value_vo), #釘釘后臺配置的需要填寫的字段,
                'approvers': approvers,
                'cc_list': cc_list,
                'cc_position': 'START_FINISH'  # 發起和完成時與抄送
            }
        else:
            data = {
                'agent_id': self.AgentId,
                'process_code': self.process_code,  #工單id
                'originator_user_id': originator_user_id, #創建人的釘釘userid
                'dept_id': dept_id,  #創建人的釘釘部門id
                'form_component_values': str(form_component_value_vo), #釘釘后臺配置的需要填寫的字段,
                'approvers': approvers,
            }
        print("dingding_utils:", data)
        response = requests.post(url, data=data)
        return response.json()

    def get_status(self, process_instance_id):
        url = self.dingding_url + '/topapi/processinstance/get?access_token=' + self.get_token()
        data = {
            "process_instance_id": process_instance_id
        }
        response = requests.post(url, data=data)
        return response.json()

    def register_callback(self, call_back_url):
        # 注冊回調
        url = self.dingding_url + '/call_back/register_call_back?access_token=' + self.get_token()
        print("self.get_token():", self.get_token())
        data = {
            "call_back_tag": ['bpms_task_change', 'bpms_instance_change'],
            "token": self.nonce,
            "aes_key": self.aes_key,
            "url": call_back_url,
        }
        response = requests.post(url, data=json.dumps(data))
        return response.json()

    def get_callback(self):
        url = self.dingding_url + '/call_back/get_call_back?access_token=' + self.get_token()
        req = requests.get(url)
        req = json.loads(req.text)
        return req

    def create_process_approver_v2(self, originator_user_id, dept_id, form_component_value_vo, approvers, cc_list):
        '''
        創建釘釘審批
        '''
        url = self.dingding_url + '/topapi/processinstance/create?access_token=' + self.get_token()
        data = {
            'agent_id': self.AgentId,
            'process_code': self.process_code,
            'originator_user_id': originator_user_id,
            'dept_id': dept_id,
            'form_component_values': str(form_component_value_vo),
            'approvers_v2': json.dumps(approvers)
        }
        if cc_list:
            data['cc_list'] = cc_list
            data['cc_position'] = 'FINISH'

        response = requests.post(url, data=data)
        return response.json()

    def create_process_approver_v2_test(self, originator_user_id, dept_id, form_component_value_vo):
        '''
        創建釘釘審批
        '''
        url = self.dingding_url + '/topapi/processinstance/create?access_token=' + self.get_token()
        data = {
            'agent_id': self.AgentId,
            'process_code': self.process_code,
            'originator_user_id': originator_user_id,
            'dept_id': dept_id,
            'form_component_values': str(form_component_value_vo),
            'approvers_v2': json.dumps([
                {
                    "task_action_type": "NONE",
                    "user_ids": ["dingding_id"],   # 單獨審批人
                },
                {
                    "task_action_type": "OR",
                    "user_ids": ["dingding_id1", "dingding_id2"],   # 或簽
                },
                {
                    "task_action_type": "AND",
                    "user_ids": ["dingding_id1", "dingding_id2"],  # 會簽
                }
            ])
        }

        response = requests.post(url, data=data)
        return response.json()


if __name__ == "__main__":

    import django, os, sys
    sys.path.append('xxxxxx')   # 項目路徑
    os.environ['DJANGO_SETTINGS_MODULE'] = 'xx.settings'
    # print("settings.DINGDING", settings.DINGDING)
    ding = DING("create_xx")
    # print(ding.get_token())
    # info = [{'name': '單行輸入框','value': 'testixxxxxxxx'}]
    # # print(ding.create_process('11', 11, info))
    a = [
        {'name': "輸入框1", 'value': "value1"},
        {'name': "輸入框2", 'value': "value2"},
    ]
    # print(ding.create_process_test('11', 11, a))
    # print(ding.create_process_approver_v2_test('11', 11, a))
    # print(ding.create_process_test2())
    # print(ding.get_status('xxx'))
    print(ding.get_status('xx'))

    # # 驗證  回調
    # a = ding.get_token()
    # print(a)
    # c = Crypto(a)
    # print(c.encrypt_success())

    # 注冊回調
    # print(ding.register_callback("http://xxxx.vaiwan.com/xxx"))
    # print(ding.get_callback())

說明:

  1 Crypto類用于對接釘釘回調用的。一個公司只有一個corpId,并且一個corpid只能注冊一個回調地址。我司有公共組注冊好了回調。只要接入公司內的回調即可。所以我實際沒有使用到Crypto。

  2  在釘釘管理后臺中創建應用后會有這三個東西:AgentId、AppKey,AppSecret  。在創建釘釘審批流程,可以從審批流程瀏覽器中獲取到APPROVE_PROCESS。別忘啦給這個流程審批接口權限。這些官方文檔有說。

  3  配置setting變量:

DINGDING = {
    "AgentId": 123,
    "AppKey": "xx",
    "AppSecret": "xx",
    "URL": "https://oapi.dingtalk.com",
    "APPROVE_PROCESS": { # process_code
        "create_xx": {
            "process_code": "abc", # 審批流程的id
    },
    "DINGTALK_AES_TOKEN": "abc",
    "nonce": "abc",
    "CorpId": "abc",
}

 4 接口形式創建的審批流程,與釘釘管理后臺創建的流程有一些不同:

    1 不能在不同的審批環節設置不同的抄送人

    2 不能審批流程前后有相同的人,不能自動顯示成 “自動同意”(管理后臺設置成去重后,但是接口指定審批人場景,不支持)

 5 其他如:審批內容、或簽,會簽代碼里都有示例。

到此這篇關于python公司內項目對接釘釘審批流程的實現的文章就介紹到這了,更多相關python對接釘釘審批內容請搜索腳本之家以前的文章或繼續瀏覽下面的相關文章希望大家以后多多支持腳本之家!

您可能感興趣的文章:
  • Python實現釘釘發送報警消息的方法
  • python3實現釘釘消息推送的方法示例
  • python 調用釘釘機器人的方法
  • python釘釘機器人運維腳本監控實例
  • Python制作釘釘加密/解密工具
  • Python第三方包之DingDingBot釘釘機器人
  • 如何基于python對接釘釘并獲取access_token
  • 詳解使用python3.7配置開發釘釘群自定義機器人(2020年新版攻略)
  • python使用自定義釘釘機器人的示例代碼
  • Python 實現 T00ls 自動簽到腳本代碼(郵件+釘釘通知)
  • 淺談Python 釘釘報警必備知識系統講解
  • Python釘釘報警及Zabbix集成釘釘報警的示例代碼

標簽:辛集 贛州 七臺河 雅安 渭南 西安 濰坊 許昌

巨人網絡通訊聲明:本文標題《python公司內項目對接釘釘審批流程的實現》,本文關鍵詞  python,公司,內,項目,對接,;如發現本文內容存在版權問題,煩請提供相關信息告之我們,我們將及時溝通與處理。本站內容系統采集于網絡,涉及言論、版權與本站無關。
  • 相關文章
  • 下面列出與本文章《python公司內項目對接釘釘審批流程的實現》相關的同類信息!
  • 本頁收集關于python公司內項目對接釘釘審批流程的實現的相關信息資訊供網民參考!
  • 推薦文章
    主站蜘蛛池模板: 尉犁县| 蒙自县| 玛曲县| 郴州市| 鹤山市| 内黄县| 德清县| 浮山县| 甘南县| 钦州市| 梅州市| 大安市| 巩义市| 江源县| 香河县| 荔浦县| 东明县| 宣化县| 黎城县| 华安县| 柯坪县| 龙游县| 姚安县| 潞西市| 年辖:市辖区| 马山县| 闽侯县| 宁阳县| 荔浦县| 济阳县| 郸城县| 宜川县| 和林格尔县| 阿图什市| 长春市| 涞水县| 武定县| 台州市| 朔州市| 吴江市| 都兰县|