zoukankan      html  css  js  c++  java
  • 利用PBFunc在Powerbuilder中支付宝当面付功能

    在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 +='&timestamp=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 += "&timestamp="+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
    

      demo代码详见w_rsa窗体的SHA1WithRSA按钮下载地址:

    http://download.csdn.net/detail/my_aa/9644084

  • 相关阅读:
    团队项目前期冲刺-5
    团队项目前期冲刺-4
    团队项目前期冲刺-3
    团队项目前期冲刺-2
    团队计划会议
    团队项目前期冲刺-1
    大道至简阅读笔记01
    软件工程第八周总结
    梦断代码阅读笔记03
    小组团队项目的NABCD分析
  • 原文地址:https://www.cnblogs.com/wangxianjin/p/5925140.html
Copyright © 2011-2022 走看看