コード例 #1
0
ファイル: cjbase1.py プロジェクト: shijunhong/jiaojiewendang
    def  cjmyhttpjs(self, method, url_path=None, post_data=None, token=None):# 传json格式
        self.url = self.base_url + url_path
        print self.url
        self.signature = generateSignature(self.nonce, method, self.url)
        # params = urllib.urlencode(post_data)
        # print  params
        encoded = encryptAES(post_data, self.key)
        data = {'data': encoded}
        payload = urllib.urlencode(data) #字典编码成字符串
        jdata = json.dumps(post_data)
        print jdata
        headers = {
            'User-Agent': 'chunmiapp',
            'signature': self.signature,
            'token': token,
            'Content-Type': 'application/json',
            'nonce': self.nonce}
        if method == 'POST':
            request = urllib2.Request(self.url, data=jdata, headers=headers)

        if method == 'GET':
            url2 = self.url + '?' + payload
            request = urllib2.Request(url2, headers=headers)
            print 'url2 :', url2
        response = urllib2.urlopen(request)
        result = response.read()
        s = decryptAES(result, self.key)
        # print s
        return s
コード例 #2
0
ファイル: cjbase.py プロジェクト: shijunhong/jiaojiewendang
 def cjmyhttp(self, method, url_path=None, post_data=None, token=None):
     url = self.base_url + url_path
     print url
     self.signature = generateSignature(self.nonce, method, url)
     print 'signature的值:', self.signature
     params = urllib.urlencode(post_data)
     encoded = encryptAES(params, self.key)
     data = {'data': encoded}
     payload = urllib.urlencode(data)
     headers = {
         'nonce': self.nonce,
         'User-Agent': 'chunmiapp',
         'signature': self.signature,
         'token': token
     }
     if method == 'GET':
         url2 = url + '?' + payload
         request = urllib2.Request(url2, headers=headers)
         # response = urllib2.urlopen(request)
         # result = response.read()
         # s = decryptAES(result, self.key)
         # return s
     if method == 'POST':
         request = urllib2.Request(url, data=payload, headers=headers)
         # response = urllib2.urlopen(request)
         # result = response.read()
         # s = decryptAES(result, self.key)
         # return s
     response = urllib2.urlopen(request)
     result = response.read()
     s = decryptAES(result, self.key)
     return s
コード例 #3
0
ファイル: cjbase1.py プロジェクト: shijunhong/jiaojiewendang
    def cjmyhttp(self,method, url_path=None,params=None,token=None):
        url = self.base_url + url_path
        print url
        self.signature = generateSignature(self.nonce, method, url)
        params = urllib.urlencode(params)
        encoded = encryptAES(params, self.key)
        data = {'data': encoded}
        payload = urllib.urlencode(data)
        # print "打印payload:%s" %payload
        print type(payload)
        headers = {'nonce': self.nonce,
                   'User-Agent': 'chunmiapp',
                   'signature': self.signature,
                   # "Accept": "application/json;charset=UTF-8",
                   #  "contentType": "application/json",
                   'token': token
                   }
        if method == 'GET':

            r=requests.get(url,params=data,headers=headers)

        if method == 'POST':
            # request = urllib2.Request(url, data=payload, headers=headers)
            r = requests.post(url, data=payload, headers=headers)


        result = r.text.encode()


        # print "打印result:%s" % result
        print "打印result类型:%s" % type(result)
        s = decryptAES(result, self.key)
        # print s
        return s