要接入支付宝,首先需要了解支付宝的接入流程,可以通过官方文档了解快速接入
支付宝接入需要密钥,密钥如果保存在客户端,存在泄漏的风险,推荐密钥保存在服务端
PB可以通过 SATRDA 组件实现服务器接入支付宝,
SATRDA下载地址:http://download.csdn.net/detail/pcwe2002/9620563
下载完成后,可以开始配置详细配置可以参考说明文档。
PB端调用代码
long ll_rtn,ll_http,ll_len
ulong ll_data,ll_buffer,ll_json,ll_rs
String ls_json,ls_null,ls_server,ls_code
long ll_start
ls_null = ""
ls_server = sle_url.text + "/alipay/precreate"
ll_http = n_api.SATHTTP_Create()
n_api.SatHttp_addformdata( ll_http, "out_trade_no", sle_no.text)
n_api.SatHttp_addformdata( ll_http, "subject", n_api.ansi_to_utf8(sle_subject.text))
n_api.SatHttp_addformdata( ll_http, "total_amount", sle_je.text)
//n_api.SATHTTP_UseGZIP( ll_http, true)
ll_rtn = n_api.SATHTTP_PostForm(ll_http,ls_server)
if ll_rtn <> 200 and ll_rtn <> 500 then
messagebox("","失败," + string(ll_rtn))
else
//得到Http返回数据
ll_buffer = n_api.SATHTTP_GetBuffer(ll_http)
n_api.Buffer_Append(ll_buffer,n_api.StringToPtr(ls_null),1) 插入1个0
ll_data = n_api.Buffer_Data(ll_buffer) //数据内容
ll_len = n_api.Buffer_Size(ll_buffer) //取大小
ls_json = string(ll_data,"address")
if ll_rtn = 500 then
messagebox("内部错误",n_api.UTF8_TO_ANSI(ls_json))
return
end if
messagebox("",ls_json)
ll_json = n_api.JsonObject_Create(ls_json)
ll_rs = n_api.JsonObject_Get(ll_json, "alipay_trade_precreate_response")
ls_code = n_api.JsonObject_GetString(ll_rs,"code")
if ls_code = "10000" then
ls_code = n_api.JsonObject_GetString(ll_rs,"qr_code")
of_qrcode(ls_code,128)
end if
end if
n_api.SATHTTP_Destroy(ll_http)
示例界面
QQ群:345559891 (交流、下载最新版本)