轉載自:http://my.oschina.net/xshuai/blog/313809
關於即時到賬的開發。審核通過。簡單測試如下。
希望看的可以收藏或者贊一下哦。
1:擁有自己的支付寶企業賬號。去產品商店選擇適合自己的方案。並簽約合同。
2:選擇合適的商家收款產品並去簽約。填寫相應的信息
3:在商家服務會有PID和KEY是關鍵的東西。
4:選擇自己簽約的產品類型,下載對應的接口api與測試代碼
官方給用戶自己提供了10種功能的代碼。
5:alipaydirect_bankpay_single 測試
在核心代碼alipayconfig需要更改自己的partner和key
6:測試界面
7:網銀銀行簡碼
網銀銀行簡碼 | |
BOCB2C | 中國銀行 |
ICBCB2C | 中國工商銀行 |
ICBCBTB | 中國工商銀行(B2B) |
CMB | 招商銀行 |
CCB | 中國建設銀行 |
CCBBTB | 中國建設銀行(B2B) |
ABC | 中國農業銀行 |
ABCBTB | 中國農業銀行(B2B) |
SPDB | 上海浦東發展銀行 |
SPDBB2B | 上海浦東發展銀行(B2B) |
CIB | 興業銀行 |
GDB | 廣東發展銀行 |
SDB | 深圳發展銀行 |
CMBC | 中國民生銀行 |
COMM | 交通銀行 |
CITIC | 中信銀行 |
CEBBANK | 光大銀行 |
NBBANK | 寧波銀行 |
HZCBB2C | 杭州銀行 |
SHBANK | 上海銀行 |
SPABANK | 平安銀行 |
BJRCB | 北京農村商業銀行 |
fdb101 | 富滇銀行 |
PSBC-DEBIT | 中國郵政儲蓄銀行 |
BJBANK | 北京銀行 |
8:錯誤代碼錯誤說明
誤代碼 | 說明 |
EXPARTNER_INFO_UNCORRECT | 傳入外部商戶接口信息不正確 |
TRADE_BUYER_NOT_MATCH | 買家賬戶與交易中不一致 |
TRADE_SELLER_NOT_MATCH | 賣家賬戶與交易中不一致 |
TRADE_DATA_NOT_MATCH | 請求數據與交易中不一致 |
SELLER_NOT_IN_SPECIFIED_SELLERS | 賣家不在指定的商戶限制賣家中 |
ILLEGAL_SIGN | 簽名驗證出錯 |
ILLEGAL_ARGUMENT | 輸入參數有錯誤 |
HASH_NO_PRIVILEGE | 沒有權限訪問該服務 |
ILLEGAL_SERVICE | service參數不正確 |
ILLEGAL_PARTNER | 合作身份者ID不正確 |
HAS_NO_PUBLICKEY | 沒有上傳公鑰 |
USER_NOT_EXIST | 會員不存在 |
OUT_TRADE_NO_EXIST | 外部交易號已經存在 |
TRADE_NOT_EXIST | 交易不存在 |
ILLEGAL_PAYMENT_TYPE | 無效支付類型 |
BUYER_NOT_EXIST | 買家不存在 |
SELLER_NOT_EXIST | 賣家不存在 |
BUYER_SELLER_EQUAL | 買家、賣家是同一帳戶 |
ILLEGAL_SIGN_TYPE | 簽名類型不正確 |
COMMISION_ID_NOT_EXIST | 佣金收取帳戶不存在 |
COMMISION_SELLER_DUPLICATE | 收取佣金帳戶和賣家是同一帳戶 |
出現的錯誤代碼為ILLEGAL_PARTNER_EXTERFACE
1、沒有簽約這個接口的合同。
2、簽約了相應的接口合同,但沒有生效。
3、簽約了相應的接口合同,但由於違規違法等原因被審核部門強制關閉。
9:頁面需要修改的東西alipayapi.jsp
10:跳轉頁面第6步有截圖。賣家賬號收款的賬號。不是付款的賬號哦。
如果調試登錄了收款的支付寶賬號。會出錯的哦。錯誤截圖如下
錯誤代碼:BUYER_SELLER_EQUAL
如果調試登錄了收款的支付寶賬號。而且頁面填寫的賣家賬號非賣家賬號(收款賬號)會出現如下錯誤
錯誤代碼:SELLER_NOT_IN_SPECIFIED_SELLERS
如果沒有錯誤。則會直接跳轉付款頁面。輸入買家賬號即可。
11:成功付款的頁面。付款頁面需要輸入購買用戶的支付寶賬號和支付密碼
12:使用springMVC封裝寫符合自己網站需求的代碼。以下代碼僅參考
這個是ALIPAYAPI代碼要獲取數據的
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
Date date =
new
Date();
//支付類型 必填 不必修改
String payment_type =
"1"
;
//服務器異步通知頁面路徑
//需http://格式的完整路徑,不能加?id=123這類自定義參數
String notify_url =
"http://localhost:8080/alipay/async"
;
//頁面跳轉同步通知頁面路徑
//需http://格式的完整路徑,不能加?id=123這類自定義參數,不能寫成http://localhost/
String return_url =
"http://192.168.0.222:8080/alipay/return_url"
;
//訂單名稱
//必填
// String subject = new String(request.getParameter("WIDsubject").getBytes("ISO-8859-1"),"UTF-8");
String subject =
new
String(
"測試商品"
.getBytes(
"ISO-8859-1"
),
"UTF-8"
);
//付款金額
//必填
// String total_fee = new String(request.getParameter("WIDtotal_fee").getBytes("ISO-8859-1"),"UTF-8");
String total_fee =
"0.01"
;
Map<String, String> sParaTemp =
new
HashMap<String, String>();
sParaTemp.put(
"service"
,
"create_direct_pay_by_user"
);
//接口服務----即時到賬
sParaTemp.put(
"partner"
, AlipayConfig.partner);
//支付寶PID
sParaTemp.put(
"_input_charset"
, AlipayConfig.input_charset);
//統一編碼
sParaTemp.put(
"payment_type"
, payment_type);
//支付類型
sParaTemp.put(
"notify_url"
, notify_url);
//異步通知頁面
sParaTemp.put(
"return_url"
, return_url);
//頁面跳轉同步通知頁面
sParaTemp.put(
"seller_email"
, Constants.SELLER_EMAIL);
//賣家支付寶賬號
sParaTemp.put(
"out_trade_no"
, date.getTime()+payment_type);
//商品訂單編號
sParaTemp.put(
"subject"
, subject);
//商品名稱
sParaTemp.put(
"total_fee"
, total_fee);
//價格
//建立請求
String sHtmlText = AlipaySubmit.buildRequest(sParaTemp,
"get"
,
"立即付款"
);
request.setAttribute(
"sHtmlText"
, sHtmlText);
return
null
;
|
付款是否成功的代碼
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
Map<String , String> params =
new
HashMap<String, String>();
Map requestParams = request.getParameterMap();
for
(Iterator iter = requestParams.keySet().iterator(); iter.hasNext();) {
String name = (String) iter.next();
String[] values = (String[]) requestParams.get(name);
String valueStr =
""
;
for
(
int
i =
0
; i < values.length; i++) {
valueStr = (i == values.length -
1
)? valueStr + values[i]:valueStr+values[i]+
","
;
}
params.put(name, valueStr);
}
String tradeNo = request.getParameter(
"out_trade_no"
);
String tradeStatus = request.getParameter(
"trade_status"
);
if
(AlipayNotify.verify(params)){
if
(tradeStatus.equals(
"TRADE_FINISHED"
) || tradeStatus.equals(
"TRADE_SUCCESS"
)){
System.out.println(
"ok!>>>>>>>>"
+ tradeNo);
}
return
"success"
;
}
else
{
return
"fail"
;
}
}
|
13:使用springMVC封裝寫符合自己網站需求的代碼。以下代碼僅參考 全部都寫在一個Controller里面
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
|
/**
* 支付寶Controller
* @author 宗瀟帥
* @修改日期 2014-9-25下午1:29:53
*/
@Controller
@RequestMapping
(value=
"/aliapi"
)
public
class
AlipayApiController {
private
static
Log log = LogFactory.getLog(AlipayApiController.
class
);
@RequestMapping
(value=
"/index"
)
public
String index(HttpServletRequest request,
HttpServletResponse response){
return
"web/pay/fund"
;
//付款的頁面。本頁面是為了測試而使用的
}
@RequestMapping
(value =
"/deposit"
, method = RequestMethod.POST,produces =
"application/json"
)
public
String deposit(HttpServletRequest request,HttpServletResponse response,Model model)
throws
Exception {
// PrintWriter out = response.getWriter();
String result =
""
;
Date date =
new
Date();
// 支付類型
// 必填,不能修改
String payment_type =
"1"
;
// 服務器異步通知頁面路徑
// 需http://格式的完整路徑,不能加?id=123這類自定義參數
String notify_url =
"http://192.168.0.222:8080/live/aliapi/async"
;
// 頁面跳轉同步通知頁面路徑
// 需http://格式的完整路徑,不能加?id=123這類自定義參數,不能寫成http://localhost/
String return_url =
"http://192.168.0.222:8080/live/aliapi/return_url"
;
// 商戶訂單號.
// 商戶網站訂單系統中唯一訂單號,必填
//String out_trade_no = date.getTime() + "";
// 訂單名稱
// 必填
String subject =
"充值測試"
;
// 防釣魚時間戳
// 若要使用請調用類文件submit中的query_timestamp函數
String anti_phishing_key =
""
;
// 客戶端的IP地址
// 非局域網的外網IP地址,如:221.0.0.1
String exter_invoke_ip =
""
;
String total_fee = ServletRequestUtils.getStringParameter(request,
"amount"
,
""
);
String body = ServletRequestUtils.getStringParameter(request,
"body"
,
"test"
);
//商品展示地址
String show_url = ServletRequestUtils.getStringParameter(request,
"show_url"
,
"http://www.elve.cn"
);
//需以http://開頭的完整路徑,例如:http://www.xxx.com/myorder.html
Map<String, String> sParaTemp =
new
HashMap<String, String>();
sParaTemp.put(
"service"
,
"create_direct_pay_by_user"
);
//接口服務----即時到賬
sParaTemp.put(
"partner"
, AlipayConfig.partner);
//支付寶PID
sParaTemp.put(
"_input_charset"
, AlipayConfig.input_charset);
//統一編碼
sParaTemp.put(
"payment_type"
, payment_type);
//支付類型
sParaTemp.put(
"notify_url"
, notify_url);
//異步通知頁面
sParaTemp.put(
"return_url"
, return_url);
//頁面跳轉同步通知頁面
sParaTemp.put(
"seller_email"
, Constants.SELLER_EMAIL);
//賣家支付寶賬號
sParaTemp.put(
"out_trade_no"
, date.getTime()+payment_type);
//商品訂單編號
sParaTemp.put(
"subject"
, subject);
//商品名稱
sParaTemp.put(
"total_fee"
, total_fee);
//價格
sParaTemp.put(
"body"
, body);
sParaTemp.put(
"show_url"
, show_url);
sParaTemp.put(
"anti_phishing_key"
, anti_phishing_key);
sParaTemp.put(
"exter_invoke_ip"
, exter_invoke_ip);
//建立請求
try
{
String sHtmlText = AlipaySubmit.buildRequest(sParaTemp,
"post"
,
"確認"
);
Gson gson =
new
GsonBuilder().setDateFormat(
"yyyy-MM-dd HH:mm:ss"
).create();
String s = gson.toJson(sHtmlText);
model.addAttribute(
"sHtmlText"
, s);
request.setAttribute(
"sHtmlText"
, s);
result =
"{\"success\":true,\"msg\":\"跳轉成功\"}"
;
StringUtil.writeToWeb(sHtmlText,
"html"
, response);
return
null
;
}
catch
(Exception e) {
if
(log.isErrorEnabled()){
log.error(
"ddddddddddddddddddddd"
);
}
result =
"{\"success\":false,\"msg\":\"跳轉失敗,請稍候再試!\"}"
;
StringUtil.writeToWeb(result,
"html"
, response);
return
null
;
}
}
/**
* 同步通知的頁面的Controller
* @param request
* @param response
* @return
* @author 宗瀟帥
*/
@RequestMapping
(value=
"/return_url"
)
public
String Return_url(HttpServletRequest request,HttpServletResponse response){
return
"web/pay/success"
;
}
/**
* 異步通知付款狀態的Controller
* @param request
* @param response
* @return
* @author 宗瀟帥
*/
@SuppressWarnings
(
"rawtypes"
)
@RequestMapping
(value=
"/async"
,method = RequestMethod.GET)
public
String async(HttpServletRequest request,
HttpServletResponse response){
Map<String,String> params =
new
HashMap<String,String>();
Map requestParams = request.getParameterMap();
for
(Iterator iter = requestParams.keySet().iterator(); iter.hasNext();) {
String name = (String) iter.next();
String[] values = (String[]) requestParams.get(name);
String valueStr =
""
;
for
(
int
i =
0
; i < values.length; i++) {
valueStr = (i == values.length -
1
) ? valueStr + values[i]: valueStr + values[i] +
","
;
}
params.put(name, valueStr);
}
String tradeNo = request.getParameter(
"out_trade_no"
);
String tradeStatus = request.getParameter(
"trade_status"
);
//String notifyId = request.getParameter("notify_id");
if
(AlipayNotify.verify(params)){
//驗證成功
if
(tradeStatus.equals(
"TRADE_FINISHED"
) || tradeStatus.equals(
"TRADE_SUCCESS"
)) {
//要寫的邏輯。自己按自己的要求寫
log.error(
"ok......."
);
System.out.println(
">>>>>充值成功"
+ tradeNo);
}
return
"web/pay/success"
;
}
else
{
//驗證失敗
return
"web/pay/fail"
;
}
}
}
|
14:JSP付款頁面表單提交數據並彈出付款頁面
只做了簡單的表單提交。可以根據自己的要求修改
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
<%@ page contentType=
"text/html;charset=UTF-8"
%>
<!DOCTYPE html>
<html xmlns=
"http://www.w3.org/1999/xhtml"
>
<head>
<meta http-equiv=
"Content-Type"
content=
"text/html; charset=utf-8"
/>
<%@ include file=
"/common/webMeta.jsp"
%>
<title>www.elve.cn</title>
<meta content=
"www.elve.cn"
name=
"keywords"
/>
<meta content=
"www.elve.cn"
name=
"description"
/>
</head>
<script type=
"text/javascript"
>
$(function(){
$(
"#amount"
).focus();
$(
"#doSubmit"
).click(function(){
form1.submit();
});
});
</script>
<body>
<form id=
"form1"
action=
"${ctx }/aliapi/deposit"
method=
"post"
target=
"_blank"
>
<table cellpadding=
"10"
>
<tr>
<td>充值測試</td>
<td
class
=
"balance"
id=
"userBalance"
></td>
</tr>
<tr>
<td><i
class
=
"zfb"
></i></td>
<td style=
"padding-bottom: 0px;"
>親愛的<span
class
=
"suppliment_user"
id=
"suppliment_user"
></span>,您可以使用支付寶充值積善分,請填寫以下信息
</td>
</tr>
<tr>
<td></td>
<td>
金額<input type=
"text"
name=
"amount"
id=
"amount"
>
</td>
</tr>
<tr>
<td></td>
<td><a href=
"javascript:void(0);"
id=
"doSubmit"
class
=
"blank_btn"
>確認</a></td>
</tr>
</table>
</form>
</body>
</html>
|