1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
| import requests import base64 from Crypto.PublicKey import RSA from Crypto.Cipher import PKCS1_v1_5 as Cipher_pkcs1_v1_5
def encode_RSA(secret): public_key = '''-----BEGIN RSA PUBLIC KEY----- MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAutgI110nsPC7PCq4wseLFd0XGmmaeJW+8qlJs+6YSbEQIDAQAB -----END RSA PUBLIC KEY----- ''' secret = secret.encode('utf-8') rsakey = RSA.importKey(public_key) cipher = Cipher_pkcs1_v1_5.new(rsakey) cipher_text = base64.b64encode(cipher.encrypt(secret)) return cipher_text
def getToken(secret): url = 'http://id:host/api/ec/dev/auth/applytoken' headers = {'appid': 'test','secret':secret} response = requests.post(url, headers=headers ) return response
def createWorkflow(token,userid,param): url = "http://ip:host/api/workflow/paService/doCreateRequest" headers = { 'token': token, 'appid': 'test', 'userid': userid, 'Content-Type' : 'application/x-www-form-urlencoded; charset=utf-8' } response = requests.request("POST", url, headers=headers,data=param) print(response.text)
if __name__ == '__main__': secret = '81ab3d9a83d34ed5b33' secretRSA = encode_RSA(secret) userid = encode_RSA('683') response = getToken(secretRSA) param = { "mainData" : '[ { "fieldName": "lxdlx", "fieldValue": "1" }, { "fieldName": "ngbm", "fieldValue": "111" },{ "fieldName": "ngsj", "fieldValue": "2023-08-29" }, { "fieldName": "ngr", "fieldValue": "683" }, { "fieldName": "cbbm", "fieldValue": "109" }, { "fieldName": "lxdnr", "fieldValue": "api/doCreateRequest测试联系单内容" },{ "fieldName": "lxdfj", "fieldValue": "58377" }, { "fieldName": "bz", "fieldValue": "接口推送流程测试0831" } ]' , "requestName" : "接口推送流程测试0831999", "workflowId" : "105" } if response.status_code == 200 : token = response.json()['token'] createWorkflow(token,userid,param)
|