Esempio n. 1
0
 def SendCode(self):
     if self.postStr == '':
         return False,'参数异常'
     
     headers = {"Content-type": "application/json; charset=UTF-8", \
                "Accept": "application/json"}
     conn = None
     response = None
     backdata = ''
     try:
         conn = httplib.HTTPSConnection(host)
         #print 'CONN',conn
         conn.request('POST', self.URL, self.postStr, headers)
         
         #返回格式{"respCode":"00112"}
         response = conn.getresponse()
         backdata = response.read(5000)
         #print backdata
     except:
         return False,'验证码发送失败'
     
     #backdata = '{"result": {"respCode": "00000","failCount": "0","smsId":"b2e5f6d04fe34390b91b2f46028ee358","createDate":"2015-12-07 14:52:58"}}'
     #返回结果分析,正常样例{"result": {"respCode": "00000","failCount": "0",
     #"smsId":"0cdcf095ee4d4e0f8bb766053f134b34","createDate":"2015-12-07 14:41:37"}}
     if 'respCode' in backdata:
         try:
             _dict = JsonRequest(backdata)
             result = _dict.get('result',None)
             #print 'result',result
             if result is not None:
                 respCode = result.get('respCode','')
                 #print 'respCode',respCode
                 if u'00000' == respCode:
                     return True,'[0]成功'
                 else:
                     return False,'[1]验证码发送失败,可能需要重发,短信平台响应码'+respCode
             else:
                 print 'backdata',backdata
                 return False,'[2]短信平台返回信息异常,短信验证码可能未成功下发'
         except:
             return False,'[3]短信平台返回信息异常,短信验证码可能未成功下发'
     else:
         return False,'[4]短信平台异常'+backdata        
Esempio n. 2
0
def get_access_token():
    try:
        headers = {\
                       "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8"}
        url = GlobalVar.wxHost + '/cgi-bin/token?grant_type=client_credential&appid=' \
            + GlobalVar.appid + '&secret=' + GlobalVar.secret
        conn = httplib.HTTPSConnection(GlobalVar.wxHost)
        conn.request('GET',url,None,headers)
        response = conn.getresponse()
        backdata = response.read(5000)
        
        #{"access_token":"ACCESS_TOKEN","expires_in":7200}
        if 'access_token' in backdata:
            _dict = JsonRequest(backdata)
            GlobalVar.access_token = _dict.get('access_token','')
            print 'access_token ok:',backdata
        else:
            print 'access_token error:',backdata
            
    except:
        #GlobalVar.access_token = ''
        pass