使用PBFunc在Powerbuilder中支付宝当面付款功能
在PB实现支付宝当面付的功能,需要先在支付宝进行商户签约,并设置相关的公钥信息(具体参考支付宝文档)。
然后使用对应的私钥文件对参数进RSAWithSha1前面计算。具体代码如下:
stringls_pubFileName,ls_priFileName n_pbfunc_cryplnv_cryp ls_priFileName="D:\pbfunclib_pri.pem"//私钥文件 stringls_str stringls_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-0811:27:15' ls_str+='&version=1.0' stringls_sigStr blobutf8R utf8R=lnv_cryp.of_str2utf8(ls_str) iflnv_cryp.of_sha1withRsa(ls_priFileName,utf8R,lnv_cryp.HASH_RESULT_DEFAULT,ls_sigStr)then MessageBox("提示","签名成功:"+ls_sigStr) Else MessageBox("提示","签名失败") endif /*验证签名可以不需要调用*/ ls_pubFileName="D:\pbfunclib_pub.pem"//在D盘生成公钥文件pbfunclib_pub.pem IFNotlnv_cryp.of_RSAVerifyFileSHA1(ls_pubFileName,utf8R,ls_sigStr,lnv_cryp.HASH_RESULT_DEFAULT)Then MessageBox("提示","验证签名失败") else messagebox("","验证签名成功") EndIF //ls_str+='' n_pbfunc_httplnv_http lnv_http.of_clear()//清空参数 stringls_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-0811:27:15") ls_data+="&version="+wf_alipay_urlencode("1.0") lnv_http.of_set_URL("https://openapi.alipay.com/gateway.do?"+ls_data) Bloblblb_data stringls_error IFlnv_http.of_post(lblb_data,ls_error)Then stringgbkData gbkData=lnv_cryp.of_utf8ToGbk(lblb_data)//由于返回来的是utf-8编码,直接显示会乱码 MessageBox("提示",gbkData+""+string(lblb_data)) Else MessageBox("提示","执行失败") EndIF
其中wf_alipay_urlencode函数代码如下:
//ls_str为参数 n_pbfunc_encodelnv_encode stringls_content,ls_reserved//指明不需要编码的字符 ls_reserved=""//都需要编码 stringls_sigStr blobutf8R utf8R=lnv_encode.of_str2utf8(ls_str) lnv_encode.of_URIEncode2(utf8R,ls_content) returnls_content
以上所述是小编给大家介绍的使用PBFunc在Powerbuilder中支付宝当面付款功能,希望对大家有所帮助,如果大家有任何疑问欢迎给我留言,小编会及时回复的。