在PB實現支付寶當面付的功能,需要先在支付寶進行商戶簽約,並設置相關的公鑰信息(具體參考支付寶文檔)。
然後使用對應的私鑰文件對參數進RSAWithSha1前面計算。具體代碼如下:
string ls_pubFileName,ls_priFileName n_pbfunc_cryp lnv_cryp ls_priFileName ="D:\pbfunclib_pri.pem"//私鑰文件 string ls_str string ls_appId,ls_secret,ls_biz_content ls_appId ="3434343"//改成你的appid ls_biz_content='{"out_trade_no": "2015020011","scene": "bar_code","auth_code": "'+sle_1.Text+'","subject": "當面付條碼支付","total_amount": "0.01"}' ls_str ="app_id="+ls_appId ls_str +='&biz_content='+ls_biz_content ls_str +='&charset=utf-8' ls_str +='&method=alipay.trade.pay' ls_str +='&sign_type=RSA' ls_str +='×tamp=2016-05-08 11:27:15' ls_str +='&version=1.0' string ls_sigStr blob utf8R utf8R =lnv_cryp.of_str2utf8(ls_str) if lnv_cryp.of_sha1withRsa(ls_priFileName,utf8R,lnv_cryp.HASH_RESULT_DEFAULT,ls_sigStr) then MessageBox("提示","簽名成功:"+ls_sigStr) Else MessageBox("提示","簽名失敗") end if /*驗證簽名可以不需要調用*/ ls_pubFileName ="D:\pbfunclib_pub.pem"//在D盤生成公鑰文件pbfunclib_pub.pem IF Not lnv_cryp.of_RSAVerifyFileSHA1(ls_pubFileName,utf8R,ls_sigStr,lnv_cryp.HASH_RESULT_DEFAULT) Then MessageBox("提示","驗證簽名失敗") else messagebox("","驗證簽名成功") End IF //ls_str +='' n_pbfunc_http lnv_http lnv_http.of_clear()//清空參數 string ls_data ls_data = "app_id="+wf_alipay_urlencode(ls_appId) ls_data += "&biz_content="+wf_alipay_urlencode(ls_biz_content) ls_data += "&charset="+wf_alipay_urlencode("utf-8") ls_data += "&method="+wf_alipay_urlencode("alipay.trade.pay") ls_data += "&sign_type="+wf_alipay_urlencode("RSA") ls_data += "&sign="+wf_alipay_urlencode(ls_sigStr) ls_data += "×tamp="+wf_alipay_urlencode("2016-05-08 11:27:15") ls_data += "&version="+wf_alipay_urlencode("1.0") lnv_http.of_set_URL("https://openapi.alipay.com/gateway.do?"+ls_data) Blob lblb_data string ls_error IF lnv_http.of_post(lblb_data,ls_error) Then string gbkData gbkData = lnv_cryp.of_utf8ToGbk(lblb_data)//由於返回來的是utf-8編碼,直接顯示會亂碼 MessageBox("提示",gbkData+" "+string(lblb_data)) Else MessageBox("提示","執行失敗") End IF
其中wf_alipay_urlencode函數代碼如下:
//ls_str為參數 n_pbfunc_encode lnv_encode string ls_content,ls_reserved//指明不需要編碼的字符 ls_reserved =""//都需要編碼 string ls_sigStr blob utf8R utf8R =lnv_encode.of_str2utf8(ls_str) lnv_encode.of_URIEncode2(utf8R,ls_content) return ls_content
以上所述是小編給大家介紹的使用PBFunc在Powerbuilder中支付寶當面付款功能,希望對大家有所幫助,如果大家有任何疑問歡迎給我留言,小編會及時回復的。