沙箱環境地址:https://openhome.alipay.com/platform/appDaily.htm?tab=info
1.將Crypto放到site-packages下git
二、OSError:Cannot load native module 'Crypto.Cipher._raw_ecb':Trying '_raw_ecb.cp36-win_amd64.pyd':cannot load library 'C:\Users\admin\AppData\Local\Temp\_MEI160382\Crypto\Util\..\Cipher\_raw_ecb.cp36-win_amb64.pyd':這個問題卡了我好久,前先後後嘗試了不少中方法,粘出其中兩種的連接github
https://github.com/Legrandin/pycryptodome/issues/155api
https://github.com/pyinstaller/pyinstaller/issues/2881app
最後通過屢次嘗試和查找資料發現 Crypto對應的是pycryptodome包,因此出現這個問題。具體操做爲pip list 查看當前安裝包中是否有pycryptodome包,如有 則pip uninstall pycryptodome,卸載pycryptodome包,安裝原包 pip install pycrypto(若失敗使用 conda install pycrypto)。dom
3.pip install Cryptoide
4.生成支付配置實例url
def ali(self): # 沙箱環境地址:https://openhome.alipay.com/platform/appDaily.htm?tab=info app_id = "2016092000558535" # POST請求,用於最後的檢測 notify_url = "http://182.61.36.131:8000/page2/" # notify_url = "http://www.wupeiqi.com:8804/page2/" # GET請求,用於頁面的跳轉展現 return_url = "http://182.61.36.131:8000/page2/" # return_url = "http://www.wupeiqi.com:8804/page2/" merchant_private_key_path = "keys/應用私鑰2048.txt" alipay_public_key_path = "keys/myalipay_public_2048.txt" alipay = AliPay( appid=app_id, app_notify_url=notify_url, return_url=return_url, app_private_key_path=merchant_private_key_path, alipay_public_key_path=alipay_public_key_path, # 支付寶的公鑰,驗證支付寶回傳消息使用,不是你本身的公鑰 debug=True, # 默認False, ) return alipay
5.調用支付寶接口URLspa
subject = request.data.get('subject') alipay = self.ali() # 生成支付的url query_params = alipay.direct_pay( subject=subject, # 商品簡單描述 out_trade_no="x2" + str(time.time()), # 商戶訂單號 total_amount=final_price, # 交易金額(單位: 元 保留倆位小數) ) pay_url = "https://openapi.alipaydev.com/gateway.do?{}".format(query_params) res.data = pay_url
https://blog.csdn.net/qq_33848737/article/details/76904591.net