商户号:1630608186
正式环境
APP唤起微信支付传输的数据为: {'appid': 'wx3acec2d59bb7e60b', 'timestamp': '1661420813', 'noncestr': 'Y0Y4TOIUO1UKKHWF056L4QAK', 'prepayid': 'wx251746531438314af953acbba19fd30000', 'partnerid': '1630608186', 'package': 'Sign=WXPay', 'sign': 'msrCXfNHCEwNgGpZbpI3J0XWgcraJL4gRQ3+1gxTRf52/eZLmFAaLksNhOZtHlo8tXQbro0XgBo1Ke43FCjIHgFlaBkWzAZPeqezTCygmT1RYu/XAhVN0fhgGXOlZtqZhZcZEz+7VQDtVFiQbg4ysvPwSCOkIyYas0al2X2kxJ4gLxHT7JjVfjEUg1Lgo0JS+/fg3JKOKGXqtimhWDuwC+2gNFTzmvrjVJ+0vjiTXLc1JOGvgCdmBOGg+KKqnfBt8kV4XnFcSxPp3ySqG5gt5Rr5eDvIlYOtv1BhhunbIigFTQkVQQ7hgK9icq2DUpRrFiXPXiWKI2fG1BFdiVkTfg=='}
我的代码是这样的
import json from wechatpayv3 import WeChatPay,WeChatPayType import settings import os import time import random client = None #得到客户端对象。 async def get_client(): global client if client is None: cur_dir = os.path.dirname(os.path.abspath(__file__)) # 上级目录 # 商户证书私钥 with open(os.path.join(cur_dir,'apiclient_key.pem')) as f: PRIVATE_KEY = f.read() client= WeChatPay( wechatpay_type=WeChatPayType.APP, mchid=settings.weixin_config.mch_id, private_key=PRIVATE_KEY, cert_serial_no=settings.weixin_config.mch_serial_no, apiv3_key=settings.weixin_config.mch_key, appid=settings.weixin_config.appid, notify_url='https://api.21days.cloud/mail/pay/notify/weixin', cert_dir=cur_dir, logger=settings.logger) return client def getRandom(num):#随机数 return ''.join(random.choices('ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789',k=num)) async def get_weixin_pay_url(order_number,total_amount,title,ip): client=await get_client() order_number=str(order_number).replace('-','_')#64个字符以内,仅支持字母、数字 、下划线且需保证在商户端不重复。 code, message = client.pay( description=title or '任务完成奖励', out_trade_no=order_number, amount={'total': int(total_amount*100)}#订单总金额,单位为分,详见支付金额 )#见下方统一下单日志 prepay_id=json.loads(message)['prepay_id'] sign_data = {'appid': settings.weixin_config.appid, 'timestamp': str(int(time.time())), 'noncestr':getRandom(24), 'prepayid': 'prepay_id='+prepay_id, } print(sign_data)#==> {'appid': 'wx3acec2d59bb7e60b', 'timestamp': '1661485406', 'noncestr': 'LV6WBDJRZ48O64AQJBH8CGJS', 'prepayid': 'prepay_id=wx261143266512844af953acbb8606ac0000'} sign = client.sign(sign_data) settings.logger.info(str(sign))#==> 2022-08-26 11:43:26.749 | INFO | apps.utils.weixin.payment:get_weixin_pay_url:75 - msrCXfNHCEwNgGpZbpI3J0XWgcraJL4gRQ3+1gxTRf52/eZLmFAaLksNhOZtHlo8tXQbro0XgBo1Ke43FCjIHgFlaBkWzAZPeqezTCygmT1RYu/XAhVN0fhgGXOlZtqZhZcZEz+7VQDtVFiQbg4ysvPwSCOkIyYas0al2X2kxJ4gLxHT7JjVfjEUg1Lgo0JS+/fg3JKOKGXqtimhWDuwC+2gNFTzmvrjVJ+0vjiTXLc1JOGvgCdmBOGg+KKqnfBt8kV4XnFcSxPp3ySqG5gt5Rr5eDvIlYOtv1BhhunbIigFTQkVQQ7hgK9icq2DUpRrFiXPXiWKI2fG1BFdiVkTfg== sign_data.update({ 'partnerid':settings.weixin_config.mch_id, 'package': 'Sign=WXPay', 'sign': sign, }) return sign_data#见下方返回数据日志
统一下单日志
2022-08-26 11:43:26.402 | DEBUG | wechatpayv3.core:request:110 - Request url: https://api.mch.weixin.qq.com/v3/pay/transactions/app 2022-08-26 11:43:26.402 | DEBUG | wechatpayv3.core:request:111 - Request type: POST 2022-08-26 11:43:26.402 | DEBUG | wechatpayv3.core:request:112 - Request headers: {'Content-Type': 'application/json', 'Accept': 'application/json', 'User-Agent': 'wechatpay v3 api python sdk(https://github.com/minibear2021/wechatpayv3)', 'Authorization': 'WECHATPAY2-SHA256-RSA2048 mchid="1630608186",nonce_str="4B2D084F364B47DA853B2C086C927953",signature="GUYW59jSlQwWs/foZTAnjXu9KaDm/YxSO1h4fcxCYN+OPY89LNYZYusSKpGioabbuHNNFp14iV61Xnt862NG7PRHW4G2qsmS5jQKLhS+cIQlx8tdgCMfi928BFonpDWOHUNsF9DI7sn3ckZQdlvQFp0//t3tMPIP4dbgXjNNM1REO2H/TIyGQ9ToKHR78bJFKoKHH9uXVrxyC8scsEPs1WzBk5BBNfvFycqS8Jy3W74UhOFMJ8E7W9b1eV3LRGg60oz2twtgD9mb2IbMnuENj8DSq2ftLWDfP0sPJcdjOW00wlLya3brvhgGv6XBcISGKthREm/QdR9YA1x9s3XCiA==",timestamp="1661485406",serial_no="52921E8C481362D7C698FDBE8689E153CE35892E"'} 2022-08-26 11:43:26.403 | DEBUG | wechatpayv3.core:request:113 - Request params: {'notify_url': 'https://api.21days.cloud/mail/pay/notify/weixin', 'description': '学霸养成计划-儿童话筒', 'out_trade_no': '20220822224010228111', 'amount': {'total': 1}, 'appid': 'wx3acec2d59bb7e60b', 'mchid': '1630608186'} 2022-08-26 11:43:26.746 | DEBUG | wechatpayv3.core:request:127 - Response status code: 200 2022-08-26 11:43:26.746 | DEBUG | wechatpayv3.core:request:128 - Response headers: {'Server': 'nginx', 'Date': 'Fri, 26 Aug 2022 03:43:26 GMT', 'Content-Type': 'application/json; charset=utf-8', 'Content-Length': '52', 'Connection': 'keep-alive', 'Keep-Alive': 'timeout=8', 'Cache-Control': 'no-cache, must-revalidate', 'X-Content-Type-Options': 'nosniff', 'Request-ID': '08DE82A1980610EC031899B68A4820F4B41428F08C06-0', 'Content-Language': 'zh-CN', 'Wechatpay-Nonce': 'c51908177b3a2e654f50ff8b88c8c817', 'Wechatpay-Signature': 'k60jpew7mlcZp91SVxv86VsSebaqBfvXsQ9nzMjrYzl+guXzs2W1etoUKlPHu92Np/y1Xw1FhWThQDKlyo0lnY/7cyaor3NoD5ThkhTBr+iwZ/XLfdPZMawqa0P3Lll5lTKw9g8RVU44qGl5I12RcJsAfmTi1KG3kGFlYWQmdx6ArcZPuHkDVCgDuM+bKiXvAtN6Ku4dcPnH3xCvbC8tZf3I65qy2NxtiNQIg/jV4Dhqsxt87wQ+vu0iU+5lG+Noaj46u6NChrvpYI4ZByyQm9iz2FafH8gk2tXG6l2OHmoWs4gEybtXp6biMVhKeie92FrO0ycARW2jlk6yJ8mBOg==', 'Wechatpay-Timestamp': '1661485406', 'Wechatpay-Serial': '740C035ED1E90599CDD648697E0C095B82210D26', 'Wechatpay-Signature-Type': 'WECHATPAY2-SHA256-RSA2048'} 返回数据日志 {'appid': 'wx3acec2d59bb7e60b', 'timestamp': '1661485406', 'noncestr': 'LV6WBDJRZ48O64AQJBH8CGJS', 'prepayid': 'prepay_id=wx261143266512844af953acbb8606ac0000', 'partnerid': '1630608186', 'package': 'Sign=WXPay', 'sign': 'msrCXfNHCEwNgGpZbpI3J0XWgcraJL4gRQ3+1gxTRf52/eZLmFAaLksNhOZtHlo8tXQbro0XgBo1Ke43FCjIHgFlaBkWzAZPeqezTCygmT1RYu/XAhVN0fhgGXOlZtqZhZcZEz+7VQDtVFiQbg4ysvPwSCOkIyYas0al2X2kxJ4gLxHT7JjVfjEUg1Lgo0JS+/fg3JKOKGXqtimhWDuwC+2gNFTzmvrjVJ+0vjiTXLc1JOGvgCdmBOGg+KKqnfBt8kV4XnFcSxPp3ySqG5gt5Rr5eDvIlYOtv1BhhunbIigFTQkVQQ7hgK9icq2DUpRrFiXPXiWKI2fG1BFdiVkTfg=='}