初始化 :param mchid: 商户号 :param key: 密钥 :param notify_url: (可选)异步通知的 URL,留空为不通知或在发起请求时设置 :param FORCE_SSL: (默认为 True)回调地址强制使用 HTTPS
(self, mchid: str, key: str, notify_url=None, **kwargs)
| 24 | payjs_order_id = '' |
| 25 | |
| 26 | def __init__(self, mchid: str, key: str, notify_url=None, **kwargs): |
| 27 | """ |
| 28 | 初始化 |
| 29 | |
| 30 | :param mchid: 商户号 |
| 31 | :param key: 密钥 |
| 32 | :param notify_url: (可选)异步通知的 URL,留空为不通知或在发起请求时设置 |
| 33 | :param FORCE_SSL: (默认为 True)回调地址强制使用 HTTPS |
| 34 | """ |
| 35 | |
| 36 | for k, v in kwargs.items(): |
| 37 | self.__setattr__(k, v) |
| 38 | |
| 39 | if type(mchid) is not str: |
| 40 | raise InvalidInfoException(-2001, "商户号格式必须为字符串") |
| 41 | |
| 42 | self.mchid = mchid |
| 43 | |
| 44 | if type(key) is not str: |
| 45 | raise InvalidInfoException(-2002, "密钥格式必须为字符串") |
| 46 | |
| 47 | self.key = key |
| 48 | |
| 49 | if not check_url(notify_url, force_ssl=self.FORCE_SSL): |
| 50 | raise InvalidInfoException(-2003, "通知回调网址错误") |
| 51 | |
| 52 | self.notify_url = notify_url |
| 53 | |
| 54 | def request(self, url: str, data: dict, method='POST'): |
| 55 | """ |
nothing calls this directly
no test coverage detected