接入Gobelieve IM开发平台的DEMO代码

许自强
2023-12-01

接入Gobelieve IM开发平台的DEMO代码,

请求头部: Authorization: Basic $base64(appid:$hex_md5(appsecret))
意思是 appsecret 做md5 得到SS,之后appid:SS 做base64

 1 # -*- coding: utf-8 -*-
 2 import struct
 3 import socket
 4 import threading
 5 import time
 6 import requests
 7 import json
 8 import uuid
 9 import base64
10 import md5
11 import sys
12 from protocol import *
13 
14 KEFU_APP_ID = 1453
15 KEFU_APP_KEY = "xQrfaJPgfc5DsWuNUKcn4DMSWJUR4fcr"
16 KEFU_APP_SECRET = "ozj9rROFg3GmiqSa8kRBagNubf52BHlz"
17 
18 APP_ID = 7
19 APP_KEY = "sVDIlIiDUm7tWPYWhi6kfNbrqui3ez44"
20 APP_SECRET = '0WiCxAU1jh76SbgaaFC7qIaBPm2zkyM1'
21 HOST = "127.0.0.1"
22 URL = "http://dev.api.gobelieve.io"
23 
24 
25 def _login(appid, app_secret, uid):
26     url = URL + "/auth/grant"
27     obj = {"uid":uid, "user_name":str(uid)}
28     secret = md5.new(app_secret).digest().encode("hex")
29     basic = base64.b64encode(str(appid) + ":" + secret)
30     headers = {'Content-Type': 'application/json; charset=UTF-8',
31                'Authorization': 'Basic ' + basic}
32      
33     res = requests.post(url, data=json.dumps(obj), headers=headers)
34     if res.status_code != 200:
35         print res.status_code, res.content
36         return None
37     obj = json.loads(res.text)
38     return obj["data"]["token"]

相关接口网址:http://developer.gobelieve.io/static/docs/im/Server.html

转载于:https://www.cnblogs.com/nuanshou/p/10429102.html

 类似资料: