MCPcopy Create free account
hub / github.com/ImSingee/PayJS / jsapi

Method jsapi

payjs/base.py:284–326  ·  view source on GitHub ↗

发起 JSAPI 支付 :param total_fee: 支付金额,单位为分,介于 1 - 1000000 之间 :param out_trade_no: 订单号,应保证唯一性,1-32 字符 :param openid: 用户 OpenID,可通过调用 get_openid 获得 :param body: (可选)订单标题,0 - 32 字符 :param notify_url: (可选)回调地址,留空使用默认,传入空字符串代表无需回调 :param attach: (可选)用

(self, total_fee: int, out_trade_no, openid, body: str = '', notify_url=None, attach=None)

Source from the content-addressed store, hash-verified

282 return url + '?' + urlencode(data)
283
284 def jsapi(self, total_fee: int, out_trade_no, openid, body: str = '', notify_url=None, attach=None):
285 """
286 发起 JSAPI 支付
287 :param total_fee: 支付金额,单位为分,介于 1 - 1000000 之间
288 :param out_trade_no: 订单号,应保证唯一性,1-32 字符
289 :param openid: 用户 OpenID,可通过调用 get_openid 获得
290 :param body: (可选)订单标题,0 - 32 字符
291 :param notify_url: (可选)回调地址,留空使用默认,传入空字符串代表无需回调
292 :param attach: (可选)用户自定义数据,在notify的时候会原样返回
293 :return:
294 """
295 url = r'https://payjs.cn/api/jsapi'
296
297 if not total_fee > 0:
298 raise InvalidInfoException(-2004, "金额必须为正整数(单位为分)")
299
300 out_trade_no = str(out_trade_no)
301
302 if not out_trade_no:
303 logger.warning("用户端订单号不可省略")
304 if not len(out_trade_no) <= 32:
305 logger.warning("用户端订单号最多为 32 位")
306
307 if not len(body) <= 32:
308 logger.warning("标题最多为 32 位")
309
310 if notify_url is None:
311 notify_url = self.notify_url
312 if not check_url(notify_url, force_ssl=self.FORCE_SSL):
313 raise InvalidInfoException(-2003, '通知回调地址有误')
314
315 data = {
316 'mchid': self.mchid,
317 'total_fee': total_fee,
318 'out_trade_no': out_trade_no,
319 'body': body,
320 'notify_url': notify_url,
321 'attach': attach,
322 'openid': openid,
323 }
324
325 ret = self.request(url, data)
326 return ret
327
328 def micropay(self, total_fee: int, out_trade_no, auth_code, body: str = ''):
329 """

Callers

nothing calls this directly

Calls 3

requestMethod · 0.95
check_urlFunction · 0.90

Tested by

no test coverage detected