python之獲取微信access_token


# -*- coding: cp936 -*-
#python 27
#xiaodeng



#獲取微信access_token
#辦法一:將該url直接填寫到瀏覽器地址中可以獲得access_token
url='https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=wxc0f4d0ed1cb2f4e1&secret=c4d72d33cacf8c94845ac906ad60eed6'


#辦法二
import urllib
url='https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential'#grant_type為固定值
data={'appid':'wxc0f4d0ed1cb2f4e1',
      'secret':'c4d72d33cacf8c94845ac906ad60eed6'}

data=urllib.urlencode(data)
html=urllib.urlopen(url,data)#<addinfourl at 34758208 whose fp = <socket._fileobject object at 0x0212F570>>
html= html.read()
print html
'''
{"access_token":"Isd_tm3QE8Kateyxjz_WEEXuerBZ0gnO6XwyjirZXY1umVIDqebi6GK2Zv2fv1hI7sXQfHXeaOa2A4XrOITwS5LnczFRXf4BbSnMdSRLKiwBQYgADASHP",
"expires_in":7200}  #expires_in,定義access_token有效時間,單位為秒
'''

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM