def create_time(self): """ 消息创建时间 ``datetime.datetime`` 类型 """ tz = timezone('Asia/Shanghai') created = datetime.fromtimestamp(self.time, tz) return created
def create(self, trade_type, body, total_fee, notify_url, client_ip=None, user_id=None, out_trade_no=None, detail=None, attach=None, fee_type='CNY', time_start=None, time_expire=None, goods_tag=None, product_id=None, device_info=None, limit_pay=None): """ 统一下单接口 :param trade_type: 交易类型,取值如下:JSAPI,NATIVE,APP,WAP :param body: 商品描述 :param total_fee: 总金额,单位分 :param notify_url: 接收微信支付异步通知回调地址 :param client_ip: 可选,APP和网页支付提交用户端ip,Native支付填调用微信支付API的机器IP :param user_id: 可选,用户在商户appid下的唯一标识。trade_type=JSAPI,此参数必传 :param out_trade_no: 可选,商户订单号,默认自动生成 :param detail: 可选,商品详情 :param attach: 可选,附加数据,在查询API和支付通知中原样返回,该字段主要用于商户携带订单的自定义数据 :param fee_type: 可选,符合ISO 4217标准的三位字母代码,默认人民币:CNY :param time_start: 可选,订单生成时间,默认为当前时间 :param time_expire: 可选,订单失效时间,默认为订单生成时间后两小时 :param goods_tag: 可选,商品标记,代金券或立减优惠功能的参数 :param product_id: 可选,trade_type=NATIVE,此参数必传。此id为二维码中包含的商品ID,商户自行定义 :param device_info: 可选,终端设备号(门店号或收银设备ID),注意:PC网页或公众号内支付请传"WEB" :param limit_pay: 可选,指定支付方式,no_credit--指定不能使用信用卡支付 :return: 返回的结果数据 """ now = datetime.fromtimestamp(time.time(), tz=timezone('Asia/Shanghai')) hours_later = now + timedelta(hours=2) if time_start is None: time_start = now if time_expire is None: time_expire = hours_later if not out_trade_no: out_trade_no = '{0}{1}{2}'.format( self.mch_id, now.strftime('%Y%m%d%H%M%S'), random.randint(1000, 10000) ) data = { 'appid': self.appid, 'device_info': device_info, 'body': body, 'detail': detail, 'attach': attach, 'out_trade_no': out_trade_no, 'fee_type': fee_type, 'total_fee': total_fee, 'spbill_create_ip': client_ip or get_external_ip(), 'time_start': time_start.strftime('%Y%m%d%H%M%S'), 'time_expire': time_expire.strftime('%Y%m%d%H%M%S'), 'goods_tag': goods_tag, 'notify_url': notify_url, 'trade_type': trade_type, 'limit_pay': limit_pay, 'product_id': product_id, 'openid': user_id, } return self._post('pay/unifiedorder', data=data)
This module defines some useful field types for parse WeChat messages :copyright: (c) 2014 by messense. :license: MIT, see LICENSE for more details. """ from __future__ import absolute_import, unicode_literals import time from datetime import datetime import base64 import copy import six from wechatpy.utils import to_text, to_binary, ObjectDict, timezone default_timezone = timezone('Asia/Shanghai') class FieldDescriptor(object): def __init__(self, field): self.field = field self.attr_name = field.name def __get__(self, instance, instance_type=None): if instance is not None: value = instance._data.get(self.attr_name) if value is None: value = copy.deepcopy(self.field.default) instance._data[self.attr_name] = value if isinstance(value, dict): value = ObjectDict(value)
def apply_deduct(self, body, total_fee, contract_id, notify_url, out_trade_no=None, detail=None, attach=None, fee_type='CNY', goods_tag=None, clientip=None, deviceid=None, mobile=None, email=None, qq=None, openid=None, creid=None, outerid=None): """ 申请扣款 api :param body: 商品描述 商品或支付单简要描述 :param out_trade_no: 可选 商户订单号 商户系统内部的订单号,32个字符内、可包含字母, 其他说明见商户订单号 :param total_fee: 总金额 订单总金额,单位为分,只能为整数,详见支付金额 :param contract_id: 委托代扣协议id 签约成功后,微信返回的委托代扣协议id :param notify_url: 回调通知url 接受扣款结果异步回调通知的url :param detail: 可选 商品详情 商品名称明细列表 :param attach: 可选 附加数据 附加数据,在查询API和支付通知中原样返回,该字段主要用于商户携带订单的自定义数据 :param fee_type: 可选 货币类型 符合ISO 4217标准的三位字母代码,默认人民币:CNY :param goods_tag: 可选 商品标记 商品标记,代金券或立减优惠功能的参数,说明详见代金券或立减优惠 :param clientip: 可选 客户端 IP 点分IP格式(客户端IP) :param deviceid: 可选 设备ID android填imei的一次md5; ios填idfa的一次md5 :param mobile: 可选 手机号 用户手机号 :param email: 可选 邮箱地址 用户邮箱地址 :param qq: 可选 QQ号 用户QQ号 :param openid: 可选 微信open ID 用户微信open ID :param creid: 可选 身份证号 用户身份证号 :param outerid: 可选 商户侧用户标识 用户在商户侧的标识 :return: 返回的结果信息 """ trade_type = 'PAP' # 交易类型 交易类型PAP-微信委托代扣支付 timestamp = int(time.time()) # 10位时间戳 spbill_create_ip = get_external_ip() # 终端IP 调用微信支付API的机器IP if not out_trade_no: now = datetime.fromtimestamp(time.time(), tz=timezone('Asia/Shanghai')) out_trade_no = '{0}{1}{2}'.format( self.mch_id, now.strftime('%Y%m%d%H%M%S'), random.randint(1000, 10000) ) data = { "appid": self.appid, "mch_id": self.mch_id, "body": body, "out_trade_no": out_trade_no, "total_fee": total_fee, "trade_type": trade_type, "contract_id": contract_id, "notify_url": notify_url, "detail": detail, "attach": attach, "fee_type": fee_type, "goods_tag": goods_tag, "clientip": clientip, "deviceid": deviceid, "mobile": mobile, "email": email, "qq": qq, "openid": openid, "creid": creid, "outerid": outerid, "timestamp": timestamp, "spbill_create_ip": spbill_create_ip, } return self._post("pay/pappayapply", data=data)
def apply_deduct( self, body, total_fee, contract_id, notify_url, out_trade_no=None, detail=None, attach=None, fee_type="CNY", goods_tag=None, clientip=None, deviceid=None, mobile=None, email=None, qq=None, openid=None, creid=None, outerid=None, ): """ 申请扣款 api :param body: 商品描述 商品或支付单简要描述 :param out_trade_no: 可选 商户订单号 商户系统内部的订单号,32个字符内、可包含字母, 其他说明见商户订单号 :param total_fee: 总金额 订单总金额,单位为分,只能为整数,详见支付金额 :param contract_id: 委托代扣协议id 签约成功后,微信返回的委托代扣协议id :param notify_url: 回调通知url 接受扣款结果异步回调通知的url :param detail: 可选 商品详情 商品名称明细列表 :param attach: 可选 附加数据 附加数据,在查询API和支付通知中原样返回,该字段主要用于商户携带订单的自定义数据 :param fee_type: 可选 货币类型 符合ISO 4217标准的三位字母代码,默认人民币:CNY :param goods_tag: 可选 商品标记 商品标记,代金券或立减优惠功能的参数,说明详见代金券或立减优惠 :param clientip: 可选 客户端 IP 点分IP格式(客户端IP) :param deviceid: 可选 设备ID android填imei的一次md5; ios填idfa的一次md5 :param mobile: 可选 手机号 用户手机号 :param email: 可选 邮箱地址 用户邮箱地址 :param qq: 可选 QQ号 用户QQ号 :param openid: 可选 微信open ID 用户微信open ID :param creid: 可选 身份证号 用户身份证号 :param outerid: 可选 商户侧用户标识 用户在商户侧的标识 :return: 返回的结果信息 """ trade_type = "PAP" # 交易类型 交易类型PAP-微信委托代扣支付 timestamp = int(time.time()) # 10位时间戳 spbill_create_ip = get_external_ip() # 终端IP 调用微信支付API的机器IP if not out_trade_no: now = datetime.fromtimestamp(time.time(), tz=timezone("Asia/Shanghai")) out_trade_no = f"{self.mch_id}{now.strftime('%Y%m%d%H%M%S')}{random.randint(1000, 10000)}" data = { "appid": self.appid, "mch_id": self.mch_id, "body": body, "out_trade_no": out_trade_no, "total_fee": total_fee, "trade_type": trade_type, "contract_id": contract_id, "notify_url": notify_url, "detail": detail, "attach": attach, "fee_type": fee_type, "goods_tag": goods_tag, "clientip": clientip, "deviceid": deviceid, "mobile": mobile, "email": email, "qq": qq, "openid": openid, "creid": creid, "outerid": outerid, "timestamp": timestamp, "spbill_create_ip": spbill_create_ip, } return self._post("pay/pappayapply", data=data)
This module defines some useful field types for parse WeChat messages :copyright: (c) 2014 by messense. :license: MIT, see LICENSE for more details. """ import time from datetime import datetime import base64 import copy from typing import Any, Callable, Optional from wechatpy.utils import to_text, to_binary, ObjectDict, timezone default_timezone = timezone("Asia/Shanghai") class FieldDescriptor: def __init__(self, field): self.field = field self.attr_name = field.name def __get__(self, instance, instance_type=None): if instance is not None: value = instance._data.get(self.attr_name) if value is None: value = copy.deepcopy(self.field.default) instance._data[self.attr_name] = value if isinstance(value, dict): value = ObjectDict(value)
def create( self, trade_type, body, total_fee, notify_url, client_ip=None, user_id=None, out_trade_no=None, detail=None, attach=None, fee_type="CNY", time_start=None, time_expire=None, goods_tag=None, product_id=None, device_info=None, limit_pay=None, scene_info=None, sub_user_id=None, **kwargs, ): """ 统一下单接口 :param trade_type: 交易类型,取值如下:JSAPI,NATIVE,APP,WAP, MWEB :param body: 商品描述 :param total_fee: 总金额,单位分 :param notify_url: 接收微信支付异步通知回调地址 :param client_ip: 可选,APP和网页支付提交用户端ip,Native支付填调用微信支付API的机器IP :param user_id: 可选,用户在商户appid下的唯一标识。trade_type=JSAPI和appid已设定,此参数必传 :param sub_user_id: 可选,小程序appid下的唯一标识。trade_type=JSAPI和sub_appid已设定,此参数必传 :param out_trade_no: 可选,商户订单号,默认自动生成 :param detail: 可选,商品详情 :param attach: 可选,附加数据,在查询API和支付通知中原样返回,该字段主要用于商户携带订单的自定义数据 :param fee_type: 可选,符合ISO 4217标准的三位字母代码,默认人民币:CNY :param time_start: 可选,订单生成时间,默认为当前时间 :param time_expire: 可选,订单失效时间,默认为订单生成时间后两小时 :param goods_tag: 可选,商品标记,代金券或立减优惠功能的参数 :param product_id: 可选,trade_type=NATIVE,此参数必传。此id为二维码中包含的商品ID,商户自行定义 :param device_info: 可选,终端设备号(门店号或收银设备ID),注意:PC网页或公众号内支付请传"WEB" :param limit_pay: 可选,指定支付方式,no_credit--指定不能使用信用卡支付 :param scene_info: 可选,上报支付的场景信息 :param kwargs: 其他未列举在上述参数中的统一下单接口调用参数,例如电子发票入口开放标识receipt :type scene_info: dict :return: 返回的结果数据 """ now = datetime.fromtimestamp(time.time(), tz=timezone("Asia/Shanghai")) hours_later = now + timedelta(hours=2) if time_start is None: time_start = now else: time_start = time_start.astimezone(timezone("Asia/Shanghai")) if time_expire is None: time_expire = hours_later else: time_expire = time_expire.astimezone(timezone("Asia/Shanghai")) if not out_trade_no: out_trade_no = "{0}{1}{2}".format(self.mch_id, now.strftime("%Y%m%d%H%M%S"), random.randint(1000, 10000)) if scene_info is not None: scene_info = json.dumps(scene_info, ensure_ascii=False) data = { "appid": self.appid, "sub_appid": self.sub_appid, "device_info": device_info, "body": body, "detail": detail, "attach": attach, "out_trade_no": out_trade_no, "fee_type": fee_type, "total_fee": total_fee, "spbill_create_ip": client_ip or get_external_ip(), "time_start": time_start.strftime("%Y%m%d%H%M%S"), "time_expire": time_expire.strftime("%Y%m%d%H%M%S"), "goods_tag": goods_tag, "notify_url": notify_url, "trade_type": trade_type, "limit_pay": limit_pay, "product_id": product_id, "openid": user_id, "sub_openid": sub_user_id, "scene_info": scene_info, } data.update(kwargs) return self._post("pay/unifiedorder", data=data)
def getOutTradeNo(): now = datetime.fromtimestamp(time.time(), tz=timezone('Asia/Shanghai')) return '{0}{1}{2}'.format(current_app.config.get("WECHAT_MCH_ID"), now.strftime('%Y%m%d%H%M%S'), random.randint(1000, 10000))
:copyright: (c) 2014 by messense. :license: MIT, see LICENSE for more details. """ from __future__ import absolute_import, unicode_literals import time from datetime import datetime import base64 import copy import six from wechatpy.utils import to_text, to_binary, ObjectDict, timezone default_timezone = timezone('Asia/Shanghai') class FieldDescriptor(object): def __init__(self, field): self.field = field self.attr_name = field.name def __get__(self, instance, instance_type=None): if instance is not None: value = instance._data.get(self.attr_name) if value is None: value = copy.deepcopy(self.field.default) instance._data[self.attr_name] = value if isinstance(value, dict):