优化工单模块,增加企微模块
This commit is contained in:
10
sg_wechat_enterprise/we_api/pay/api/__init__.py
Normal file
10
sg_wechat_enterprise/we_api/pay/api/__init__.py
Normal file
@@ -0,0 +1,10 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import absolute_import, unicode_literals
|
||||
from wechatpy.pay.api.redpack import WeChatRedpack # NOQA
|
||||
from wechatpy.pay.api.transfer import WeChatTransfer # NOQA
|
||||
from wechatpy.pay.api.coupon import WeChatCoupon # NOQA
|
||||
from wechatpy.pay.api.order import WeChatOrder # NOQA
|
||||
from wechatpy.pay.api.refund import WeChatRefund # NOQA
|
||||
from wechatpy.pay.api.tools import WeChatTools # NOQA
|
||||
from wechatpy.pay.api.jsapi import WeChatJSAPI # NOQA
|
||||
from wechatpy.pay.api.micropay import WeChatMicroPay # NOQA
|
||||
82
sg_wechat_enterprise/we_api/pay/api/coupon.py
Normal file
82
sg_wechat_enterprise/we_api/pay/api/coupon.py
Normal file
@@ -0,0 +1,82 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import absolute_import, unicode_literals
|
||||
import random
|
||||
from datetime import datetime
|
||||
|
||||
from wechatpy.pay.base import BaseWeChatPayAPI
|
||||
|
||||
|
||||
class WeChatCoupon(BaseWeChatPayAPI):
|
||||
|
||||
def send(self, user_id, stock_id, op_user_id=None, device_info=None,
|
||||
out_trade_no=None):
|
||||
"""
|
||||
发放代金券
|
||||
|
||||
:param user_id: 用户在公众号下的 openid
|
||||
:param stock_id: 代金券批次 ID
|
||||
:param op_user_id: 可选,操作员账号,默认为商户号
|
||||
:param device_info: 可选,微信支付分配的终端设备号
|
||||
:param out_trade_no: 可选,商户订单号,需保持唯一性,默认自动生成
|
||||
:return: 返回的结果信息
|
||||
"""
|
||||
if not out_trade_no:
|
||||
now = datetime.now()
|
||||
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,
|
||||
'coupon_stock_id': stock_id,
|
||||
'openid': user_id,
|
||||
'openid_count': 1,
|
||||
'partner_trade_no': out_trade_no,
|
||||
'op_user_id': op_user_id,
|
||||
'device_info': device_info,
|
||||
'version': '1.0',
|
||||
'type': 'XML',
|
||||
}
|
||||
return self._post('mmpaymkttransfers/send_coupon', data=data)
|
||||
|
||||
def query_stock(self, stock_id, op_user_id=None, device_info=None):
|
||||
"""
|
||||
查询代金券批次
|
||||
|
||||
:param stock_id: 代金券批次 ID
|
||||
:param op_user_id: 可选,操作员账号,默认为商户号
|
||||
:param device_info: 可选,微信支付分配的终端设备号
|
||||
:return: 返回的结果信息
|
||||
"""
|
||||
data = {
|
||||
'appid': self.appid,
|
||||
'coupon_stock_id': stock_id,
|
||||
'op_user_id': op_user_id,
|
||||
'device_info': device_info,
|
||||
'version': '1.0',
|
||||
'type': 'XML',
|
||||
}
|
||||
return self._post('mmpaymkttransfers/query_coupon_stock', data=data)
|
||||
|
||||
def query_coupon(self, coupon_id, user_id,
|
||||
op_user_id=None, device_info=None):
|
||||
"""
|
||||
查询代金券信息
|
||||
|
||||
:param coupon_id: 代金券 ID
|
||||
:param user_id: 用户在公众号下的 openid
|
||||
:param op_user_id: 可选,操作员账号,默认为商户号
|
||||
:param device_info: 可选,微信支付分配的终端设备号
|
||||
:return: 返回的结果信息
|
||||
"""
|
||||
data = {
|
||||
'coupon_id': coupon_id,
|
||||
'openid': user_id,
|
||||
'appid': self.appid,
|
||||
'op_user_id': op_user_id,
|
||||
'device_info': device_info,
|
||||
'version': '1.0',
|
||||
'type': 'XML',
|
||||
}
|
||||
return self._post('promotion/query_coupon', data=data)
|
||||
48
sg_wechat_enterprise/we_api/pay/api/jsapi.py
Normal file
48
sg_wechat_enterprise/we_api/pay/api/jsapi.py
Normal file
@@ -0,0 +1,48 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import absolute_import, unicode_literals
|
||||
import time
|
||||
|
||||
from wechatpy.utils import random_string, to_text
|
||||
from wechatpy.pay.base import BaseWeChatPayAPI
|
||||
from wechatpy.pay.utils import calculate_signature
|
||||
|
||||
|
||||
class WeChatJSAPI(BaseWeChatPayAPI):
|
||||
|
||||
def get_jsapi_signature(self, prepay_id, timestamp=None, nonce_str=None):
|
||||
"""
|
||||
获取 JSAPI 签名
|
||||
|
||||
:param prepay_id: 统一下单接口返回的 prepay_id 参数值
|
||||
:param timestamp: 可选,时间戳,默认为当前时间戳
|
||||
:param nonce_str: 可选,随机字符串,默认自动生成
|
||||
:return: 签名
|
||||
"""
|
||||
data = {
|
||||
'appId': self.appid,
|
||||
'timeStamp': timestamp or to_text(int(time.time())),
|
||||
'nonceStr': nonce_str or random_string(32),
|
||||
'signType': 'MD5',
|
||||
'package': 'prepay_id={0}'.format(prepay_id),
|
||||
}
|
||||
return calculate_signature(data, self._client.api_key)
|
||||
|
||||
def get_jsapi_params(self, prepay_id, timestamp=None, nonce_str=None):
|
||||
"""
|
||||
获取 JSAPI 参数
|
||||
|
||||
:param prepay_id: 统一下单接口返回的 prepay_id 参数值
|
||||
:param timestamp: 可选,时间戳,默认为当前时间戳
|
||||
:param nonce_str: 可选,随机字符串,默认自动生成
|
||||
:return: 签名
|
||||
"""
|
||||
data = {
|
||||
'appId': self.appid,
|
||||
'timeStamp': timestamp or to_text(int(time.time())),
|
||||
'nonceStr': nonce_str or random_string(32),
|
||||
'signType': 'MD5',
|
||||
'package': 'prepay_id={0}'.format(prepay_id),
|
||||
}
|
||||
sign = calculate_signature(data, self._client.api_key)
|
||||
data['paySign'] = sign
|
||||
return data
|
||||
64
sg_wechat_enterprise/we_api/pay/api/micropay.py
Normal file
64
sg_wechat_enterprise/we_api/pay/api/micropay.py
Normal file
@@ -0,0 +1,64 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import absolute_import, unicode_literals
|
||||
import random
|
||||
from datetime import datetime
|
||||
|
||||
from wechatpy.pay.utils import get_external_ip
|
||||
from wechatpy.pay.base import BaseWeChatPayAPI
|
||||
|
||||
|
||||
class WeChatMicroPay(BaseWeChatPayAPI):
|
||||
def create(self, body, total_fee, auth_code, client_ip=None, out_trade_no=None, detail=None, attach=None,
|
||||
fee_type='CNY', goods_tag=None, device_info=None, limit_pay=None):
|
||||
"""
|
||||
刷卡支付接口
|
||||
:param device_info: 可选,终端设备号(商户自定义,如门店编号)
|
||||
:param body: 商品描述
|
||||
:param detail: 可选,商品详情
|
||||
:param attach: 可选,附加数据,在查询API和支付通知中原样返回,该字段主要用于商户携带订单的自定义数据
|
||||
:param client_ip: 可选,APP和网页支付提交用户端ip,Native支付填调用微信支付API的机器IP
|
||||
:param out_trade_no: 可选,商户订单号,默认自动生成
|
||||
:param total_fee: 总金额,单位分
|
||||
:param fee_type: 可选,符合ISO 4217标准的三位字母代码,默认人民币:CNY
|
||||
:param goods_tag: 可选,商品标记,代金券或立减优惠功能的参数
|
||||
:param limit_pay: 可选,指定支付方式,no_credit--指定不能使用信用卡支付
|
||||
:param auth_code: 授权码,扫码支付授权码,设备读取用户微信中的条码或者二维码信息
|
||||
:return: 返回的结果数据
|
||||
"""
|
||||
now = datetime.now()
|
||||
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,
|
||||
'total_fee': total_fee,
|
||||
'fee_type': fee_type,
|
||||
'spbill_create_ip': client_ip or get_external_ip(),
|
||||
'goods_tag': goods_tag,
|
||||
'limit_pay': limit_pay,
|
||||
'auth_code': auth_code,
|
||||
}
|
||||
return self._post('pay/micropay', data=data)
|
||||
|
||||
def query(self, transaction_id=None, out_trade_no=None):
|
||||
"""
|
||||
查询订单
|
||||
|
||||
:param transaction_id: 微信的订单号,优先使用
|
||||
:param out_trade_no: 商户系统内部的订单号,当没提供transaction_id时需要传这个。
|
||||
:return: 返回的结果数据
|
||||
"""
|
||||
data = {
|
||||
'appid': self.appid,
|
||||
'transaction_id': transaction_id,
|
||||
'out_trade_no': out_trade_no,
|
||||
}
|
||||
return self._post('pay/orderquery', data=data)
|
||||
138
sg_wechat_enterprise/we_api/pay/api/order.py
Normal file
138
sg_wechat_enterprise/we_api/pay/api/order.py
Normal file
@@ -0,0 +1,138 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import absolute_import, unicode_literals
|
||||
import time
|
||||
import random
|
||||
from datetime import datetime, timedelta
|
||||
|
||||
from wechatpy.utils import timezone
|
||||
from wechatpy.pay.utils import get_external_ip
|
||||
from wechatpy.pay.base import BaseWeChatPayAPI
|
||||
from wechatpy.utils import random_string, to_text
|
||||
from wechatpy.pay.utils import calculate_signature
|
||||
|
||||
|
||||
class WeChatOrder(BaseWeChatPayAPI):
|
||||
|
||||
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)
|
||||
|
||||
def query(self, transaction_id=None, out_trade_no=None):
|
||||
"""
|
||||
查询订单
|
||||
|
||||
:param transaction_id: 微信的订单号,优先使用
|
||||
:param out_trade_no: 商户系统内部的订单号,当没提供transaction_id时需要传这个。
|
||||
:return: 返回的结果数据
|
||||
"""
|
||||
data = {
|
||||
'appid': self.appid,
|
||||
'transaction_id': transaction_id,
|
||||
'out_trade_no': out_trade_no,
|
||||
}
|
||||
return self._post('pay/orderquery', data=data)
|
||||
|
||||
def close(self, out_trade_no):
|
||||
"""
|
||||
关闭订单
|
||||
|
||||
:param out_trade_no: 商户系统内部的订单号
|
||||
:return: 返回的结果数据
|
||||
"""
|
||||
data = {
|
||||
'appid': self.appid,
|
||||
'out_trade_no': out_trade_no,
|
||||
}
|
||||
return self._post('pay/closeorder', data=data)
|
||||
|
||||
def get_appapi_params(self, prepay_id, timestamp=None, nonce_str=None):
|
||||
"""
|
||||
获取 APP 支付参数
|
||||
|
||||
:param prepay_id: 统一下单接口返回的 prepay_id 参数值
|
||||
:param timestamp: 可选,时间戳,默认为当前时间戳
|
||||
:param nonce_str: 可选,随机字符串,默认自动生成
|
||||
:return: 签名
|
||||
"""
|
||||
data = {
|
||||
'appid': self.appid,
|
||||
'partnerid': self.mch_id,
|
||||
'prepayid': prepay_id,
|
||||
'package': 'Sign=WXPay',
|
||||
'timestamp': timestamp or to_text(int(time.time())),
|
||||
'noncestr': nonce_str or random_string(32)
|
||||
}
|
||||
sign = calculate_signature(data, self._client.api_key)
|
||||
data['sign'] = sign
|
||||
return data
|
||||
|
||||
def reverse(self, transaction_id=None, out_trade_no=None):
|
||||
"""
|
||||
撤销订单
|
||||
|
||||
:param transaction_id: 可选,微信的订单号,优先使用
|
||||
:param out_trade_no: 可选,商户系统内部的订单号,
|
||||
transaction_id、out_trade_no二选一,
|
||||
如果同时存在优先级:transaction_id> out_trade_no
|
||||
:return: 返回的结果数据
|
||||
"""
|
||||
data = {
|
||||
'appid': self.appid,
|
||||
'transaction_id': transaction_id,
|
||||
'out_trade_no': out_trade_no,
|
||||
}
|
||||
return self._post('secapi/pay/reverse', data=data)
|
||||
125
sg_wechat_enterprise/we_api/pay/api/redpack.py
Normal file
125
sg_wechat_enterprise/we_api/pay/api/redpack.py
Normal file
@@ -0,0 +1,125 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import absolute_import, unicode_literals
|
||||
import random
|
||||
from datetime import datetime
|
||||
|
||||
from wechatpy.pay.utils import get_external_ip
|
||||
from wechatpy.pay.base import BaseWeChatPayAPI
|
||||
|
||||
|
||||
class WeChatRedpack(BaseWeChatPayAPI):
|
||||
|
||||
def send(self, user_id, total_amount, send_name, act_name,
|
||||
wishing, remark, total_num=1, client_ip=None,
|
||||
nick_name=None, min_value=None,
|
||||
max_value=None, out_trade_no=None, logo_imgurl=None):
|
||||
"""
|
||||
发送现金红包
|
||||
|
||||
:param user_id: 接收红包的用户在公众号下的 openid
|
||||
:param total_amount: 红包金额,单位分
|
||||
:param send_name: 商户名称
|
||||
:param nick_name: 可选,提供方名称,默认和商户名称相同
|
||||
:param act_name: 活动名称
|
||||
:param wishing: 红包祝福语
|
||||
:param remark: 备注
|
||||
:param client_ip: 可选,调用接口的机器 IP 地址
|
||||
:param total_num: 可选,红包发放总人数,默认为 1
|
||||
:param min_value: 可选,最小红包金额,单位分
|
||||
:param max_value: 可选,最大红包金额,单位分
|
||||
:param out_trade_no: 可选,商户订单号,默认会自动生成
|
||||
:param logo_imgurl: 可选,商户 Logo 的 URL
|
||||
:return: 返回的结果数据字典
|
||||
"""
|
||||
if not out_trade_no:
|
||||
now = datetime.now()
|
||||
out_trade_no = '{0}{1}{2}'.format(
|
||||
self.mch_id,
|
||||
now.strftime('%Y%m%d%H%M%S'),
|
||||
random.randint(1000, 10000)
|
||||
)
|
||||
data = {
|
||||
'wxappid': self.appid,
|
||||
're_openid': user_id,
|
||||
'total_amount': total_amount,
|
||||
'nick_name': nick_name or send_name,
|
||||
'send_name': send_name,
|
||||
'act_name': act_name,
|
||||
'wishing': wishing,
|
||||
'remark': remark,
|
||||
'client_ip': client_ip or get_external_ip(),
|
||||
'total_num': total_num,
|
||||
'min_value': min_value or total_amount,
|
||||
'max_value': max_value or total_amount,
|
||||
'mch_billno': out_trade_no,
|
||||
'logo_imgurl': logo_imgurl,
|
||||
}
|
||||
return self._post('mmpaymkttransfers/sendredpack', data=data)
|
||||
|
||||
def send_group(self, user_id, total_amount, send_name, act_name, wishing,
|
||||
remark, total_num, client_ip=None, amt_type="ALL_RAND",
|
||||
amt_list=None, out_trade_no=None,
|
||||
logo_imgurl=None, watermark_imgurl=None,
|
||||
banner_imgurl=None):
|
||||
"""
|
||||
发送裂变红包
|
||||
|
||||
:param user_id: 接收红包的用户在公众号下的 openid
|
||||
:param total_amount: 红包金额,单位分
|
||||
:param send_name: 商户名称
|
||||
:param act_name: 活动名称
|
||||
:param wishing: 红包祝福语
|
||||
:param remark: 备注
|
||||
:param total_num: 红包发放总人数
|
||||
:param client_ip: 可选,调用接口的机器 IP 地址
|
||||
:param amt_type: 可选,红包金额设置方式
|
||||
ALL_RAND—全部随机,商户指定总金额和红包发放总人数,由微信支付随机计算出各红包金额
|
||||
ALL_SPECIFIED—全部自定义
|
||||
SEED_SPECIFIED—种子红包自定义,其他随机
|
||||
:param amt_list: 可选,各红包具体金额,自定义金额时必须设置,单位分
|
||||
:param out_trade_no: 可选,商户订单号,默认会自动生成
|
||||
:param logo_imgurl: 可选,商户 Logo 的 URL
|
||||
:param watermark_imgurl: 可选,背景水印图片 URL
|
||||
:param banner_imgurl: 红包详情页面的 banner 图片 URL
|
||||
:return: 返回的结果数据字典
|
||||
"""
|
||||
if not out_trade_no:
|
||||
now = datetime.now()
|
||||
out_trade_no = '{0}{1}{2}'.format(
|
||||
self._client.mch_id,
|
||||
now.strftime('%Y%m%d%H%M%S'),
|
||||
random.randint(1000, 10000)
|
||||
)
|
||||
data = {
|
||||
'wxappid': self.appid,
|
||||
're_openid': user_id,
|
||||
'total_amount': total_amount,
|
||||
'send_name': send_name,
|
||||
'act_name': act_name,
|
||||
'wishing': wishing,
|
||||
'remark': remark,
|
||||
'total_num': total_num,
|
||||
'client_ip': client_ip or get_external_ip(),
|
||||
'amt_type': amt_type,
|
||||
'amt_list': amt_list,
|
||||
'mch_billno': out_trade_no,
|
||||
'logo_imgurl': logo_imgurl,
|
||||
'watermark_imgurl': watermark_imgurl,
|
||||
'banner_imgurl': banner_imgurl,
|
||||
}
|
||||
return self._post('mmpaymkttransfers/sendgroupredpack', data=data)
|
||||
|
||||
def query(self, out_trade_no, bill_type='MCHT'):
|
||||
"""
|
||||
查询红包发放记录
|
||||
|
||||
:param out_trade_no: 商户订单号
|
||||
:param bill_type: 可选,订单类型,目前固定为 MCHT
|
||||
:return: 返回的红包发放记录信息
|
||||
"""
|
||||
data = {
|
||||
'mch_billno': out_trade_no,
|
||||
'bill_type': bill_type,
|
||||
'appid': self.appid,
|
||||
}
|
||||
return self._post('mmpaymkttransfers/gethbinfo', data=data)
|
||||
61
sg_wechat_enterprise/we_api/pay/api/refund.py
Normal file
61
sg_wechat_enterprise/we_api/pay/api/refund.py
Normal file
@@ -0,0 +1,61 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import absolute_import, unicode_literals
|
||||
from wechatpy.pay.base import BaseWeChatPayAPI
|
||||
|
||||
|
||||
class WeChatRefund(BaseWeChatPayAPI):
|
||||
|
||||
def apply(self, total_fee, refund_fee, out_refund_no, transaction_id=None,
|
||||
out_trade_no=None, fee_type='CNY', op_user_id=None,
|
||||
device_info=None,notify_url=None,refund_account='REFUND_SOURCE_UNSETTLED_FUNDS'):
|
||||
"""
|
||||
申请退款
|
||||
|
||||
:param total_fee: 订单总金额,单位为分
|
||||
:param refund_fee: 退款总金额,单位为分
|
||||
:param out_refund_no: 商户系统内部的退款单号,商户系统内部唯一,同一退款单号多次请求只退一笔
|
||||
:param transaction_id: 可选,微信订单号
|
||||
:param out_trade_no: 可选,商户系统内部的订单号,与 transaction_id 二选一
|
||||
:param fee_type: 可选,货币类型,符合ISO 4217标准的三位字母代码,默认人民币:CNY
|
||||
:param op_user_id: 可选,操作员帐号, 默认为商户号
|
||||
:param refund_account: 可选,退款资金来源,仅针对老资金流商户使用,默认使用未结算资金退款
|
||||
:param device_info: 可选,终端设备号
|
||||
:return: 返回的结果数据
|
||||
"""
|
||||
data = {
|
||||
'appid': self.appid,
|
||||
'device_info': device_info,
|
||||
'transaction_id': transaction_id,
|
||||
'out_trade_no': out_trade_no,
|
||||
'out_refund_no': out_refund_no,
|
||||
'total_fee': total_fee,
|
||||
'refund_fee': refund_fee,
|
||||
'refund_fee_type': fee_type,
|
||||
'op_user_id': op_user_id if op_user_id else self.mch_id,
|
||||
"notify_url":notify_url,
|
||||
'refund_account': refund_account,
|
||||
|
||||
}
|
||||
return self._post('secapi/pay/refund', data=data)
|
||||
|
||||
def query(self, refund_id=None, out_refund_no=None, transaction_id=None,
|
||||
out_trade_no=None, device_info=None):
|
||||
"""
|
||||
查询退款
|
||||
|
||||
:param refund_id: 微信退款单号
|
||||
:param out_refund_no: 商户退款单号
|
||||
:param transaction_id: 微信订单号
|
||||
:param out_trade_no: 商户系统内部的订单号
|
||||
:param device_info: 可选,终端设备号
|
||||
:return: 返回的结果数据
|
||||
"""
|
||||
data = {
|
||||
'appid': self.appid,
|
||||
'device_info': device_info,
|
||||
'transaction_id': transaction_id,
|
||||
'out_trade_no': out_trade_no,
|
||||
'out_refund_no': out_refund_no,
|
||||
'refund_id': refund_id,
|
||||
}
|
||||
return self._post('pay/refundquery', data=data)
|
||||
57
sg_wechat_enterprise/we_api/pay/api/tools.py
Normal file
57
sg_wechat_enterprise/we_api/pay/api/tools.py
Normal file
@@ -0,0 +1,57 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import absolute_import, unicode_literals
|
||||
from datetime import datetime, date
|
||||
|
||||
from wechatpy.pay.base import BaseWeChatPayAPI
|
||||
|
||||
|
||||
class WeChatTools(BaseWeChatPayAPI):
|
||||
|
||||
def short_url(self, long_url):
|
||||
"""
|
||||
长链接转短链接
|
||||
|
||||
:param long_url: 长链接
|
||||
:return: 返回的结果数据
|
||||
"""
|
||||
data = {
|
||||
'appid': self.appid,
|
||||
'long_url': long_url,
|
||||
}
|
||||
return self._post('tools/shorturl', data=data)
|
||||
|
||||
def download_bill(self, bill_date, bill_type='ALL', device_info=None):
|
||||
"""
|
||||
下载对账单
|
||||
|
||||
:param bill_date: 下载对账单的日期
|
||||
:param bill_type: 账单类型,ALL,返回当日所有订单信息,默认值
|
||||
SUCCESS,返回当日成功支付的订单,
|
||||
REFUND,返回当日退款订单,
|
||||
REVOKED,已撤销的订单
|
||||
:param device_info: 微信支付分配的终端设备号,填写此字段,只下载该设备号的对账单
|
||||
:return: 返回的结果数据
|
||||
"""
|
||||
if isinstance(bill_date, (datetime, date)):
|
||||
bill_date = bill_date.strftime('%Y%m%d')
|
||||
|
||||
data = {
|
||||
'appid': self.appid,
|
||||
'bill_date': bill_date,
|
||||
'bill_type': bill_type,
|
||||
'device_info': device_info,
|
||||
}
|
||||
return self._post('pay/downloadbill', data=data)
|
||||
|
||||
def auto_code_to_openid(self, auth_code):
|
||||
"""
|
||||
授权码查询 openid 接口
|
||||
|
||||
:param auth_code: 扫码支付授权码,设备读取用户微信中的条码或者二维码信息
|
||||
:return: 返回的结果数据
|
||||
"""
|
||||
data = {
|
||||
'appid': self.appid,
|
||||
'auth_code': auth_code,
|
||||
}
|
||||
return self._post('tools/authcodetoopenid', data=data)
|
||||
65
sg_wechat_enterprise/we_api/pay/api/transfer.py
Normal file
65
sg_wechat_enterprise/we_api/pay/api/transfer.py
Normal file
@@ -0,0 +1,65 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import absolute_import, unicode_literals
|
||||
import random
|
||||
from datetime import datetime
|
||||
|
||||
from wechatpy.pay.utils import get_external_ip
|
||||
from wechatpy.pay.base import BaseWeChatPayAPI
|
||||
|
||||
|
||||
class WeChatTransfer(BaseWeChatPayAPI):
|
||||
|
||||
def transfer(self, user_id, amount, desc, client_ip=None,
|
||||
check_name='OPTION_CHECK', real_name=None,
|
||||
out_trade_no=None, device_info=None):
|
||||
"""
|
||||
企业付款接口
|
||||
|
||||
:param user_id: 接受收红包的用户在公众号下的 openid
|
||||
:param amount: 付款金额,单位分
|
||||
:param desc: 付款说明
|
||||
:param client_ip: 可选,调用接口机器的 IP 地址
|
||||
:param check_name: 可选,校验用户姓名选项,
|
||||
NO_CHECK:不校验真实姓名,
|
||||
FORCE_CHECK:强校验真实姓名(未实名认证的用户会校验失败,无法转账),
|
||||
OPTION_CHECK:针对已实名认证的用户才校验真实姓名(未实名认证用户不校验,可以转账成功),
|
||||
默认为 OPTION_CHECK
|
||||
:param real_name: 可选,收款用户真实姓名,
|
||||
如果check_name设置为FORCE_CHECK或OPTION_CHECK,则必填用户真实姓名
|
||||
:param out_trade_no: 可选,商户订单号,需保持唯一性,默认自动生成
|
||||
:param device_info: 可选,微信支付分配的终端设备号
|
||||
:return: 返回的结果信息
|
||||
"""
|
||||
if not out_trade_no:
|
||||
now = datetime.now()
|
||||
out_trade_no = '{0}{1}{2}'.format(
|
||||
self.mch_id,
|
||||
now.strftime('%Y%m%d%H%M%S'),
|
||||
random.randint(1000, 10000)
|
||||
)
|
||||
data = {
|
||||
'mch_appid': self.appid,
|
||||
'mchid': self.mch_id,
|
||||
'device_info': device_info,
|
||||
'partner_trade_no': out_trade_no,
|
||||
'openid': user_id,
|
||||
'check_name': check_name,
|
||||
're_user_name': real_name,
|
||||
'amount': amount,
|
||||
'desc': desc,
|
||||
'spbill_create_ip': client_ip or get_external_ip(),
|
||||
}
|
||||
return self._post('mmpaymkttransfers/promotion/transfers', data=data)
|
||||
|
||||
def query(self, out_trade_no):
|
||||
"""
|
||||
企业付款查询接口
|
||||
|
||||
:param out_trade_no: 商户调用企业付款API时使用的商户订单号
|
||||
:return: 返回的结果数据
|
||||
"""
|
||||
data = {
|
||||
'appid': self.appid,
|
||||
'partner_trade_no': out_trade_no,
|
||||
}
|
||||
return self._post('mmpaymkttransfers/gettransferinfo', data=data)
|
||||
Reference in New Issue
Block a user