微信网页授权,获取地理位置 | 您所在的位置:网站首页 › 微信要获取地理位置 › 微信网页授权,获取地理位置 |
OAuth2.0网页授权 官方网站:http://oauth.net/ http://oauth.net/2/ 权威定义:OAuth is An open protocol to allow secure authorization in a simple and standard method from web, mobile and desktop applications. OAuth是一个开放协议,允许用户让第三方应用以安全且标准的方式获取该用户在某一网站、移动或桌面应用上存储的私密的资源(如用户个人信息、照片、视频、联系人列表),而无需将用户名和密码提供给第三方应用。 OAuth 2.0是OAuth协议的下一版本,但不向后兼容OAuth 1.0。 OAuth 2.0关注客户端开发者的简易性,同时为Web应用,桌面应用和手机,和起居室设备提供专门的认证流程。 OAuth允许用户提供一个令牌,而不是用户名和密码来访问他们存放在特定服务提供者的数据。每一个令牌授权一个特定的网站(例如,视频编辑网站)在特定的时段(例如,接下来的2小时内)内访问特定的资源(例如仅仅是某一相册中的视频)。这样,OAuth允许用户授权第三方网站访问他们存储在另外的服务提供者上的信息,而不需要分享他们的访问许可或他们数据的所有内容。 新浪微博API目前也使用OAuth 2.0。 微信官方文档 https://mp.weixin.qq.com/wiki/17/c0f37d5704f0b64713d5d2c37b468d75.html 不是很完善 网页授权域名填写 填写域名即可 将MP_verify_CvTI87TanTCtnz9M.txt文件放在根目录即可 python实现: 1.获取用户点击的url 授权获取code 1 def get_url(): 2 url = 'https://open.weixin.qq.com/connect/oauth2/authorize' 3 data = collections.OrderedDict() 4 data['appid'] = 'xxxxxxxxx' ### 5 data['redirect_uri'] = 'https://xxxxxxxxxxx' 6 data['response_type'] = 'code' 7 data['scope'] = 'snsapi_userinfo' 8 data['state'] = '123' 9 wei_url = url + '?' +urllib.urlencode(data) + '#wechat_redirect' 10 return wei_url用户点击url后 redirect_uri 收到返回的code 2.通过code获取用户openid access_token 1 def get_openid(code): 2 url = 'https://api.weixin.qq.com/sns/oauth2/access_token' 3 data = collections.OrderedDict() ####按插入顺序排序的字典 4 data['appid'] = 'xxxxxxx' 5 data['secret'] = 'xxxxxxxxxxxxx' 6 data['code'] = code 7 data['grant_type'] = 'authorization_code' 8 data = urllib.urlencode(data) 9 ss = requests.session() 10 req = ss.post(url, data=data, verify = False) 11 cont = json.loads(req.content) 12 print cont 13 errcode = cont.get('errcode',None) 14 if errcode is not None: 15 return cont.get('errcode') 16 access_token= cont['access_token'] 17 openid= cont['openid'] 18 expires_in = cont['expires_in'] 19 refresh_token = cont['refresh_token'] 20 scope = cont['scope'] 3.获取用户地理位置 在开发中心>接口权限>对话服务中开启获取用户地理位置(我开启的是用户对话是上报位置) 在基本配置中启用服务器配置(这个配置开启后自定义菜单将不能使用,需要再开发) 配置url 用于接收微信事件推送,token与该文件中一致 EncodingAESKey 随机生成即可 php文件接收,将位置信息post python接口,写库 1
|
CopyRight 2018-2019 实验室设备网 版权所有 |