python自学

腾讯后台对接接口案例

2019-01-14  本文已影响4人  数据小菜鸟

不管前端后端涉及到三方平台都需要对接三方平台。按照文档一步一步操作。往往可以解决问题。中途也会几经波折。只有处理过的这类工作的人才深有体会。所以才衍生出 易接sdk 这类公司。这里提供思路。三方集成sdk(成熟,全面)-> 平台强硬要求自己的对接。所以技术在手,靠自己丰衣足食。这里给撸一段腾讯的对接接口。至少自己以后可以回顾自己。如果对你有帮助我也很替你开心。

# -*- coding: utf-8 -*-
# chenxiaoyumail@gmail.com
# 腾讯对接细节案例
# 主流web 接口 md5(使用key + context + 时间戳) 或 类md5 非加密
# 代码可以运行 由于商业已经把key appid id 给弄掉了。直接套用自己的即可使用

import os,sys
import urllib2
import hashlib
import time

def md5hex(word):
    """ MD5加密算法,返回32位小写16进制符号 """ 
    if isinstance(word, unicode): 
        word = word.encode("utf-8") 
    elif not isinstance(word, str): 
        word = str(word) 
    m = hashlib.md5() 
    m.update(word) 
    return m.hexdigest()


#文档网址
#http://wiki.open.qq.com/wiki/YSDK%E5%90%8E%E5%8F%B0%E6%8E%A5%E5%8F%A3

t = int(time.time())

reqhttp = 'http://ysdktest.qq.com/auth/qq_check_token?'
appid='appid'
openid='openid'
openkey='openkey'
AppKey='AppKey'

sig=md5hex(AppKey+str(t))

url = reqhttp + 'timestamp={}&appid={}&sig={}&openid={}&openkey={}'.format(str(t),appid,sig,openid,openkey) 
req = urllib2.Request(url) # url 转换成发起get 请求的url  
result = urllib2.urlopen(req) # 发起GET http服务  
res = result.read() #把结果通过.read()函数读取出来
print "AppKey",AppKey
print url
print res


'''
openid=''
openkey=''

reqhttp = 'http://ysdktest.qq.com/auth/wx_check_token?'
appid='appid'
wxAppKey='wxAppKey'
sig=md5hex(wxAppKey+str(t))
url = reqhttp + 'timestamp={}&appid={}&sig={}&openid={}&openkey={}'.format(str(t),appid,sig,openid,openkey) 
req = urllib2.Request(url) # url 转换成发起get 请求的url  
result = urllib2.urlopen(req) # 发起GET http服务  
res = result.read() #把结果通过.read()函数读取出来
print "AppKey",wxAppKey
print url
print res
'''

运行结果.png
上一篇 下一篇

猜你喜欢

热点阅读