class
payment
(view)
: @staticmethod
defget_nonce_str()
:"""生成隨機字串"""
return
str(uuid.uuid4())
.replace(
'-','')
@staticmethod
defgetsing
(o_dict)
:"""生成簽名"""
keys, paras =
sorted
(o_dict),[
] paras =
['{}={}'
.format
(key, o_dict[key]
)for key in keys]
# and kwargs[key] != '']
stringa =
'&'.join(paras)
stringsigntemp = stringa +
'&key='
+ mch_key
print
(stringsigntemp)
md5 = hashlib.md5(
) md5.update(stringsigntemp.encode(
'utf-8'))
return md5.hexdigest(
).upper(
) @staticmethod
deftrans_dict_to_xml
(data_dict)
: data_xml =
for k in data_dict.keys():
# 遍歷字典排序後的key
v = data_dict.get(k)
# 取出字典中key對應的value
'<>'
.format
(key=k, value=v)
)print
('{}'
.format(''
.join(data_xml)))
return
'{}'
.format(''
.join(data_xml)
).encode(
'utf-8'
)# 返回xml,並轉成u
@staticmethod
defgetxml
(kwargs)
:# 生成xml
xml =
''for key, value in kwargs.items():
xml +=
'<>'
.format
(key, value)
xml =''.
format
(xml)
return xml
defpost
(self, request)
: url =
""body =
"test"
trade_type =
"jsapi"
# 交易型別
data = json.loads(request.body.decode())
nonce_str = self.get_nonce_str(
)# 隨機字串
out_trade_no = data.get(
"out_trade_no"
)# 商戶訂單號
total_fee = data.get(
"total_fee"
)# 訂單總金額 單位為分
openid = data.get(
"openid"
) notify_url =
""# 通知位址
# 終端ip
# 簽名
data_dict[
'sign'
]= sing
xml = self.getxml(data_dict)
print
(xml)
headers =
request_data = requests.post(url, data=xml.encode(
"utf-8"
), headers=headers)
content = request_data.content.decode(
)print
(content)
# xml 轉換字典
微信小程式PHP 微信支付介面呼叫
小程式端 伺服器端 準備資料 都在後台系統中可查到 mch id 12 02 商戶號 key lk afk12 openid trim post openid out trade no mch id.time out trade no trim post out trade no body 答題獎金...
小程式微信支付
weixinpay new weixinpay openid,orderid.res2,訂單支付 res3 goods name total price 100,tsd res2 ret weixinpay pay class weixinpay public function pay 統一下單介面...
微信小程式支付
class wxpay protected mch id protected key protected openid protected out trade no protected body protected total fee protected notifyurl protected un...