在PB实现支付宝当面付的功能,需要先在支付宝进行商户签约,并设置相关的公钥信息(具体参考支付宝文档)。
然后使用对应的私钥文件对参数进RSAWithSha1前面计算。具体代码如下:
string ls_pubFileName,ls_priFileNamen_pbfunc_cryp lnv_crypls_priFileName ="D:/pbfunclib_pri.pem"//私钥文件string ls_strstring ls_appId,ls_secret,ls_biz_contentls_appId ="3434343"//改成你的appidls_biz_content='{"out_trade_no": "2015020011","scene": "bar_code","auth_code": "'+sle_1.Text+'","subject": "当面付条码支付","total_amount": "0.01"}'ls_str ="app_id="+ls_appIdls_str +='&biz_content='+ls_biz_contentls_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_sigStrblob utf8Rutf8R =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.pemIF 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_httplnv_http.of_clear()//清空参数string ls_datals_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_datastring ls_errorIF 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_encodestring ls_content,ls_reserved//指明不需要编码的字符ls_reserved =""//都需要编码string ls_sigStrblob utf8Rutf8R =lnv_encode.of_str2utf8(ls_str)lnv_encode.of_URIEncode2(utf8R,ls_content)return ls_content
以上所述是小编给大家介绍的使用PBFunc在Powerbuilder中支付宝当面付款功能,希望对大家有所帮助,如果大家有任何疑问欢迎给我留言,小编会及时回复的。
新闻热点
疑难解答