沙箱环境地址:https://openhome.alipay.com/platform/appDaily.htm?tab=info
1.将Crypto放到site-packages下
2、OSError:Cannot load native module 'Crypto.Cipher._raw_ecb':Trying '_raw_ecb.cp36-win_amd64.pyd':cannot load library 'C:UsersadminAppDataLocalTemp\_MEI160382CryptoUtil..Cipher\_raw_ecb.cp36-win_amb64.pyd':这个问题卡了我很久,前前后后尝试了很多中方法,粘出其中两种的链接
https://github.com/Legrandin/pycryptodome/issues/155
https://github.com/pyinstaller/pyinstaller/issues/2881
最后经过多次尝试和查找资料发现 Crypto对应的是pycryptodome包,所以出现这个问题。具体操作为pip list 查看当前安装包中是否有pycryptodome包,若有 则pip uninstall pycryptodome,卸载pycryptodome包,安装原包 pip install pycrypto(若失败使用 conda install pycrypto)。
3.pip install Crypto
4.生成支付配置实例
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.调用支付宝接口URL
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