diff --git a/examples.py b/examples.py index 6e3081a..66449ad 100644 --- a/examples.py +++ b/examples.py @@ -3,13 +3,14 @@ from wechatpayv3 import WeChatPay, WeChatPayType -wxpay = WeChatPay(wechatpay_type=WeChatPayType.MINIPROG, - mchid=MCHID, - mch_parivate_key=MCH_PRIVATE_KEY, - mch_key_serial_no=MCH_KEY_SERIAL_NO, - wechat_certificate=WECHAT_CERTIFICATE, - appid=APPID, - notify_url=NOTIFY_URL) +wxpay = WeChatPay( + wechatpay_type=WeChatPayType.MINIPROG, + mchid=MCHID, + mch_parivate_key=MCH_PRIVATE_KEY, + mch_key_serial_no=MCH_KEY_SERIAL_NO, + wechat_certificate=WECHAT_CERTIFICATE, + appid=APPID, + notify_url=NOTIFY_URL) def certificate(): @@ -18,10 +19,11 @@ def certificate(): def pay(): - code, message = wxpay.pay(description='demo-description', - out_trade_no='demo-trade-no', - amount={'total': 100}, - payer={'openid': 'demo-openid'}) + code, message = wxpay.pay( + description='demo-description', + out_trade_no='demo-trade-no', + amount={'total': 100}, + payer={'openid': 'demo-openid'}) print('code: %s, message: %s' % (code, message)) @@ -36,9 +38,10 @@ def close(): def refund(): - code, message = wxpay.refund(transaction_id='demo-transation-id', - out_refund_no='demo-out-refund-no', - amount={'refund': 100, 'total': 100, 'currency': 'CNY'}) + code, message = wxpay.refund( + transaction_id='demo-transation-id', + out_refund_no='demo-out-refund-no', + amount={'refund': 100, 'total': 100, 'currency': 'CNY'}) print('code: %s, message: %s' % (code, message)) @@ -64,8 +67,15 @@ def download_bill(): def combine_pay(): - code, message = wxpay.combine_pay(combine_out_trade_no='demo_out_trade_no', sub_orders=[{'mchid': '1900000109', 'attach': '深圳分店', 'amount': { - 'total_amount': 100, 'currency': 'CNY'}, 'out_trade_no': '20150806125346', 'description': '腾讯充值中心-QQ会员充值', 'settle_info': {'profit_sharing': False, 'subsidy_amount': 10}}]) + code, message = wxpay.combine_pay( + combine_out_trade_no='demo_out_trade_no', + sub_orders=[{'mchid': '1900000109', + 'attach': '深圳分店', + 'amount': {'total_amount': 100, 'currency': 'CNY'}, + 'out_trade_no': '20150806125346', + 'description': '腾讯充值中心-QQ会员充值', + 'settle_info': {'profit_sharing': False, 'subsidy_amount': 10}}], + combine_payer_info={'openid':'oUpF8uMuAJO_M2pxb1Q9zNjWeS6o'}) print('code: %s, message: %s' % (code, message)) @@ -76,8 +86,9 @@ def combine_query(): def combine_close(): - code, message = wxpay.combine_close(combine_out_trade_no='demo_out_trade_no', sub_orders=[ - {'mchid': '1900000109', 'out_trade_no': '20150806125346'}]) + code, message = wxpay.combine_close( + combine_out_trade_no='demo_out_trade_no', + sub_orders=[{'mchid': '1900000109', 'out_trade_no': '20150806125346'}]) print('code: %s, message: %s' % (code, message)) diff --git a/setup.py b/setup.py index 58d2b1e..b00f4f8 100644 --- a/setup.py +++ b/setup.py @@ -6,7 +6,7 @@ setup( name="wechatpayv3", - version="0.46", + version="0.47", author="minibear", description="微信支付接口V3版python库", long_description=long_description, diff --git a/wechatpayv3/api.py b/wechatpayv3/api.py index 3c66dc2..eccde40 100644 --- a/wechatpayv3/api.py +++ b/wechatpayv3/api.py @@ -109,9 +109,7 @@ def close(self, out_trade_no): if not out_trade_no: raise Exception('out_trade_no is not assigned.') path = '/v3/pay/transactions/out-trade-no/%s/close' % out_trade_no - params = {} - params['mchid'] = self._mchid - params['out_trade_no'] = out_trade_no + params = {'mchid': self._mchid} return self._core.post(path, data=params) def query(self, transaction_id=None, out_trade_no=None): @@ -158,7 +156,7 @@ def refund(self, else: raise Exception('amount is not assigned.') if transaction_id: - params.update({'transation_id': transaction_id}) + params.update({'transaction_id': transaction_id}) if out_trade_no: params.update({'out_trade_no': out_trade_no}) if reason: diff --git a/wechatpayv3/core.py b/wechatpayv3/core.py index ae15e31..ec77f17 100644 --- a/wechatpayv3/core.py +++ b/wechatpayv3/core.py @@ -32,7 +32,7 @@ def get(self, path): return -1, '{"message": "微信支付平台证书序号不一致"}' if not verify_response(timestamp, nonce, body, signature, self._wechat_certificate): return -1, '{"message": "应答签名验证失败"}' - return response.status_code, response.content + return response.status_code, response.text def post(self, path, data=None): headers = {} @@ -56,4 +56,4 @@ def post(self, path, data=None): return -1, '{"message": "微信支付平台证书序号不一致"}' if not verify_response(timestamp, nonce, body, signature, self._wechat_certificate): return -1, '{"message": "应答签名验证失败"}' - return response.status_code, response.content + return response.status_code, response.text