然后使用对应的私钥文件对参数进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中支付宝当面付款功能,希望对大家有所帮助,如果大家有任何疑问欢迎给我留言,小编会及时回复的。
您可能感兴趣的文章: