1 #-*- coding:utf-8 -*-
2 importrequests3 importhashlib4 importxmltodict5 importtime6 importrandom7 importstring8 importurllib29 importsys10
11
12 classWX_PayToolUtil():13 """微信支付工具"""
14
15 def __init__(self, APP_ID, MCH_ID, API_KEY, NOTIFY_URL):16 self._APP_ID = APP_ID #小程序ID
17 self._MCH_ID = MCH_ID ## 商户号
18 self._API_KEY =API_KEY19 self._UFDODER_URL = "https://api.mch.weixin.qq.com/pay/unifiedorder" #接口链接
20 self._NOTIFY_URL = NOTIFY_URL #异步通知
21
22 defgenerate_sign(self, param):23 '''生成签名'''
24 stringA = ''
25 ks =sorted(param.keys())26 #参数排序
27 for k inks:28 stringA += (k + '=' + param[k] + '&')29 #拼接商户KEY
30 stringSignTemp = stringA + "key=" +self._API_KEY31 #md5