123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- # -*- coding: utf-8 -*-
- import json
- from odoo import http
- from odoo.http import request
- from .base import BaseController
- import logging
- _logger = logging.getLogger(__name__)
- class WxappMessage(http.Controller, BaseController):
- @http.route('/<string:sub_domain>/test', auth='public', methods=['GET'])
- def test(self, sub_domain, **kwargs):
- if not sub_domain:
- sub_domain = 'main'
- return self.res_ok("{'center':'" + sub_domain + "'}")
- @http.route('/apply-company', auth='public', methods=['POST'], csrf=False)
- def check_company(self, **kwargs):
- company_name, company_number = self._get_params(['company', 'number'])
- if not company_name:
- return self.res_err(600, u'缺少参数:公司 company')
- if not company_number:
- return self.res_err(600, u'缺少参数:识别码 number')
- company_code = self._query_company_code(company_name, company_number)
- if not company_code:
- return self.res_err(700, u'公司、识别码错误')
- return self.res_ok({'code': company_code})
- def _get_params(self, param_list):
- if not param_list:
- return None
- param_values = []
- try:
- encrypt_type = request.params.get('encrypt_type', 'raw')
- if encrypt_type == 'raw':
- if request.httprequest.data:
- dic = json.loads(request.httprequest.data)
- for p in param_list:
- param_values.append(dic.get(p, None))
- else:
- for p in param_list:
- v = request.httprequest.values[p] if p in request.httprequest.values else None
- param_values.append(v)
- return param_values
- else:
- _logger.info(u'>>> ===error===未处理的请求类型')
- return None
- except Exception as e:
- _logger.info(u'>>> ===error===获取参数出错:' + str(e))
- return None
- def _query_company_code(self, company_name, company_number):
- return request.env(user=1)['wxapp.company'].query_code(company_name, company_number)
|