37 lines
1.4 KiB
Python
37 lines
1.4 KiB
Python
# -*- coding: utf-8 -*-
|
|
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
|
from urllib.parse import quote
|
|
|
|
from odoo import http
|
|
from odoo.http import request
|
|
|
|
|
|
class Home(http.Controller):
|
|
@http.route('/WW_verify_fC7AX158Ffby8Ed1.txt', type='http', auth="public")
|
|
def WW_verify_UP42BAWNwtWK60RH(self):
|
|
return 'fC7AX158Ffby8Ed1'
|
|
|
|
@http.route('/wechat/login', type='http', auth="none", methods=['GET'])
|
|
def wechat_login(self):
|
|
'''
|
|
返回wechat login 的链接
|
|
'''
|
|
base_url = request.env['ir.config_parameter'].sudo().get_param('web.base.url')
|
|
redirect_uri = quote(f'{base_url}/wechat/login_by_code')
|
|
# urlencode redirect_uri python
|
|
redirect_uri = redirect_uri.replace(' ', '%20')
|
|
|
|
|
|
appid = 'wwc955c117b738b052'
|
|
agent_id = '1000120'
|
|
url = f'https://open.weixin.qq.com/connect/oauth2/authorize?appid={appid}&redirect_uri={redirect_uri}&response_type=code&scope=snsapi_base&state=STATE&agentid={agent_id}#wechat_redirect'
|
|
return http.request.redirect(url, 301, False)
|
|
|
|
@http.route('/wechat/login_by_code', typ='http', auth="none", methods=['GET'])
|
|
def wechat_login_by_code(self, code):
|
|
|
|
provider = request.env.ref('yuthon_wechat.wechat_corp_web_auth_oauth_provider')
|
|
(db, login, code) = request.env['res.users'].sudo().auth_oauth_wechat(provider.sudo(), {'code': code})
|
|
|
|
return (db, login, code)
|