コード例 #1
0
ファイル: tests.py プロジェクト: Jaccorot/weixin_pay
    def test_calculate_sign(self):
        params = {"123": "123"}
        key = "12345678901234567890"
        sign = calculate_sign(params, key)
        expect_sign = hashlib.md5("123=123&key=%s"%key).hexdigest().upper()
        self.assertEqual(sign, expect_sign)

        params = {"abc": "abc", "123": "123"}
        sign = calculate_sign(params, key)
        expect_sign = hashlib.md5("123=123&abc=abc&key=%s" % key).hexdigest().upper()
        print sign
        self.assertEqual(sign, expect_sign)
コード例 #2
0
    def test_calculate_sign(self):
        params = {"123": "123"}
        key = "12345678901234567890"
        sign = calculate_sign(params, key)
        expect_sign = hashlib.md5("123=123&key=%s" % key).hexdigest().upper()
        self.assertEqual(sign, expect_sign)

        params = {"abc": "abc", "123": "123"}
        sign = calculate_sign(params, key)
        expect_sign = hashlib.md5("123=123&abc=abc&key=%s" %
                                  key).hexdigest().upper()
        print sign
        self.assertEqual(sign, expect_sign)
コード例 #3
0
ファイル: weixin_pay.py プロジェクト: Jaccorot/weixin_pay
 def post_xml(self):
     sign = calculate_sign(self.params, self.api_key)
     xml = dict_to_xml(self.params, sign)
     print xml
     response = post_xml(self.url, xml)
     print '*' * 5, response.text
     return xml_to_dict(response.text)
コード例 #4
0
 def _get_json_js_api_params(self, prepay_id):
     js_params = {
                  "appId": self.appid,
                  "timeStamp": "%d" % time.time(),
                  "nonceStr": random_str(32),
                  "package": "prepay_id=%s" % prepay_id,
                  "signType": "MD5",
                 }
     js_params["paySign"] = calculate_sign(js_params, self.api_key)
     return js_params
コード例 #5
0
 def _get_json_js_api_params(self, prepay_id):
     js_params = {
         "appId": self.appid,
         "timeStamp": "%d" % time.time(),
         "nonceStr": random_str(32),
         "package": "prepay_id=%s" % prepay_id,
         "signType": "MD5",
     }
     js_params["paySign"] = calculate_sign(js_params, self.api_key)
     return js_params
コード例 #6
0
ファイル: pay.py プロジェクト: geerniya/test
    def _request(self, method, api_endpoint, **kwargs):
        url = '{0}{1}'.format(self.API_BASE_URL, api_endpoint)
        params = kwargs['params']
        params['appId'], params['merchantId'] = self.appid, self.merchant_id

        # 生成签名和随机数
        # 特殊处理wxSubAppId(该参数不加入签名)
        if api_endpoint == 'api/pay/micropay':
            _params = copy.copy(params)
            if _params.get('wxSubAppId'):
                del _params['wxSubAppId']
            random_string, sign = calculate_sign(self.appsecret, _params)
        else:
            random_string, sign = calculate_sign(self.appsecret, params)

        params['random'], params['sign'] = random_string, sign

        res = self._http.request(method=method, url=url, json=params)
        res.raise_for_status()

        
        
        # 处理返回结果
        return self.handle_result(res)
コード例 #7
0
 def post_xml(self):
     sign = calculate_sign(self.params, self.api_key)
     xml = dict_to_xml(self.params, sign)
     response = post_xml(self.url, xml)
     return xml_to_dict(response.text)