示例#1
0
 def post(self, request):
     args = self._get_args(request)
     weixin = WeixinMpAPI(**args)
     if not weixin.validate_signature():
         raise AttributeError("Invalid weixin signature")
     xml_str = self._get_xml(request.body)
     crypt = WXBizMsgCrypt(token, encoding_aeskey, appid)
     decryp_xml, nonce = self._decrypt_xml(request.raw_args, crypt, xml_str)
     xml_dict = xmltodict.parse(decryp_xml)
     xml = WXResponse(xml_dict)() or 'success'
     encryp_xml = self._encryp_xml(crypt, xml, nonce)
     return text(encryp_xml or xml)
示例#2
0
def get_weixinmp_token(appid, app_secret, is_refresh=False):
    from weixin import WeixinMpAPI
    from weixin.oauth2 import (ConnectTimeoutError, ConnectionError,
                               OAuth2AuthExchangeError)
    try:
        api = WeixinMpAPI(appid=appid,
                          app_secret=app_secret,
                          grant_type='client_credential')
        token = api.client_credential_for_access_token().get('access_token')
        return token, None
    except (OAuth2AuthExchangeError, ConnectTimeoutError,
            ConnectionError) as ex:
        return None, ex
示例#3
0
 def get(self, request):
     args = self._get_args(request)
     weixin = WeixinMpAPI(**args)
     if weixin.validate_signature():
         return text(args.get('echostr') or 'fail')
     return text('fail')
示例#4
0
 def get(self):
     args = self._get_args()
     weixin = WeixinMpAPI(**args)
     if weixin.validate_signature():
         return args.get('echostr') or 'fail'
     return 'fail'