# -*- coding: utf-8 -*- from .type import RequestType from .core import Core from apps.WechatApplet.models import WechatApplet class Transfer(object): def __init__(self, appid): wx = WechatApplet.objects.filter(authorizer_appid=appid).first() if not wx: raise Exception(u'小程序appid认证失败!') self._core = Core(wx.agent_num, wx.cert_serial_no, wx.apiv3_key) def transfer_batch(self, appid, out_batch_no, batch_name, batch_remark, total_amount, total_num, transfer_detail_list=[]): ''' 商户可以通过该接口同时向多个用户微信零钱进行转账操作 :param appid string[1,32] 直连商户的appid: 申请商户号的appid或商户号绑定的appid(企业号corpid即为此appid)示例值:wxf636efh567hg4356 :param out_batch_no string[1,32] 商家批次单号: 商户系统内部的商家批次单号,要求此参数只能由数字、大小写字母组成,在商户系统内部唯一,示例值:'plfk2020042013' :param batch_name string[1,32] 批次名称: 该笔批量转账的名称 示例值:2019年1月深圳分部报销单 :param batch_remark string[1,32] 批次备注: 转账说明,UTF8编码,最多允许32个字符 示例值:2019年1月深圳分部报销单 :param total_amount int 转账总金额: 转账金额单位为“分”。转账总金额必须与批次内所有明细转账金额之和保持一致,否则无法发起转账操作 :param total_num int 转账总笔数: 一个转账批次单最多发起三千笔转账。转账总笔数必须与批次内所有明细之和保持一致,否则无法发起转账操作 :param transfer_detail_list array 转账明细列表: 发起批量转账的明细列表,最多三千笔 out_detail_no string[1,32] 商家明细单号 商户系统内部区分转账批次单下不同转账明细单的唯一标识,要求此参数只能由数字、大小写字母组成 示例值:x23zy545Bd5436 transfer_amount int 转账金额 转账金额单位为分 transfer_remark string[1,32] 转账备注 单条转账备注(微信用户会收到该备注),UTF8编码,最多允许32个字符 示例值:2020年4月报销 openid string[1,128] 用户在直连商户应用下的用户标示 注意: 商户上送敏感信息时使用微信支付平台公钥加密,证书序列号包含在请求HTTP头部的Wechatpay-Serial 批量转账一旦发起后,不允许撤销,批次受理成功后开始执行转账 转账批次单中涉及金额的字段单位为 分 当返回错误码为 "SYSTEM_ERROR" 时,请不要更换商家批次单号, 一定要使用原商家批次单号重试,否则可能造成重复转账等资金风险。 不同的商家批次单号 out_batch_no 请求为一个全新的批次, 在未查询到明确的转账批次但处理结果之前,请勿修改商家批次单号 重新提交! 请商户在自身的系统中合理设置转账频次并做好并发控制,防范错付风险 https://api.mch.weixin.qq.com/v3/transfer/batches POST ''' if not appid: raise Exception(u'缺少参数appid') if not out_batch_no: raise Exception(u'缺少参数out_batch_no') if not out_batch_no: raise Exception(u'缺少参数batch_name') if not out_batch_no: raise Exception(u'缺少参数batch_remark') if not out_batch_no: raise Exception(u'缺少参数total_amount') if not out_batch_no: raise Exception(u'缺少参数total_num') if not transfer_detail_list: raise Exception(u'缺少参数transfer_detail_list') params = { 'appid': appid, 'out_batch_no': out_batch_no, 'batch_name': batch_name, 'batch_remark': batch_remark, 'total_amount': total_amount, 'total_num': total_num, 'transfer_detail_list': transfer_detail_list } path = '/v3/transfer/batches' return self._core.request(path, method=RequestType.POST, data=params, cipher_data=False)