Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
T
TopUpCambodian-java
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
hewei
TopUpCambodian-java
Commits
346342bd
Commit
346342bd
authored
Apr 15, 2021
by
giaogiao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
增加paygo通道
parent
63d0f414
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
1510 additions
and
343 deletions
+1510
-343
src/com/library/TopUp/Statel/SeatelSentUtils.java
+93
-181
src/com/library/test/PaygoTest.java
+135
-103
src/com/library/test/PaygoTest2.java
+616
-0
src/com/library/test/PaygoTest3.java
+656
-0
src/com/library/util/Paygo24Utils.java
+10
-59
No files found.
src/com/library/TopUp/Statel/SeatelSentUtils.java
View file @
346342bd
package
com
.
library
.
TopUp
.
Statel
;
package
com
.
library
.
TopUp
.
Statel
;
import
com.google.gson.Gson
;
import
com.google.gson.Gson
;
import
com.google.gson.JsonObject
;
import
com.google.gson.JsonObject
;
import
com.google.gson.JsonParser
;
import
com.google.gson.JsonParser
;
import
com.library.TopUp.Http.HttpUtils
;
import
com.library.TopUp.Http.HttpsTool
;
import
com.library.TopUp.model.ResultsModel
;
import
com.library.TopUp.model.ResultsModel
;
import
com.library.respcode.ServerResponse
;
import
com.wechat.pay.MD5Util
;
import
com.wechat.pay.MD5Util
;
import
org.apache.http.util.TextUtils
;
import
org.apache.http.util.TextUtils
;
import
java.math.BigDecimal
;
import
java.math.BigDecimal
;
import
java.net.URLEncoder
;
import
java.text.SimpleDateFormat
;
import
java.text.SimpleDateFormat
;
import
java.util.*
;
import
java.util.Date
;
import
java.util.HashMap
;
import
java.util.Map
;
import
java.util.Random
;
import
java.util.SimpleTimeZone
;
import
java.util.TimeZone
;
import
java.util.UUID
;
public
class
SeatelSentUtils
{
public
class
SeatelSentUtils
{
public
static
final
String
url
=
"http://172.22.188.20:11800/SeatelPayment/pay.jsp"
;
private
static
final
String
shopid
=
"linkasia"
;
private
static
final
String
private_key
=
"a562065907364aacedb102375a01fb39"
;
private
static
final
String
terminalid
=
"linkasia001"
;
public
SeatelSentUtils
()
{
}
public
final
static
String
url
=
"http://172.22.188.20:11999/SeatelPayment/pay.jsp"
;
//测试
// public final static String url = "http://172.22.188.20:11800/SeatelPayment/pay.jsp";//生产
private
final
static
String
shopid
=
"shoptest"
;
private
final
static
String
private_key
=
"9834a62b4ec7c78a5424932bfdedfd74"
;
private
final
static
String
terminalid
=
"shoptest0001"
;
/**
/**
* 检查手机是否能充值
* 检查手机是否能充值
...
@@ -32,38 +36,27 @@ public class SeatelSentUtils {
...
@@ -32,38 +36,27 @@ public class SeatelSentUtils {
* @return
* @return
*/
*/
public
static
String
checkPhone
(
String
phone
)
{
public
static
String
checkPhone
(
String
phone
)
{
try
{
try
{
String
time
=
getFormatedDateString
(
7.0
F
);
String
time
=
getFormatedDateString
(
7
);
String
cmd
=
"queryphonenumberstatus"
;
String
cmd
=
"queryphonenumberstatus"
;
String
terminaltrace
=
"shoptest186"
+
new
Random
().
nextInt
(
10000
);
String
terminaltrace
=
"linkasia1"
+
(
new
Random
()).
nextInt
(
10000
);
Map
params
=
new
HashMap
();
Map
params
=
new
HashMap
();
params
.
put
(
"cmd"
,
cmd
);
params
.
put
(
"cmd"
,
cmd
);
params
.
put
(
"shopid"
,
shopid
);
params
.
put
(
"shopid"
,
"linkasia"
);
params
.
put
(
"terminalid"
,
terminalid
);
params
.
put
(
"terminalid"
,
"linkasia001"
);
params
.
put
(
"terminaltrace"
,
terminaltrace
);
params
.
put
(
"terminaltrace"
,
terminaltrace
);
params
.
put
(
"transtime"
,
time
);
params
.
put
(
"transtime"
,
time
);
params
.
put
(
"phone"
,
phone
);
params
.
put
(
"phone"
,
phone
);
params
.
put
(
"signtype"
,
"MD5"
);
params
.
put
(
"signtype"
,
"MD5"
);
String
sign
=
getSignStr
(
cmd
,
terminaltrace
,
time
,
phone
);
String
sign
=
getSignStr
(
cmd
,
terminaltrace
,
time
,
phone
);
params
.
put
(
"sign"
,
sign
);
params
.
put
(
"sign"
,
sign
);
Map
<
String
,
String
>
heardMap
=
new
HashMap
();
Map
<
String
,
String
>
heardMap
=
new
HashMap
<>();
heardMap
.
put
(
"Content-Type"
,
"application/json"
);
heardMap
.
put
(
"Content-Type"
,
"application/json"
);
heardMap
.
put
(
"Accept"
,
"application/json"
);
heardMap
.
put
(
"Accept"
,
"application/json"
);
String
json
=
HttpClientUtils
.
postWithJson
((
new
Gson
()).
toJson
(
params
),
"http://172.22.188.20:11800/SeatelPayment/pay.jsp"
,
heardMap
);
// HttpClientResult clientResult = HttpClientUtils.doGet(url, heardMap, params);
String
json
=
HttpClientUtils
.
postWithJson
(
new
Gson
().
toJson
(
params
),
url
,
heardMap
);
return
json
;
return
json
;
}
catch
(
Exception
var8
)
{
}
catch
(
Exception
e
)
{
var8
.
printStackTrace
();
e
.
printStackTrace
();
return
null
;
return
null
;
}
}
}
}
...
@@ -74,48 +67,28 @@ public class SeatelSentUtils {
...
@@ -74,48 +67,28 @@ public class SeatelSentUtils {
* @return
* @return
*/
*/
public
static
String
checkPhone2
(
String
phone
)
{
public
static
String
checkPhone2
(
String
phone
)
{
try
{
try
{
String
time
=
getFormatedDateString
(
7.0
F
);
String
time
=
getFormatedDateString
(
7
);
String
cmd
=
"queryphonenumberstatus"
;
String
cmd
=
"queryphonenumberstatus"
;
String
terminaltrace
=
UUID
.
randomUUID
().
toString
().
replace
(
"-"
,
""
);
String
terminaltrace
=
UUID
.
randomUUID
().
toString
().
replace
(
"-"
,
""
);
// String terminaltrace = generateKey()+new Random().nextInt(10000);;
Map
params
=
new
HashMap
();
Map
params
=
new
HashMap
();
params
.
put
(
"cmd"
,
cmd
);
params
.
put
(
"cmd"
,
cmd
);
params
.
put
(
"shopid"
,
shopid
);
params
.
put
(
"shopid"
,
"linkasia"
);
params
.
put
(
"terminalid"
,
terminalid
);
params
.
put
(
"terminalid"
,
"linkasia001"
);
params
.
put
(
"terminaltrace"
,
terminaltrace
);
params
.
put
(
"terminaltrace"
,
terminaltrace
);
params
.
put
(
"transtime"
,
time
);
params
.
put
(
"transtime"
,
time
);
params
.
put
(
"phone"
,
phone
);
params
.
put
(
"phone"
,
phone
);
params
.
put
(
"signtype"
,
"MD5"
);
params
.
put
(
"signtype"
,
"MD5"
);
String
sign
=
getSignStr
(
cmd
,
terminaltrace
,
time
,
phone
);
String
sign
=
getSignStr
(
cmd
,
terminaltrace
,
time
,
phone
);
params
.
put
(
"sign"
,
sign
);
params
.
put
(
"sign"
,
sign
);
Map
<
String
,
String
>
heardMap
=
new
HashMap
();
Map
<
String
,
String
>
heardMap
=
new
HashMap
<>();
heardMap
.
put
(
"Content-Type"
,
"application/json"
);
heardMap
.
put
(
"Content-Type"
,
"application/json"
);
heardMap
.
put
(
"Accept"
,
"application/json"
);
heardMap
.
put
(
"Accept"
,
"application/json"
);
String
strJson
=
"{\"cmd\":\""
+
cmd
+
"\",\"shopid\":\""
+
"linkasia"
+
"\",\"terminalid\":\""
+
"linkasia001"
+
"\",\"terminaltrace\":\""
+
terminaltrace
+
"\",\"transtime\":\""
+
time
+
"\",\"phone\":\""
+
phone
+
"\",\"signtype\":\"MD5\",\"sign\":\""
+
sign
+
"\",}"
;
String
strJson
=
"{"
+
String
json
=
HttpClientUtils
.
postWithJson
(
strJson
,
"http://172.22.188.20:11800/SeatelPayment/pay.jsp"
,
heardMap
);
"\"cmd\":"
+
"\""
+
cmd
+
"\""
+
","
+
"\"shopid\":"
+
"\""
+
shopid
+
"\""
+
","
+
"\"terminalid\":"
+
"\""
+
terminalid
+
"\""
+
","
+
"\"terminaltrace\":"
+
"\""
+
terminaltrace
+
"\""
+
","
+
"\"transtime\":"
+
"\""
+
time
+
"\""
+
","
+
"\"phone\":"
+
"\""
+
phone
+
"\""
+
","
+
"\"signtype\":"
+
"\""
+
"MD5"
+
"\""
+
","
+
"\"sign\":"
+
"\""
+
sign
+
"\""
+
","
+
"}"
;
String
json
=
HttpClientUtils
.
postWithJson
(
strJson
,
url
,
heardMap
);
return
json
;
return
json
;
}
catch
(
Exception
var9
)
{
}
catch
(
Exception
e
)
{
var9
.
printStackTrace
();
e
.
printStackTrace
();
return
null
;
return
null
;
}
}
}
}
...
@@ -126,34 +99,19 @@ public class SeatelSentUtils {
...
@@ -126,34 +99,19 @@ public class SeatelSentUtils {
* @return
* @return
*/
*/
public
static
String
queryAgentFee
()
{
public
static
String
queryAgentFee
()
{
try
{
try
{
String
time
=
getFormatedDateString
(
7.0
F
);
String
time
=
getFormatedDateString
(
7
);
String
cmd
=
"queryagentfee"
;
String
cmd
=
"queryagentfee"
;
String
terminaltrace
=
"shoptest183"
+
new
Random
().
nextInt
(
10000
);
String
terminaltrace
=
"shoptest183"
+
(
new
Random
()).
nextInt
(
10000
);
String
sign
=
getSignStr
(
cmd
,
terminaltrace
,
time
,
""
);
String
sign
=
getSignStr
(
cmd
,
terminaltrace
,
time
,
""
);
Map
<
String
,
String
>
heardMap
=
new
HashMap
();
Map
<
String
,
String
>
heardMap
=
new
HashMap
<>();
heardMap
.
put
(
"Content-Type"
,
"application/json"
);
heardMap
.
put
(
"Content-Type"
,
"application/json"
);
heardMap
.
put
(
"Accept"
,
"application/json"
);
heardMap
.
put
(
"Accept"
,
"application/json"
);
String
strJson
=
"{\"cmd\":\""
+
cmd
+
"\",\"shopid\":\""
+
"linkasia"
+
"\",\"terminalid\":\""
+
"linkasia001"
+
"\",\"terminaltrace\":\""
+
terminaltrace
+
"\",\"transtime\":\""
+
time
+
"\",\"signtype\":\"MD5\",\"sign\":\""
+
sign
+
"\",}"
;
String
strJson
=
"{"
+
String
json
=
HttpClientUtils
.
postWithJson
(
strJson
,
"http://172.22.188.20:11800/SeatelPayment/pay.jsp"
,
heardMap
);
"\"cmd\":"
+
"\""
+
cmd
+
"\""
+
","
+
"\"shopid\":"
+
"\""
+
shopid
+
"\""
+
","
+
"\"terminalid\":"
+
"\""
+
terminalid
+
"\""
+
","
+
"\"terminaltrace\":"
+
"\""
+
terminaltrace
+
"\""
+
","
+
"\"transtime\":"
+
"\""
+
time
+
"\""
+
","
+
"\"signtype\":"
+
"\""
+
"MD5"
+
"\""
+
","
+
"\"sign\":"
+
"\""
+
sign
+
"\""
+
","
+
"}"
;
String
json
=
HttpClientUtils
.
postWithJson
(
strJson
,
url
,
heardMap
);
return
json
;
return
json
;
}
catch
(
Exception
var7
)
{
}
catch
(
Exception
e
)
{
var7
.
printStackTrace
();
e
.
printStackTrace
();
return
null
;
return
null
;
}
}
}
}
...
@@ -166,38 +124,20 @@ public class SeatelSentUtils {
...
@@ -166,38 +124,20 @@ public class SeatelSentUtils {
* @return
* @return
*/
*/
public
static
String
crmRecharge
(
String
phone
,
int
amount
)
{
public
static
String
crmRecharge
(
String
phone
,
int
amount
)
{
try
{
try
{
String
amountStr
=
String
.
valueOf
(
amount
*
100
);
String
amountStr
=
String
.
valueOf
(
amount
*
100
);
String
time
=
getFormatedDateString
(
7.0
F
);
String
time
=
getFormatedDateString
(
7
);
String
cmd
=
"crmrecharge"
;
String
cmd
=
"crmrecharge"
;
String
terminaltrace
=
"shoptest183"
+
new
Random
().
nextInt
(
10000
);
String
terminaltrace
=
"shoptest183"
+
(
new
Random
()).
nextInt
(
10000
);
String
sign
=
getSignInTopUp
(
cmd
,
terminaltrace
,
time
,
phone
,
amountStr
);
String
sign
=
getSignInTopUp
(
cmd
,
terminaltrace
,
time
,
phone
,
amountStr
);
Map
<
String
,
String
>
heardMap
=
new
HashMap
();
Map
<
String
,
String
>
heardMap
=
new
HashMap
<>();
heardMap
.
put
(
"Content-Type"
,
"application/json"
);
heardMap
.
put
(
"Content-Type"
,
"application/json"
);
heardMap
.
put
(
"Accept"
,
"application/json"
);
heardMap
.
put
(
"Accept"
,
"application/json"
);
String
strJson
=
"{\"cmd\":\""
+
cmd
+
"\",\"shopid\":\""
+
"linkasia"
+
"\",\"terminalid\":\""
+
"linkasia001"
+
"\",\"terminaltrace\":\""
+
terminaltrace
+
"\",\"transtime\":\""
+
time
+
"\",\"phone\":\""
+
phone
+
"\",\"amount\":"
+
amountStr
+
",\"signtype\":\"MD5\",\"sign\":\""
+
sign
+
"\",}"
;
String
strJson
=
"{"
+
String
json
=
HttpClientUtils
.
postWithJson
(
strJson
,
"http://172.22.188.20:11800/SeatelPayment/pay.jsp"
,
heardMap
);
"\"cmd\":"
+
"\""
+
cmd
+
"\""
+
","
+
"\"shopid\":"
+
"\""
+
shopid
+
"\""
+
","
+
"\"terminalid\":"
+
"\""
+
terminalid
+
"\""
+
","
+
"\"terminaltrace\":"
+
"\""
+
terminaltrace
+
"\""
+
","
+
"\"transtime\":"
+
"\""
+
time
+
"\""
+
","
+
"\"phone\":"
+
"\""
+
phone
+
"\""
+
","
+
"\"amount\":"
+
""
+
amountStr
+
""
+
","
+
"\"signtype\":"
+
"\""
+
"MD5"
+
"\""
+
","
+
"\"sign\":"
+
"\""
+
sign
+
"\""
+
","
+
"}"
;
String
json
=
HttpClientUtils
.
postWithJson
(
strJson
,
url
,
heardMap
);
return
json
;
return
json
;
}
catch
(
Exception
var10
)
{
}
catch
(
Exception
e
)
{
var10
.
printStackTrace
();
e
.
printStackTrace
();
return
null
;
return
null
;
}
}
}
}
...
@@ -209,67 +149,40 @@ public class SeatelSentUtils {
...
@@ -209,67 +149,40 @@ public class SeatelSentUtils {
* @return
* @return
*/
*/
public
static
String
queryCrmRecharge
(
String
systemtrace
)
{
public
static
String
queryCrmRecharge
(
String
systemtrace
)
{
try
{
try
{
String
time
=
getFormatedDateString
(
7.0
F
);
String
time
=
getFormatedDateString
(
7
);
String
cmd
=
"querycrmrecharge"
;
String
cmd
=
"querycrmrecharge"
;
String
terminaltrace
=
"shoptest183"
+
new
Random
().
nextInt
(
10000
);
String
terminaltrace
=
"shoptest183"
+
(
new
Random
()).
nextInt
(
10000
);
String
str
=
cmd
+
"linkasia"
+
"linkasia001"
+
terminaltrace
+
time
+
systemtrace
+
""
+
"a562065907364aacedb102375a01fb39"
;
// String sign = getSignStr(cmd, terminaltrace, time, "");
String
str
=
cmd
+
shopid
+
terminalid
+
terminaltrace
+
time
+
systemtrace
+
""
+
private_key
;
String
sign
=
MD5Util
.
MD5Encode
(
str
,
""
);
String
sign
=
MD5Util
.
MD5Encode
(
str
,
""
);
Map
<
String
,
String
>
heardMap
=
new
HashMap
();
Map
<
String
,
String
>
heardMap
=
new
HashMap
<>();
heardMap
.
put
(
"Content-Type"
,
"application/json"
);
heardMap
.
put
(
"Content-Type"
,
"application/json"
);
heardMap
.
put
(
"Accept"
,
"application/json"
);
heardMap
.
put
(
"Accept"
,
"application/json"
);
String
strJson
=
"{\"cmd\":\""
+
cmd
+
"\",\"shopid\":\""
+
"linkasia"
+
"\",\"terminalid\":\""
+
"linkasia001"
+
"\",\"terminaltrace\":\""
+
terminaltrace
+
"\",\"transtime\":\""
+
time
+
"\",\"systemtrace\":\""
+
systemtrace
+
"\",\"signtype\":\"MD5\",\"sign\":\""
+
sign
+
"\",}"
;
String
strJson
=
"{"
+
String
json
=
HttpClientUtils
.
postWithJson
(
strJson
,
"http://172.22.188.20:11800/SeatelPayment/pay.jsp"
,
heardMap
);
"\"cmd\":"
+
"\""
+
cmd
+
"\""
+
","
+
"\"shopid\":"
+
"\""
+
shopid
+
"\""
+
","
+
"\"terminalid\":"
+
"\""
+
terminalid
+
"\""
+
","
+
"\"terminaltrace\":"
+
"\""
+
terminaltrace
+
"\""
+
","
+
"\"transtime\":"
+
"\""
+
time
+
"\""
+
","
+
"\"systemtrace\":"
+
"\""
+
systemtrace
+
"\""
+
","
+
"\"signtype\":"
+
"\""
+
"MD5"
+
"\""
+
","
+
"\"sign\":"
+
"\""
+
sign
+
"\""
+
","
+
"}"
;
String
json
=
HttpClientUtils
.
postWithJson
(
strJson
,
url
,
heardMap
);
return
json
;
return
json
;
}
catch
(
Exception
var9
)
{
}
catch
(
Exception
e
)
{
var9
.
printStackTrace
();
e
.
printStackTrace
();
return
null
;
return
null
;
}
}
}
}
private
static
String
getSignStr
(
String
cmd
,
String
terminaltrace
,
String
transtime
,
String
phone
)
{
private
static
String
getSignStr
(
String
cmd
,
String
terminaltrace
,
String
transtime
,
String
phone
)
{
String
str
=
cmd
+
""
+
"linkasia"
+
"linkasia001"
+
terminaltrace
+
transtime
+
phone
+
"a562065907364aacedb102375a01fb39"
;
String
str
=
cmd
+
""
+
shopid
+
terminalid
+
terminaltrace
+
transtime
+
phone
+
private_key
;
String
md5Text
=
MD5Util
.
MD5Encode
(
str
,
""
);
String
md5Text
=
MD5Util
.
MD5Encode
(
str
,
""
);
return
md5Text
;
return
md5Text
;
}
}
private
static
String
getSignInTopUp
(
String
cmd
,
String
terminaltrace
,
String
transtime
,
String
phone
,
String
amount
)
{
private
static
String
getSignInTopUp
(
String
cmd
,
String
terminaltrace
,
String
transtime
,
String
phone
,
String
amount
)
{
String
str
=
cmd
+
""
+
"linkasia"
+
"linkasia001"
+
terminaltrace
+
transtime
+
phone
+
amount
+
"a562065907364aacedb102375a01fb39"
;
String
str
=
cmd
+
""
+
shopid
+
terminalid
+
terminaltrace
+
transtime
+
phone
+
amount
+
private_key
;
String
md5Text
=
MD5Util
.
MD5Encode
(
str
,
""
);
String
md5Text
=
MD5Util
.
MD5Encode
(
str
,
""
);
return
md5Text
;
return
md5Text
;
}
}
public
static
void
main
(
String
[]
args
)
{
public
static
void
main
(
String
[]
args
)
{
String
phone
=
"0189464112"
;
String
phone
=
"0189464112"
;
String
json
=
queryAgentFee
();
String
json
=
checkPhone
(
phone
);
System
.
out
.
println
(
json
);
System
.
out
.
println
(
json
);
// ResultsModel resultsModel = sentTopUp(phone, 1, "99999912");
//
// System.out.println("充值是否成功:" + resultsModel.isSuccessful());
// System.out.println("充值日志:" + resultsModel.getTip());
}
}
/**
/**
...
@@ -280,100 +193,99 @@ public class SeatelSentUtils {
...
@@ -280,100 +193,99 @@ public class SeatelSentUtils {
*
*
*/
*/
public
static
ResultsModel
sentTopUp
(
String
phone
,
int
topUpAmount
)
{
public
static
ResultsModel
sentTopUp
(
String
phone
,
int
topUpAmount
)
{
String
tip
=
""
;
String
tip
=
""
;
boolean
topUpSuccess
=
false
;
boolean
topUpSuccess
=
false
;
try
{
try
{
String
feeJson
=
""
;
String
feeJson
=
""
;
String
checkJson
=
checkPhone2
(
phone
);
String
checkJson
=
checkPhone2
(
phone
);
String
systemtrace
;
if
(!
TextUtils
.
isEmpty
(
checkJson
))
{
if
(!
TextUtils
.
isEmpty
(
checkJson
))
{
JsonParser
jsonParserCheck
=
new
JsonParser
();
JsonParser
jsonParserCheck
=
new
JsonParser
();
JsonObject
jsonObjectCheck
=
jsonParserCheck
.
parse
(
checkJson
).
getAsJsonObject
();
JsonObject
jsonObjectCheck
=
jsonParserCheck
.
parse
(
checkJson
).
getAsJsonObject
();
String
codeCheck
=
jsonObjectCheck
.
get
(
"code"
)
==
null
?
""
:
jsonObjectCheck
.
get
(
"code"
).
getAsString
();
systemtrace
=
jsonObjectCheck
.
get
(
"code"
)
==
null
?
""
:
jsonObjectCheck
.
get
(
"code"
).
getAsString
();
if
(!
TextUtils
.
isEmpty
(
systemtrace
)
&&
systemtrace
.
equals
(
"0"
))
{
if
(!
TextUtils
.
isEmpty
(
codeCheck
)
&&
codeCheck
.
equals
(
"0"
))
{
//号码校验成功,发起查询余额
//号码校验成功,发起查询余额
feeJson
=
queryAgentFee
();
feeJson
=
queryAgentFee
();
}
else
{
}
else
{
tip
+=
"校验号码失败;结果为:"
+
checkJson
;
tip
=
tip
+
"校验号码失败;结果为:"
+
checkJson
;
}
}
}
}
String
rechargeJson
=
""
;
String
rechargeJson
=
""
;
if
(!
TextUtils
.
isEmpty
(
feeJson
))
{
if
(!
TextUtils
.
isEmpty
(
feeJson
))
{
JsonParser
jsonParserFee
=
new
JsonParser
();
JsonParser
jsonParserFee
=
new
JsonParser
();
JsonObject
jsonObjectFee
=
jsonParserFee
.
parse
(
feeJson
).
getAsJsonObject
();
JsonObject
jsonObjectFee
=
jsonParserFee
.
parse
(
feeJson
).
getAsJsonObject
();
String
codeCheck
=
jsonObjectFee
.
get
(
"code"
)
==
null
?
""
:
jsonObjectFee
.
get
(
"code"
).
getAsString
();
String
codeCheck
=
jsonObjectFee
.
get
(
"code"
)
==
null
?
""
:
jsonObjectFee
.
get
(
"code"
).
getAsString
();
if
(!
TextUtils
.
isEmpty
(
codeCheck
)
&&
codeCheck
.
equals
(
"0"
))
{
if
(!
TextUtils
.
isEmpty
(
codeCheck
)
&&
codeCheck
.
equals
(
"0"
))
{
//接口查询成功,比较金额大小
//接口查询成功,比较金额大小
if
(
jsonObjectFee
.
get
(
"amount"
)
!=
null
)
{
if
(
jsonObjectFee
.
get
(
"amount"
)
!=
null
)
{
BigDecimal
myAmount
=
jsonObjectFee
.
get
(
"amount"
).
getAsBigDecimal
();
BigDecimal
myAmount
=
jsonObjectFee
.
get
(
"amount"
).
getAsBigDecimal
();
if
(
myAmount
.
compareTo
(
new
BigDecimal
(
topUpAmount
))
>=
0
)
{
if
(
myAmount
.
compareTo
(
new
BigDecimal
(
topUpAmount
))
>=
0
)
{
//余额充足
//余额充足
rechargeJson
=
crmRecharge
(
phone
,
topUpAmount
);
rechargeJson
=
crmRecharge
(
phone
,
topUpAmount
);
}
else
{
}
else
{
//余额不足
//余额不足
tip
+=
"余额不足,请充值"
;
tip
=
tip
+
"余额不足,请充值"
;
}
}
}
else
{
}
else
{
tip
+=
"获取不到余额信息"
;
tip
=
tip
+
"获取不到余额信息"
;
}
}
}
else
{
}
else
{
tip
+=
"查询余额失败;结果为:"
+
feeJson
;
tip
=
tip
+
"查询余额失败;结果为:"
+
feeJson
;
}
}
}
}
String
queryResultJson
=
""
;
String
queryResultJson
=
""
;
String
systemtrace
=
""
;
systemtrace
=
""
;
String
codeCheck
;
JsonParser
jsonParserResult
;
JsonObject
jsonObjectResult
;
if
(!
TextUtils
.
isEmpty
(
rechargeJson
))
{
if
(!
TextUtils
.
isEmpty
(
rechargeJson
))
{
//充值请求成功
//充值请求成功
JsonParser
jsonParserRecharge
=
new
JsonParser
();
jsonParserResult
=
new
JsonParser
();
JsonObject
jsonObjectRecharge
=
jsonParserRecharge
.
parse
(
rechargeJson
).
getAsJsonObject
();
jsonObjectResult
=
jsonParserResult
.
parse
(
rechargeJson
).
getAsJsonObject
();
String
codeCheck
=
jsonObjectRecharge
.
get
(
"code"
)
==
null
?
""
:
jsonObjectRecharge
.
get
(
"code"
).
getAsString
();
codeCheck
=
jsonObjectResult
.
get
(
"code"
)
==
null
?
""
:
jsonObjectResult
.
get
(
"code"
).
getAsString
();
if
(!
TextUtils
.
isEmpty
(
codeCheck
)
&&
codeCheck
.
equals
(
"0"
))
{
if
(!
TextUtils
.
isEmpty
(
codeCheck
)
&&
codeCheck
.
equals
(
"0"
))
{
//充值成功
//充值成功
tip
+=
"充值成功!!! 发起复查;"
;
// topUpSuccess = true;//复查成功,再更改
systemtrace
=
jsonObjectRecharge
.
get
(
"systemtrace"
)
==
null
?
""
:
jsonObjectRecharge
.
get
(
"systemtrace"
).
getAsString
();
queryResultJson
=
queryCrmRecharge
(
systemtrace
);
tip
=
tip
+
"充值成功!!! 发起复查;"
;
systemtrace
=
jsonObjectResult
.
get
(
"systemtrace"
)
==
null
?
""
:
jsonObjectResult
.
get
(
"systemtrace"
).
getAsString
();
queryResultJson
=
queryCrmRecharge
(
systemtrace
);
}
else
{
}
else
{
tip
+=
"充值失败,返回结果:"
+
rechargeJson
;
tip
=
tip
+
"充值失败,返回结果:"
+
rechargeJson
;
}
}
}
}
if
(!
TextUtils
.
isEmpty
(
queryResultJson
))
{
if
(!
TextUtils
.
isEmpty
(
queryResultJson
))
{
JsonParser
jsonParserResult
=
new
JsonParser
();
jsonParserResult
=
new
JsonParser
();
JsonObject
jsonObjectResult
=
jsonParserResult
.
parse
(
queryResultJson
).
getAsJsonObject
();
jsonObjectResult
=
jsonParserResult
.
parse
(
queryResultJson
).
getAsJsonObject
();
String
codeCheck
=
jsonObjectResult
.
get
(
"code"
)
==
null
?
""
:
jsonObjectResult
.
get
(
"code"
).
getAsString
();
codeCheck
=
jsonObjectResult
.
get
(
"code"
)
==
null
?
""
:
jsonObjectResult
.
get
(
"code"
).
getAsString
();
if
(!
TextUtils
.
isEmpty
(
codeCheck
)
&&
codeCheck
.
equals
(
"0"
))
{
if
(!
TextUtils
.
isEmpty
(
codeCheck
)
&&
codeCheck
.
equals
(
"0"
))
{
String
crmstatus
=
jsonObjectResult
.
get
(
"crmstatus"
)
==
null
?
""
:
jsonObjectResult
.
get
(
"crmstatus"
).
getAsString
();
String
crmstatus
=
jsonObjectResult
.
get
(
"crmstatus"
)
==
null
?
""
:
jsonObjectResult
.
get
(
"crmstatus"
).
getAsString
();
if
(
crmstatus
.
equals
(
"successed"
))
{
if
(
crmstatus
.
equals
(
"successed"
))
{
//检查结果,充值成功
//检查结果,充值成功
topUpSuccess
=
true
;
topUpSuccess
=
true
;
tip
+=
"检查结果,充值成功。"
;
tip
=
tip
+
"检查结果,充值成功。"
;
}
else
{
}
else
{
tip
+=
"检查结果,充值失败。"
;
tip
=
tip
+
"检查结果,充值失败。"
;
}
}
}
else
{
}
else
{
tip
+=
"请求复查错误,解析如下:"
+
queryResultJson
;
tip
=
tip
+
"请求复查错误,解析如下:"
+
queryResultJson
;
}
}
}
}
ResultsModel
resultsModel
=
new
ResultsModel
(
topUpSuccess
,
tip
,
systemtrace
);
ResultsModel
resultsModel
=
new
ResultsModel
(
topUpSuccess
,
tip
,
systemtrace
);
resultsModel
.
setTopUpNum
(
systemtrace
);
resultsModel
.
setTopUpNum
(
systemtrace
);
return
resultsModel
;
return
resultsModel
;
}
catch
(
Exception
var13
)
{
}
catch
(
Exception
e
)
{
var13
.
printStackTrace
();
e
.
printStackTrace
();
ResultsModel
resultsModel
=
new
ResultsModel
(
topUpSuccess
,
tip
);
ResultsModel
resultsModel
=
new
ResultsModel
(
topUpSuccess
,
tip
);
return
resultsModel
;
return
resultsModel
;
}
}
...
@@ -381,7 +293,8 @@ public class SeatelSentUtils {
...
@@ -381,7 +293,8 @@ public class SeatelSentUtils {
public
static
String
generateKey
()
{
public
static
String
generateKey
()
{
String
key
=
UUID
.
randomUUID
().
toString
();
String
key
=
UUID
.
randomUUID
().
toString
();
key
=
key
.
replace
(
"-"
,
""
).
substring
(
0
,
16
);
// 替换掉-号
// 替换掉-号
key
=
key
.
replace
(
"-"
,
""
).
substring
(
0
,
16
);
return
key
;
return
key
;
}
}
...
@@ -394,13 +307,13 @@ public class SeatelSentUtils {
...
@@ -394,13 +307,13 @@ public class SeatelSentUtils {
* @return
* @return
*/
*/
public
static
String
getFormatedDateString
(
float
timeZoneOffset
)
{
public
static
String
getFormatedDateString
(
float
timeZoneOffset
)
{
if
(
timeZoneOffset
>
13
||
timeZoneOffset
<
-
12
)
{
if
(
timeZoneOffset
>
13
.0
F
||
timeZoneOffset
<
-
12.0
F
)
{
timeZoneOffset
=
0
;
timeZoneOffset
=
0
.0
F
;
}
}
int
newTime
=
(
int
)
(
timeZoneOffset
*
60
*
60
*
1000
);
int
newTime
=
(
int
)
(
timeZoneOffset
*
60.0
F
*
60.0
F
*
1000.0
F
);
TimeZone
timeZone
;
String
[]
ids
=
TimeZone
.
getAvailableIDs
(
newTime
);
String
[]
ids
=
TimeZone
.
getAvailableIDs
(
newTime
);
Object
timeZone
;
if
(
ids
.
length
==
0
)
{
if
(
ids
.
length
==
0
)
{
timeZone
=
TimeZone
.
getDefault
();
timeZone
=
TimeZone
.
getDefault
();
}
else
{
}
else
{
...
@@ -408,8 +321,7 @@ public class SeatelSentUtils {
...
@@ -408,8 +321,7 @@ public class SeatelSentUtils {
}
}
SimpleDateFormat
sdf
=
new
SimpleDateFormat
(
"yyyy-MM-dd HH:mm:ss"
);
SimpleDateFormat
sdf
=
new
SimpleDateFormat
(
"yyyy-MM-dd HH:mm:ss"
);
sdf
.
setTimeZone
(
timeZone
);
sdf
.
setTimeZone
(
(
TimeZone
)
timeZone
);
return
sdf
.
format
(
new
Date
());
return
sdf
.
format
(
new
Date
());
}
}
}
}
src/com/library/test/PaygoTest.java
View file @
346342bd
...
@@ -25,18 +25,18 @@ import java.util.UUID;
...
@@ -25,18 +25,18 @@ import java.util.UUID;
import
java.util.logging.Level
;
import
java.util.logging.Level
;
import
java.util.logging.Logger
;
import
java.util.logging.Logger
;
/**
* 测试环境
* point_id: 181775
* password: link_asia_test_pwd
* md5: nS/Ou9oiC4LcSvEEn+54Jg==
*/
public
class
PaygoTest
{
public
class
PaygoTest
{
private
static
final
String
mAddress
=
"https://api2.paygo24.com/paygoservice.asmx"
;
private
static
final
String
mUsername
=
"181775"
;
//point_id
private
static
final
String
mPassword
=
encodePass
(
"link_asia_test_pwd"
);
// test
// private static final String mAddress = "https://api2.paygo24.com/paygoservice.asmx";
// private static final String mUsername = "181775";
// private static final String mPassword ="nS/Ou9oiC4LcSvEEn+54Jg==";
// prod
private
static
final
String
mAddress
=
"https://processing2.paygo24.com/paygoservice.asmx"
;
private
static
final
String
mUsername
=
"451717"
;
private
static
final
String
mPassword
=
encodePass
(
"Ws8GsJZu"
);
public
static
void
main
(
String
[]
args
)
{
public
static
void
main
(
String
[]
args
)
{
Date
now
=
new
Date
();
Date
now
=
new
Date
();
...
@@ -47,7 +47,7 @@ public class PaygoTest {
...
@@ -47,7 +47,7 @@ public class PaygoTest {
PaygoTest
test
=
new
PaygoTest
();
PaygoTest
test
=
new
PaygoTest
();
Payment
payment
=
new
Payment
();
Payment
payment
=
new
Payment
();
payment
.
setId
(
UUID
.
randomUUID
().
toString
());
payment
.
setId
(
UUID
.
randomUUID
().
toString
());
payment
.
setAccount
(
"
969414416
"
);
payment
.
setAccount
(
"
098375667
"
);
payment
.
setServiceId
(
"2"
);
payment
.
setServiceId
(
"2"
);
payment
.
setCommission
(
"0.00"
);
payment
.
setCommission
(
"0.00"
);
payment
.
setValue
(
"1.00"
);
payment
.
setValue
(
"1.00"
);
...
@@ -57,9 +57,8 @@ public class PaygoTest {
...
@@ -57,9 +57,8 @@ public class PaygoTest {
payment
.
setEncashmentNumber
(
"0"
);
payment
.
setEncashmentNumber
(
"0"
);
payment
.
setCurrency
(
"USD"
);
payment
.
setCurrency
(
"USD"
);
payment
.
setPaymentTool
(
"1"
);
payment
.
setPaymentTool
(
"1"
);
List
<
Payment
.
PaymentParam
>
params
=
new
ArrayList
<>();
List
params
=
new
ArrayList
<>();
params
.
add
(
new
Payment
.
PaymentParam
(
"account"
,
"098375667"
));
params
.
add
(
new
Payment
.
PaymentParam
(
"account"
,
"969414416"
));
//account parameter
//account parameter
payment
.
setParams
(
params
);
payment
.
setParams
(
params
);
try
{
try
{
...
@@ -96,7 +95,6 @@ public class PaygoTest {
...
@@ -96,7 +95,6 @@ public class PaygoTest {
}
}
private
static
final
String
encodePass
(
String
pass
)
{
private
static
final
String
encodePass
(
String
pass
)
{
try
{
try
{
byte
messageDigest
[]
=
null
;
byte
messageDigest
[]
=
null
;
...
@@ -156,17 +154,26 @@ public class PaygoTest {
...
@@ -156,17 +154,26 @@ public class PaygoTest {
private
void
getCheckResultRequest
(
Payment
payment
)
throws
Exception
{
private
void
getCheckResultRequest
(
Payment
payment
)
throws
Exception
{
String
requestXML
String
requestXML
=
"\n"
=
"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
+
"\n"
+
"<SOAP-ENV:Envelope \n"
+
" \n"
+
"xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\"\n"
+
" "
+
"xmlns:paygo=\"http://paygo24.com/v3/protocol\" \n"
+
""
+
"xmlns:tem=\"http://tempuri.org/\" \n"
+
"\n"
+
""
+
"xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" \n"
+
"$POINT_ID\n"
+
"xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">\n"
+
" $PASSWORD"
+
" <SOAP-ENV:Header/>\n"
+
""
+
""
+
" <SOAP-ENV:Body>"
+
"\n"
+
"<tem:SendRequest>"
+
""
;
+
"<request\n"
+
"xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n"
+
"xmlns=\"http://paygo24.com/v3/protocol\"\n"
+
"xsi:type=\"GetCheckResultRequest\"\n"
+
"Id=\"$PAYMENT_ID\">\n"
+
"</request>"
+
"<tem:pointId>$POINT_ID</tem:pointId>\n"
+
" <tem:password>$PASSWORD</tem:password>"
+
"</tem:SendRequest>"
+
""
+
"</SOAP-ENV:Body>\n"
+
"</SOAP-ENV:Envelope>"
;
// set the payment id
// set the payment id
requestXML
=
requestXML
.
replace
(
"$PAYMENT_ID"
,
payment
.
getId
()).
replace
(
"$POINT_ID"
,
mUsername
).
replace
(
"$PASSWORD"
,
mPassword
);
requestXML
=
requestXML
.
replace
(
"$PAYMENT_ID"
,
payment
.
getId
()).
replace
(
"$POINT_ID"
,
mUsername
).
replace
(
"$PASSWORD"
,
mPassword
);
...
@@ -180,51 +187,61 @@ public class PaygoTest {
...
@@ -180,51 +187,61 @@ public class PaygoTest {
}
}
private
void
registerCheckRequest
(
Payment
payment
)
throws
Exception
{
private
void
registerCheckRequest
(
Payment
payment
)
throws
Exception
{
// String requestXML = "\n"
String
requestXML
=
"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
// + "\n"
+
"<SOAP-ENV:Envelope \n"
// + " \n"
+
"xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\"\n"
// + " "
+
"xmlns:paygo=\"http://paygo24.com/v3/protocol\" \n"
// + ""
+
"xmlns:tem=\"http://tempuri.org/\" \n"
// + "\n"
+
"xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" \n"
// + "\n" + "$PAYMENT_PARAMS"
+
"xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">\n"
// + "\n" + "" + ""
+
" <SOAP-ENV:Header/>\n"
// + "$POINT_ID\n"
+
" <SOAP-ENV:Body>"
// + " $PASSWORD"
+
"<tem:SendRequest>"
// + "" + ""
+
"<request\n"
// + "\n"
+
"xmlns=\"http://paygo24.com/v3/protocol\"\n"
// + "";
+
"xsi:type=\"RegisterCheckRequest\"\n"
+
"Id=\"$PAYMENT_ID\"\n"
+
"Service=\"$SERVICE_ID\">\n"
+
"<PaymentParameters xmlns=\"\">\n"
+
"$PAYMENT_PARAMS"
String
requestXML
=
"<?xml version='1.0' encoding='utf-8'?>\n"
+
+
"</PaymentParameters>\n"
+
"</request>"
+
""
"<soap:Envelope xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema'>\n"
+
+
"<tem:pointId>$POINT_ID</tem:pointId>\n"
" <soap:Body>\n"
+
+
" <tem:password>$PASSWORD</tem:password>"
" <SendRequest xmlns='http://tempuri.org/'>\n"
+
+
"</tem:SendRequest>"
+
""
" <request xsi:type='RegisterCheckRequest' Id='7a646d45-ee2f-4b1c-8de8-780c416fbbd0' Service='42' xmlns='http://paygo24.com/v3/protocol'>\n"
+
+
"</SOAP-ENV:Body>\n"
" <PaymentParameters xmlns=''>\n"
+
+
"</SOAP-ENV:Envelope>"
;
" <Parameter Name='account' Value='08374829' />\n"
+
" </PaymentParameters>\n"
+
" </request>\n"
+
// String requestXML = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" +
" <pointId>46</pointId>\n"
+
// "<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">\n" +
" <password>4QrcOUm6Wau+VuBX8g+IPg==</password>\n"
+
// " <soap:Body>\n" +
" </SendRequest>\n"
+
// " <SendRequest xmlns=\"http://tempuri.org/\">\n" +
" </soap:Body>\n"
+
// " <request xsi:type=\"RegisterCheckRequest\" Id=\"$PAYMENT_ID\" Service=\"2\" xmlns=\"http://paygo24.com/v3/protocol\">\n" +
"</soap:Envelope>"
;
// " <PaymentParameters xmlns=\"\">\n" +
// " <Parameter Name=\"account\" Value=\"098375667\" />\n" +
// " </PaymentParameters>\n" +
// " </request>\n" +
// " <pointId>46</pointId>\n" +
// " <password>4QrcOUm6Wau+VuBX8g+IPg==</password>\n" +
// " </SendRequest>\n" +
// " </soap:Body>\n" +
// "</soap:Envelope>";
// set the payment id
// set the payment id
requestXML
=
requestXML
.
replace
(
"$PAYMENT_ID"
,
payment
.
getId
())
requestXML
=
requestXML
.
replace
(
"$PAYMENT_ID"
,
payment
.
getId
())
.
replace
(
"$SERVICE_ID"
,
payment
.
getServiceId
())
.
replace
(
"$SERVICE_ID"
,
payment
.
getServiceId
())
.
replace
(
"$POINT_ID"
,
mUsername
)
.
replace
(
"$POINT_ID"
,
mUsername
)
.
replace
(
"$PASSWORD"
,
mPassword
);
.
replace
(
"$PASSWORD"
,
mPassword
)
.
replace
(
"$ACCOUNT"
,
payment
.
getAccount
());
// serialize the payment parameters
// serialize the payment parameters
String
paramsStr
=
""
;
String
paramsStr
=
""
;
List
params
=
payment
.
getParams
();
List
<
Payment
.
PaymentParam
>
params
=
payment
.
getParams
();
for
(
int
i
=
0
,
c
=
params
.
size
();
i
<
c
;
++
i
)
{
for
(
int
i
=
0
,
c
=
params
.
size
();
i
<
c
;
++
i
)
{
Payment
.
PaymentParam
param
=
(
Payment
.
PaymentParam
)
params
.
get
(
i
);
Payment
.
PaymentParam
param
=
params
.
get
(
i
);
paramsStr
+=
"\n"
;
paramsStr
+=
"<Parameter Name=\""
+
param
.
getName
()
+
"\" Value=\""
+
param
.
getValue
()
+
"\"/>\n"
;
}
}
requestXML
=
requestXML
.
replace
(
"$PAYMENT_PARAMS"
,
paramsStr
);
requestXML
=
requestXML
.
replace
(
"$PAYMENT_PARAMS"
,
paramsStr
);
...
@@ -239,19 +256,36 @@ public class PaygoTest {
...
@@ -239,19 +256,36 @@ public class PaygoTest {
private
void
sendPaymentRequest
(
Payment
payment
)
throws
Exception
{
private
void
sendPaymentRequest
(
Payment
payment
)
throws
Exception
{
String
requestXML
=
"\n"
String
requestXML
=
"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
+
"\n"
+
"<SOAP-ENV:Envelope \n"
+
" \n"
+
"xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\"\n"
+
" "
+
"xmlns:paygo=\"http://paygo24.com/v3/protocol\" \n"
+
""
+
"xmlns:tem=\"http://tempuri.org/\" \n"
+
"\n"
+
"xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" \n"
+
"\n"
+
"$PAYMENT_PARAMS"
+
"xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">\n"
+
"\n"
+
""
+
" <SOAP-ENV:Header/>\n"
+
"$POINT_ID\n"
+
" <SOAP-ENV:Body>"
+
" $PASSWORD"
+
"<tem:SendRequest>"
+
""
+
""
+
"<request\n"
+
"\n"
+
"xmlns=\"http://paygo24.com/v3/protocol\"\n"
+
""
;
+
"xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n"
+
"xsi:type=\"SendPaymentRequest\"\n"
+
"Id=\"$PAYMENT_ID\"\n"
+
"Service=\"$SERVICE_ID\"\n"
+
"Ticket=\"$PAYMENT_TICKET\"\n"
+
"Number=\"$PAYMENT_NUMBER\"\n"
+
"Time=\"$PAYMENT_TIME\"\n"
+
"EncashmentNumber=\"$ENCASHMENT_NUMBER\"\n"
+
"Value=\"$PAYMENT_VALUE\"\n"
+
"Commission=\"$PAYMENT_COMMISSION\"\n"
+
"Currency=\"$PAYMENT_CURRENCY\"\n"
+
"PaymentTool=\"$PAYMENT_TOOL\">\n"
+
"<PaymentParameters xmlns=\"\">\n"
+
"$PAYMENT_PARAMS"
+
"</PaymentParameters>\n"
+
"</request>"
+
"<tem:pointId>$POINT_ID</tem:pointId>\n"
+
" <tem:password>$PASSWORD</tem:password>"
+
"</tem:SendRequest>"
+
""
+
"</SOAP-ENV:Body>\n"
+
"</SOAP-ENV:Envelope>"
;
// set the payment id
// set the payment id
requestXML
=
requestXML
.
replace
(
"$PAYMENT_ID"
,
payment
.
getId
())
requestXML
=
requestXML
.
replace
(
"$PAYMENT_ID"
,
payment
.
getId
())
...
@@ -269,12 +303,13 @@ public class PaygoTest {
...
@@ -269,12 +303,13 @@ public class PaygoTest {
// serialize the payment parameters
// serialize the payment parameters
String
paramsStr
=
""
;
String
paramsStr
=
""
;
List
params
=
payment
.
getParams
();
List
<
Payment
.
PaymentParam
>
params
=
payment
.
getParams
();
for
(
int
i
=
0
,
c
=
params
.
size
();
i
<
c
;
++
i
)
{
for
(
int
i
=
0
,
c
=
params
.
size
();
i
<
c
;
++
i
)
{
Payment
.
PaymentParam
param
=
(
Payment
.
PaymentParam
)
params
.
get
(
i
);
Payment
.
PaymentParam
param
=
params
.
get
(
i
);
paramsStr
+=
"\n"
;
paramsStr
+=
"<Parameter Name=\""
+
param
.
getName
()
+
"\" Value=\""
+
param
.
getValue
()
+
"\"/>\n"
;
}
}
requestXML
=
requestXML
.
replace
(
"$PAYMENT_PARAMS"
,
paramsStr
);
requestXML
=
requestXML
.
replace
(
"$PAYMENT_PARAMS"
,
paramsStr
);
...
@@ -308,18 +343,26 @@ public class PaygoTest {
...
@@ -308,18 +343,26 @@ public class PaygoTest {
private
void
checkStatusRequest
(
Payment
payment
)
throws
Exception
{
private
void
checkStatusRequest
(
Payment
payment
)
throws
Exception
{
String
requestXML
String
requestXML
=
"\n"
=
"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
+
"\n"
+
"<SOAP-ENV:Envelope \n"
+
" \n"
+
"xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\"\n"
+
" "
+
"xmlns:paygo=\"http://paygo24.com/v3/protocol\" \n"
+
""
+
"xmlns:tem=\"http://tempuri.org/\" \n"
+
"\n"
+
"xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" \n"
+
""
+
"xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">\n"
+
"$POINT_ID\n"
+
" <SOAP-ENV:Header/>\n"
+
"$PASSWORD"
+
" <SOAP-ENV:Body>"
+
""
+
""
+
"<tem:SendRequest>"
+
"\n"
+
"<request\n"
+
""
;
+
"xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n"
+
"xmlns=\"http://paygo24.com/v3/protocol\"\n"
+
"xsi:type=\"CheckStatusRequest\"\n"
+
"Id=\"$PAYMENT_ID\">\n"
+
"</request>"
+
"<tem:pointId>$POINT_ID</tem:pointId>\n"
+
"<tem:password>$PASSWORD</tem:password>"
+
"</tem:SendRequest>"
+
""
+
"</SOAP-ENV:Body>\n"
+
"</SOAP-ENV:Envelope>"
;
// set the payment id
// set the payment id
requestXML
=
requestXML
.
replace
(
"$PAYMENT_ID"
,
payment
.
getId
())
requestXML
=
requestXML
.
replace
(
"$PAYMENT_ID"
,
payment
.
getId
())
...
@@ -370,7 +413,7 @@ public class PaygoTest {
...
@@ -370,7 +413,7 @@ public class PaygoTest {
return
sb
.
toString
();
return
sb
.
toString
();
}
}
public
static
final
class
Payment
implements
Comparable
{
public
static
final
class
Payment
implements
Comparable
<
Payment
>
{
private
String
mId
;
private
String
mId
;
private
String
mServiceId
;
private
String
mServiceId
;
...
@@ -398,7 +441,7 @@ public class PaygoTest {
...
@@ -398,7 +441,7 @@ public class PaygoTest {
private
String
mServiceName
;
private
String
mServiceName
;
public
Payment
()
{
public
Payment
()
{
mParams
=
new
ArrayList
();
mParams
=
new
ArrayList
<
PaymentParam
>
();
}
}
...
@@ -422,11 +465,11 @@ public class PaygoTest {
...
@@ -422,11 +465,11 @@ public class PaygoTest {
mServiceId
=
serviceId
;
mServiceId
=
serviceId
;
}
}
public
List
getParams
()
{
public
List
<
PaymentParam
>
getParams
()
{
return
mParams
;
return
mParams
;
}
}
public
void
setParams
(
List
params
)
{
public
void
setParams
(
List
<
PaymentParam
>
params
)
{
mParams
=
params
;
mParams
=
params
;
}
}
...
@@ -558,21 +601,11 @@ public class PaygoTest {
...
@@ -558,21 +601,11 @@ public class PaygoTest {
return
this
.
mAccount
;
return
this
.
mAccount
;
}
}
// @Override
// public int compareTo(Payment another) {
// return Long.compare(another.getTimeLong(), mTimeLong);
// }
@Override
@Override
public
int
compareTo
(
Object
o
)
{
public
int
compareTo
(
Payment
another
)
{
Payment
payment
=
(
Payment
)
o
;
return
Long
.
compare
(
another
.
getTimeLong
(),
mTimeLong
);
return
Long
.
compare
(
payment
.
getTimeLong
(),
mTimeLong
);
// return 0;
}
}
public
String
getServiceName
()
{
public
String
getServiceName
()
{
return
mServiceName
;
return
mServiceName
;
}
}
...
@@ -648,7 +681,6 @@ public class PaygoTest {
...
@@ -648,7 +681,6 @@ public class PaygoTest {
}
}
}
}
}
}
public
static
class
PaypointException
extends
Exception
{
public
static
class
PaypointException
extends
Exception
{
private
String
mErrorCode
;
private
String
mErrorCode
;
...
...
src/com/library/test/PaygoTest2.java
0 → 100644
View file @
346342bd
package
com
.
library
.
test
;
import
java.io.BufferedInputStream
;
import
java.io.BufferedOutputStream
;
import
java.io.BufferedReader
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.io.InputStreamReader
;
import
java.net.HttpURLConnection
;
import
java.net.URL
;
import
java.security.MessageDigest
;
import
java.text.SimpleDateFormat
;
import
java.util.ArrayList
;
import
java.util.Base64
;
import
java.util.Date
;
import
java.util.List
;
import
java.util.UUID
;
import
java.util.logging.Level
;
import
java.util.logging.Logger
;
import
javax.net.ssl.HttpsURLConnection
;
import
org.w3c.dom.Document
;
import
org.w3c.dom.Element
;
import
org.w3c.dom.NamedNodeMap
;
import
org.w3c.dom.Node
;
import
org.w3c.dom.NodeList
;
public
class
PaygoTest2
{
public
static
void
main
(
String
[]
args
)
{
Date
now
=
new
Date
();
SimpleDateFormat
formatter
=
new
SimpleDateFormat
(
"yyyyMMddHHmmss"
);
SimpleDateFormat
ticket_format
=
new
SimpleDateFormat
(
"HHmmss"
);
SimpleDateFormat
format3339
=
new
SimpleDateFormat
(
"yyyy-MM-dd'T'HH:mm:ss.SSSXXX"
);
PaygoTest2
test
=
new
PaygoTest2
();
Payment
payment
=
new
Payment
();
payment
.
setId
(
UUID
.
randomUUID
().
toString
());
payment
.
setAccount
(
"017910301"
);
payment
.
setServiceId
(
"3"
);
//Cellcard
payment
.
setCommission
(
"0.00"
);
payment
.
setValue
(
"1.00"
);
payment
.
setTicket
(
ticket_format
.
format
(
now
));
payment
.
setNumber
(
formatter
.
format
(
now
));
payment
.
setTime
(
format3339
.
format
(
now
));
payment
.
setEncashmentNumber
(
"0"
);
payment
.
setCurrency
(
"USD"
);
payment
.
setPaymentTool
(
"1"
);
List
params
=
new
ArrayList
<>();
params
.
add
(
new
Payment
.
PaymentParam
(
"account"
,
"017910301"
));
//account parameter
payment
.
setParams
(
params
);
try
{
//Checking payment parameters
test
.
registerCheckRequest
(
payment
);
//2 sec delay before getting result
Thread
.
sleep
(
2000
);
//Getting check result
test
.
getCheckResultRequest
(
payment
);
//In your system you have to repeat request results while
//State is not 0, 1 or 2
//If State==1 reject payment proceeding
//Sending payment
test
.
sendPaymentRequest
(
payment
);
//In this method if you get ErrorResponse check Error Code
//if Code==7 (Payment is already exists) call checkStatusRequest()
//5 sec delay before checking payment status
Thread
.
sleep
(
5000
);
//Checking payment status
test
.
checkStatusRequest
(
payment
);
//In your system you have to repeat request check status while
//State is not final - 1, 2 (rejected) or 5 (completed)
//If you got status 3 or 4 and do not receive final state for 40 seconds complete the payment on your side
}
catch
(
Exception
ex
)
{
Logger
.
getLogger
(
PaygoTest2
.
class
.
getName
()).
log
(
Level
.
SEVERE
,
null
,
ex
);
}
}
private
static
final
String
mAddress
=
"https://api2.paygo24.com/paygoservice.asmx"
;
private
static
final
String
mUsername
=
"46"
;
private
static
final
String
mPassword
=
encodePass
(
"123456"
);
private
static
final
String
encodePass
(
String
pass
)
{
try
{
byte
messageDigest
[]
=
null
;
MessageDigest
digest
=
java
.
security
.
MessageDigest
.
getInstance
(
"MD5"
);
digest
.
update
(
pass
.
getBytes
());
messageDigest
=
digest
.
digest
();
pass
=
Base64
.
getEncoder
().
encodeToString
(
messageDigest
);
return
pass
;
}
catch
(
Exception
ex
)
{
return
""
;
}
}
public
InputStream
sendRequest
(
String
requestXML
)
throws
Exception
{
try
{
System
.
out
.
println
(
requestXML
);
URL
urll
=
new
URL
(
mAddress
);
HttpsURLConnection
conn
=
(
HttpsURLConnection
)
urll
.
openConnection
();
// set required headers
conn
.
setRequestProperty
(
"Content-Type"
,
"text/xml;charset=UTF-8"
);
conn
.
setRequestMethod
(
"POST"
);
conn
.
setDoOutput
(
true
);
byte
[]
body
=
requestXML
.
getBytes
(
"UTF-8"
);
conn
.
setFixedLengthStreamingMode
(
body
.
length
);
BufferedOutputStream
out
=
new
BufferedOutputStream
(
conn
.
getOutputStream
());
out
.
write
(
body
);
out
.
close
();
conn
.
connect
();
int
statusCode
=
conn
.
getResponseCode
();
if
(
statusCode
==
HttpURLConnection
.
HTTP_OK
)
{
InputStream
content
=
new
BufferedInputStream
(
conn
.
getInputStream
());
return
content
;
}
else
{
throw
new
Exception
(
"HTTP Status: "
+
statusCode
);
}
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
throw
e
;
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
throw
e
;
}
}
private
void
getCheckResultRequest
(
Payment
payment
)
throws
Exception
{
String
requestXML
=
"\n"
+
"\n"
+
" \n"
+
" "
+
""
+
"\n"
+
""
+
"$POINT_ID\n"
+
" $PASSWORD"
+
""
+
""
+
"\n"
+
""
;
// set the payment id
requestXML
=
requestXML
.
replace
(
"$PAYMENT_ID"
,
payment
.
getId
()).
replace
(
"$POINT_ID"
,
mUsername
).
replace
(
"$PASSWORD"
,
mPassword
);
// send the request to the server
InputStream
responseXML
=
sendRequest
(
requestXML
);
String
responseStr
=
convertStreamToString
(
responseXML
);
System
.
out
.
println
(
responseStr
);
}
private
void
registerCheckRequest
(
Payment
payment
)
throws
Exception
{
String
requestXML
=
"\n"
+
"\n"
+
" \n"
+
" "
+
""
+
"\n"
+
"\n"
+
"$PAYMENT_PARAMS"
+
"\n"
+
""
+
""
+
"$POINT_ID\n"
+
" $PASSWORD"
+
""
+
""
+
"\n"
+
""
;
// set the payment id
requestXML
=
requestXML
.
replace
(
"$PAYMENT_ID"
,
payment
.
getId
())
.
replace
(
"$SERVICE_ID"
,
payment
.
getServiceId
())
.
replace
(
"$POINT_ID"
,
mUsername
)
.
replace
(
"$PASSWORD"
,
mPassword
);
// serialize the payment parameters
String
paramsStr
=
""
;
List
params
=
payment
.
getParams
();
for
(
int
i
=
0
,
c
=
params
.
size
();
i
<
c
;
++
i
)
{
Object
param
=
params
.
get
(
i
);
paramsStr
+=
"\n"
;
}
requestXML
=
requestXML
.
replace
(
"$PAYMENT_PARAMS"
,
paramsStr
);
// send the request to the server
InputStream
responseXML
=
sendRequest
(
requestXML
);
String
responseStr
=
convertStreamToString
(
responseXML
);
System
.
out
.
println
(
responseStr
);
}
private
void
sendPaymentRequest
(
Payment
payment
)
throws
Exception
{
String
requestXML
=
"\n"
+
"\n"
+
" \n"
+
" "
+
""
+
"\n"
+
"\n"
+
"$PAYMENT_PARAMS"
+
"\n"
+
""
+
"$POINT_ID\n"
+
" $PASSWORD"
+
""
+
""
+
"\n"
+
""
;
// set the payment id
requestXML
=
requestXML
.
replace
(
"$PAYMENT_ID"
,
payment
.
getId
())
.
replace
(
"$SERVICE_ID"
,
payment
.
getServiceId
())
.
replace
(
"$PAYMENT_TICKET"
,
payment
.
getTicket
())
.
replace
(
"$PAYMENT_NUMBER"
,
payment
.
getNumber
())
.
replace
(
"$PAYMENT_TIME"
,
payment
.
getTime
())
.
replace
(
"$ENCASHMENT_NUMBER"
,
payment
.
getEncashmentNumber
())
.
replace
(
"$PAYMENT_VALUE"
,
payment
.
getValue
())
.
replace
(
"$PAYMENT_COMMISSION"
,
payment
.
getCommission
())
.
replace
(
"$PAYMENT_CURRENCY"
,
payment
.
getCurrency
())
.
replace
(
"$PAYMENT_TOOL"
,
payment
.
getPaymentTool
())
.
replace
(
"$POINT_ID"
,
mUsername
)
.
replace
(
"$PASSWORD"
,
mPassword
);
// serialize the payment parameters
String
paramsStr
=
""
;
List
params
=
payment
.
getParams
();
for
(
int
i
=
0
,
c
=
params
.
size
();
i
<
c
;
++
i
)
{
Object
param
=
params
.
get
(
i
);
paramsStr
+=
"\n"
;
}
requestXML
=
requestXML
.
replace
(
"$PAYMENT_PARAMS"
,
paramsStr
);
// send the request to the server
InputStream
responseXML
=
sendRequest
(
requestXML
);
String
responseStr
=
convertStreamToString
(
responseXML
);
System
.
out
.
println
(
responseStr
);
}
/*
* Checks the server response for errors and throws an exception
*/
private
void
checkError
(
Document
dom
)
throws
PaypointException
{
Element
root
=
dom
.
getDocumentElement
();
NodeList
errorItems
=
root
.
getElementsByTagName
(
"Error"
);
if
(
errorItems
.
getLength
()
!=
0
)
{
Node
item
=
errorItems
.
item
(
0
);
NamedNodeMap
attrs
=
item
.
getAttributes
();
String
errorText
=
attrs
.
getNamedItem
(
"Description"
)
.
getTextContent
();
throw
new
PaypointException
(
errorText
,
attrs
.
getNamedItem
(
"Number"
)
.
getTextContent
());
}
}
private
void
checkStatusRequest
(
Payment
payment
)
throws
Exception
{
String
requestXML
=
"\n"
+
"\n"
+
" \n"
+
" "
+
""
+
"\n"
+
""
+
"$POINT_ID\n"
+
"$PASSWORD"
+
""
+
""
+
"\n"
+
""
;
// set the payment id
requestXML
=
requestXML
.
replace
(
"$PAYMENT_ID"
,
payment
.
getId
())
.
replace
(
"$POINT_ID"
,
mUsername
)
.
replace
(
"$PASSWORD"
,
mPassword
);
// send the request to the server
InputStream
responseXML
=
sendRequest
(
requestXML
);
String
responseStr
=
convertStreamToString
(
responseXML
);
System
.
out
.
println
(
responseStr
);
}
private
String
getAttrValue
(
NamedNodeMap
attrs
,
String
name
)
{
Node
value
=
attrs
.
getNamedItem
(
name
);
if
(
value
!=
null
)
{
return
value
.
getTextContent
();
}
else
{
return
""
;
}
}
private
static
String
convertStreamToString
(
InputStream
is
)
{
/*
* To convert the InputStream to String we use the
* BufferedReader.readLine() method. We iterate until the BufferedReader
* return null which means there's no more data to read. Each line will
* appended to a StringBuilder and returned as String.
*/
BufferedReader
reader
=
new
BufferedReader
(
new
InputStreamReader
(
is
));
StringBuilder
sb
=
new
StringBuilder
();
String
line
=
null
;
try
{
while
((
line
=
reader
.
readLine
())
!=
null
)
{
sb
.
append
(
line
+
"\n"
);
}
}
catch
(
IOException
e
)
{
}
finally
{
try
{
is
.
close
();
}
catch
(
IOException
e
)
{
}
}
return
sb
.
toString
();
}
public
static
final
class
Payment
implements
Comparable
{
private
String
mId
;
private
String
mServiceId
;
private
String
mTicket
;
private
String
mNumber
;
private
String
mTime
;
private
String
mEncashmentNumber
;
private
String
mValue
;
private
String
mCommission
;
private
String
mBalance
;
private
String
mCurrency
;
private
String
mPaymentTool
;
private
String
mRejectPayment
;
private
String
mState
;
private
String
mStateComment
;
private
String
mStateTime
;
private
String
mServerPaymentId
;
private
List
mParams
;
// cached parameters
private
String
mAccount
;
private
int
mStateAsInt
;
private
long
mTimeLong
;
private
String
mServiceName
;
public
Payment
()
{
mParams
=
new
ArrayList
();
}
public
long
getTimeLong
()
{
return
mTimeLong
;
}
public
String
getId
()
{
return
mId
;
}
public
void
setId
(
String
id
)
{
mId
=
id
;
}
public
String
getServiceId
()
{
return
mServiceId
;
}
public
void
setServiceId
(
String
serviceId
)
{
mServiceId
=
serviceId
;
}
public
List
getParams
()
{
return
mParams
;
}
public
void
setParams
(
List
params
)
{
mParams
=
params
;
}
public
String
getTicket
()
{
return
mTicket
;
}
public
void
setTicket
(
String
ticket
)
{
mTicket
=
ticket
;
}
public
String
getNumber
()
{
return
mNumber
;
}
public
void
setNumber
(
String
number
)
{
mNumber
=
number
;
}
public
String
getTime
()
{
return
mTime
;
}
public
void
setTime
(
String
time
)
{
mTime
=
time
;
}
public
String
getEncashmentNumber
()
{
return
mEncashmentNumber
;
}
public
void
setEncashmentNumber
(
String
encashmentNumber
)
{
mEncashmentNumber
=
encashmentNumber
;
}
public
String
getValue
()
{
return
mValue
;
}
public
void
setValue
(
String
value
)
{
mValue
=
value
;
}
public
String
getCommission
()
{
return
mCommission
;
}
public
void
setCommission
(
String
commission
)
{
mCommission
=
commission
;
}
public
String
getBalance
()
{
return
mBalance
;
}
public
void
setBalance
(
String
balance
)
{
mBalance
=
balance
;
}
public
String
getCurrency
()
{
return
mCurrency
;
}
public
void
setCurrency
(
String
currency
)
{
mCurrency
=
currency
;
}
public
String
getPaymentTool
()
{
return
mPaymentTool
;
}
public
void
setPaymentTool
(
String
paymentTool
)
{
mPaymentTool
=
paymentTool
;
}
public
String
getRejectPayment
()
{
return
mRejectPayment
;
}
public
void
setRejectPayment
(
String
rejectPayment
)
{
mRejectPayment
=
rejectPayment
;
}
public
String
getState
()
{
return
mState
;
}
public
void
setState
(
String
state
)
{
mState
=
state
;
try
{
mStateAsInt
=
Integer
.
parseInt
(
state
);
}
catch
(
NumberFormatException
e
)
{
mStateAsInt
=
-
1
;
}
}
public
String
getStateComment
()
{
return
mStateComment
;
}
public
void
setStateComment
(
String
stateComment
)
{
mStateComment
=
stateComment
;
}
public
String
getStateTime
()
{
return
mStateTime
;
}
public
void
setStateTime
(
String
stateTime
)
{
mStateTime
=
stateTime
;
}
public
String
getAccount
()
{
return
mAccount
;
}
public
void
setAccount
(
String
account
)
{
mAccount
=
account
;
}
public
int
getStateAsInt
()
{
return
this
.
mStateAsInt
;
}
@Override
public
String
toString
()
{
return
this
.
mAccount
;
}
public
String
getServiceName
()
{
return
mServiceName
;
}
public
void
setServiceName
(
String
serviceName
)
{
mServiceName
=
serviceName
;
}
public
String
getServerPaymentId
()
{
return
mServerPaymentId
;
}
public
void
setServerPaymentId
(
String
serverPaymentId
)
{
mServerPaymentId
=
serverPaymentId
;
}
@Override
public
int
compareTo
(
Object
o
)
{
return
0
;
}
public
static
class
PaymentParam
{
public
static
final
int
TYPE_INPUT
=
1
;
public
static
final
int
TYPE_OUTPUT
=
2
;
public
static
final
int
TYPE_INPUT_OUTPUT
=
3
;
public
static
final
int
TYPE_INTERNAL_DEVICE
=
4
;
private
String
mName
;
private
String
mValue
;
private
int
mType
=
TYPE_INPUT
;
public
PaymentParam
(
String
name
,
String
value
)
{
mName
=
name
;
mValue
=
value
;
}
public
PaymentParam
(
String
name
,
String
value
,
int
type
)
{
this
(
name
,
value
);
mType
=
type
;
}
public
int
getType
()
{
return
mType
;
}
public
void
setType
(
int
type
)
{
mType
=
type
;
}
public
String
getName
()
{
return
mName
;
}
public
void
setName
(
String
name
)
{
mName
=
name
;
}
public
String
getValue
()
{
return
mValue
;
}
public
void
setValue
(
String
value
)
{
mValue
=
value
;
}
}
}
public
static
class
PaypointException
extends
Exception
{
private
String
mErrorCode
;
public
String
getErrorCode
()
{
return
mErrorCode
;
}
PaypointException
(
String
message
,
String
errorCode
)
{
super
(
message
);
mErrorCode
=
errorCode
;
}
}
}
src/com/library/test/PaygoTest3.java
0 → 100644
View file @
346342bd
//package com.library.test;
//
//import org.w3c.dom.Document;
//import org.w3c.dom.Element;
//import org.w3c.dom.NamedNodeMap;
//import org.w3c.dom.Node;
//import org.w3c.dom.NodeList;
//
//import javax.net.ssl.HttpsURLConnection;
//import java.io.BufferedInputStream;
//import java.io.BufferedOutputStream;
//import java.io.BufferedReader;
//import java.io.IOException;
//import java.io.InputStream;
//import java.io.InputStreamReader;
//import java.net.HttpURLConnection;
//import java.net.URL;
//import java.security.MessageDigest;
//import java.text.SimpleDateFormat;
//import java.util.ArrayList;
//import java.util.Base64;
//import java.util.Date;
//import java.util.List;
//import java.util.UUID;
//import java.util.logging.Level;
//import java.util.logging.Logger;
//
///**
// * 测试环境
// * point_id: 181775
// * password: link_asia_test_pwd
// * md5: nS/Ou9oiC4LcSvEEn+54Jg==
// */
//public class PaygoTest {
//
// private static final String mAddress = "https://api2.paygo24.com/paygoservice.asmx";
// private static final String mUsername = "451717"; //point_id
// // iWoQosQ+z9YFXqKuyPyRNg==
// private static final String mPassword = encodePass("Ws8GsJZu");
//
//// private static final String mUsername = "46"; //point_id
//// private static final String mPassword = "4QrcOUm6Wau+VuBX8g+IPg==";
//
//
// public static void main(String[] args) {
// Date now = new Date();
//
// SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMddHHmmss");
// SimpleDateFormat ticket_format = new SimpleDateFormat("HHmmss");
// SimpleDateFormat format3339 = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSXXX");
// PaygoTest test = new PaygoTest();
// Payment payment = new Payment();
// payment.setId(UUID.randomUUID().toString());
// payment.setAccount("969414416");
// payment.setServiceId("2");
// payment.setCommission("0.00");
// payment.setValue("1.00");
// payment.setTicket(ticket_format.format(now));
// payment.setNumber(formatter.format(now));
// payment.setTime(format3339.format(now));
// payment.setEncashmentNumber("0");
// payment.setCurrency("USD");
// payment.setPaymentTool("1");
//
// List params = new ArrayList<>();
// params.add(new Payment.PaymentParam("account", "969414416"));
// //account parameter
// payment.setParams(params);
// try {
// //Checking payment parameters
// test.registerCheckRequest(payment);
//
// //2 sec delay before getting result
// Thread.sleep(2000);
//
// //Getting check result
// test.getCheckResultRequest(payment);
// //In your system you have to repeat request results while
// //State is not 0, 1 or 2
// //If State==1 reject payment proceeding
//
// //Sending payment
// test.sendPaymentRequest(payment);
// //In this method if you get ErrorResponse check Error Code
// //if Code==7 (Payment is already exists) call checkStatusRequest()
//
// //5 sec delay before checking payment status
// Thread.sleep(5000);
//
// //Checking payment status
// test.checkStatusRequest(payment);
// //In your system you have to repeat request check status while
// //State is not final - 1, 2 (rejected) or 5 (completed)
// //If you got status 3 or 4 and do not receive final state for 40 seconds complete the payment on your side
//
//
// } catch (Exception ex) {
// Logger.getLogger(PaygoTest.class.getName()).log(Level.SEVERE, null, ex);
// }
//
// }
//
//
// private static final String encodePass(String pass) {
// try {
// byte messageDigest[] = null;
// MessageDigest digest = java.security.MessageDigest
// .getInstance("MD5");
// digest.update(pass.getBytes());
// messageDigest = digest.digest();
// pass = Base64.getEncoder().encodeToString(messageDigest);
// return pass;
// } catch (Exception ex) {
// return "";
// }
// }
//
// public InputStream sendRequest(String requestXML) throws Exception {
// try {
//
// System.out.println(requestXML);
//
// URL urll = new URL(mAddress);
// HttpsURLConnection conn = (HttpsURLConnection) urll.openConnection();
//
// // set required headers
// conn.setRequestProperty("Content-Type",
// "text/xml;charset=UTF-8");
// conn.setRequestMethod("POST");
//
// conn.setDoOutput(true);
//
// byte[] body = requestXML.getBytes("UTF-8");
// conn.setFixedLengthStreamingMode(body.length);
//
// BufferedOutputStream out = new BufferedOutputStream(conn.getOutputStream());
// out.write(body);
// out.close();
// conn.connect();
// int statusCode = conn.getResponseCode();
//
// if (statusCode == HttpURLConnection.HTTP_OK) {
// InputStream content = new BufferedInputStream(conn.getInputStream());
// return content;
// } else {
// throw new Exception("HTTP Status: " + statusCode);
// }
//
// } catch (IOException e) {
// e.printStackTrace();
// throw e;
//
// } catch (Exception e) {
// e.printStackTrace();
// throw e;
// }
//
// }
//
// private void getCheckResultRequest(Payment payment) throws Exception {
//
// String requestXML
// = "\n"
// + "\n"
// + " \n"
// + " "
// + ""
// + "\n" + ""
// + "$POINT_ID\n"
// + " $PASSWORD"
// + "" + ""
// + "\n"
// + "";
//
// // set the payment id
// requestXML = requestXML.replace("$PAYMENT_ID", payment.getId()).replace("$POINT_ID", mUsername).replace("$PASSWORD", mPassword);
//
// // send the request to the server
// InputStream responseXML = sendRequest(requestXML);
//
// String responseStr = convertStreamToString(responseXML);
// System.out.println(responseStr);
//
// }
//
// private void registerCheckRequest(Payment payment) throws Exception {
//
//
// String requestXML = "<?xml version='1.0' encoding='utf-8'?>\n" +
// "<soap:Envelope xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema'>\n" +
// " <soap:Body>\n" +
// " <SendRequest xmlns='http://tempuri.org/'>\n" +
// " <request xsi:type='RegisterCheckRequest' Id='" + payment.getId() + "' Service='" + payment.getServiceId() + "' xmlns='http://paygo24.com/v3/protocol'>\n" +
// " <PaymentParameters xmlns=''>\n" +
// " <Parameter Name='account' Value='" + payment.getAccount() + "' />\n" +
// " </PaymentParameters>\n" +
// " </request>\n" +
// " <pointId>" + mUsername + "</pointId>\n" +
// " <password>" + mPassword + "</password>\n" +
// " </SendRequest>\n" +
// " </soap:Body>\n" +
// "</soap:Envelope>";
//
//
// // set the payment id
// requestXML = requestXML.replace("$PAYMENT_ID", payment.getId())
// .replace("$SERVICE_ID", payment.getServiceId())
// .replace("$POINT_ID", mUsername)
// .replace("$PASSWORD", mPassword);
//
// // serialize the payment parameters
// String paramsStr = "";
// List params = payment.getParams();
//
// for (int i = 0, c = params.size(); i < c; ++i) {
// Payment.PaymentParam param = (Payment.PaymentParam) params.get(i);
//
// paramsStr += "\n";
// }
//
// requestXML = requestXML.replace("$PAYMENT_PARAMS", paramsStr);
//
// // send the request to the server
// InputStream responseXML = sendRequest(requestXML);
//
// String responseStr = convertStreamToString(responseXML);
// System.out.println(responseStr);
//
// }
//
// private void sendPaymentRequest(Payment payment) throws Exception {
//
// String requestXML = "\n"
// + "\n"
// + " \n"
// + " "
// + ""
// + "\n"
// + "\n" + "$PAYMENT_PARAMS"
// + "\n" + ""
// + "$POINT_ID\n"
// + " $PASSWORD"
// + "" + ""
// + "\n"
// + "";
//
// // set the payment id
// requestXML = requestXML.replace("$PAYMENT_ID", payment.getId())
// .replace("$SERVICE_ID", payment.getServiceId())
// .replace("$PAYMENT_TICKET", payment.getTicket())
// .replace("$PAYMENT_NUMBER", payment.getNumber())
// .replace("$PAYMENT_TIME", payment.getTime())
// .replace("$ENCASHMENT_NUMBER", payment.getEncashmentNumber())
// .replace("$PAYMENT_VALUE", payment.getValue())
// .replace("$PAYMENT_COMMISSION", payment.getCommission())
// .replace("$PAYMENT_CURRENCY", payment.getCurrency())
// .replace("$PAYMENT_TOOL", payment.getPaymentTool())
// .replace("$POINT_ID", mUsername)
// .replace("$PASSWORD", mPassword);
//
// // serialize the payment parameters
// String paramsStr = "";
// List params = payment.getParams();
//
// for (int i = 0, c = params.size(); i < c; ++i) {
// Payment.PaymentParam param = (Payment.PaymentParam) params.get(i);
//
// paramsStr += "\n";
// }
//
// requestXML = requestXML.replace("$PAYMENT_PARAMS", paramsStr);
//
// // send the request to the server
// InputStream responseXML = sendRequest(requestXML);
//
// String responseStr = convertStreamToString(responseXML);
//
// System.out.println(responseStr);
//
// }
//
// /*
// * Checks the server response for errors and throws an exception
// */
// private void checkError(Document dom) throws PaypointException {
// Element root = dom.getDocumentElement();
// NodeList errorItems = root.getElementsByTagName("Error");
//
// if (errorItems.getLength() != 0) {
// Node item = errorItems.item(0);
// NamedNodeMap attrs = item.getAttributes();
// String errorText = attrs.getNamedItem("Description")
// .getTextContent();
//
// throw new PaypointException(errorText, attrs.getNamedItem("Number")
// .getTextContent());
// }
// }
//
// private void checkStatusRequest(Payment payment) throws Exception {
// String requestXML
// = "\n"
// + "\n"
// + " \n"
// + " "
// + ""
// + "\n"
// + ""
// + "$POINT_ID\n"
// + "$PASSWORD"
// + "" + ""
// + "\n"
// + "";
//
// // set the payment id
// requestXML = requestXML.replace("$PAYMENT_ID", payment.getId())
// .replace("$POINT_ID", mUsername)
// .replace("$PASSWORD", mPassword);
//
// // send the request to the server
// InputStream responseXML = sendRequest(requestXML);
//
// String responseStr = convertStreamToString(responseXML);
// System.out.println(responseStr);
//
// }
//
// private String getAttrValue(NamedNodeMap attrs, String name) {
// Node value = attrs.getNamedItem(name);
// if (value != null) {
// return value.getTextContent();
// } else {
// return "";
// }
// }
//
// private static String convertStreamToString(InputStream is) {
// /*
// * To convert the InputStream to String we use the
// * BufferedReader.readLine() method. We iterate until the BufferedReader
// * return null which means there's no more data to read. Each line will
// * appended to a StringBuilder and returned as String.
// */
// BufferedReader reader = new BufferedReader(new InputStreamReader(is));
// StringBuilder sb = new StringBuilder();
//
// String line = null;
// try {
// while ((line = reader.readLine()) != null) {
// sb.append(line + "\n");
// }
// } catch (IOException e) {
//
// } finally {
// try {
// is.close();
// } catch (IOException e) {
//
// }
// }
// return sb.toString();
// }
//
// public static final class Payment implements Comparable {
//
// private String mId;
// private String mServiceId;
// private String mTicket;
// private String mNumber;
// private String mTime;
// private String mEncashmentNumber;
// private String mValue;
// private String mCommission;
// private String mBalance;
// private String mCurrency;
// private String mPaymentTool;
// private String mRejectPayment;
// private String mState;
// private String mStateComment;
// private String mStateTime;
// private String mServerPaymentId;
//
// private List<PaymentParam> mParams;
//
// // cached parameters
// private String mAccount;
// private int mStateAsInt;
// private long mTimeLong;
// private String mServiceName;
//
// public Payment() {
// mParams = new ArrayList();
//
// }
//
// public long getTimeLong() {
// return mTimeLong;
// }
//
// public String getId() {
// return mId;
// }
//
// public void setId(String id) {
// mId = id;
// }
//
// public String getServiceId() {
// return mServiceId;
// }
//
// public void setServiceId(String serviceId) {
// mServiceId = serviceId;
// }
//
// public List getParams() {
// return mParams;
// }
//
// public void setParams(List params) {
// mParams = params;
// }
//
// public String getTicket() {
// return mTicket;
// }
//
// public void setTicket(String ticket) {
// mTicket = ticket;
// }
//
// public String getNumber() {
// return mNumber;
// }
//
// public void setNumber(String number) {
// mNumber = number;
// }
//
// public String getTime() {
// return mTime;
// }
//
// public void setTime(String time) {
// mTime = time;
//
// }
//
// public String getEncashmentNumber() {
// return mEncashmentNumber;
// }
//
// public void setEncashmentNumber(String encashmentNumber) {
// mEncashmentNumber = encashmentNumber;
// }
//
// public String getValue() {
// return mValue;
// }
//
// public void setValue(String value) {
// mValue = value;
// }
//
// public String getCommission() {
// return mCommission;
// }
//
// public void setCommission(String commission) {
// mCommission = commission;
// }
//
// public String getBalance() {
// return mBalance;
// }
//
// public void setBalance(String balance) {
// mBalance = balance;
// }
//
// public String getCurrency() {
// return mCurrency;
// }
//
// public void setCurrency(String currency) {
// mCurrency = currency;
// }
//
// public String getPaymentTool() {
// return mPaymentTool;
// }
//
// public void setPaymentTool(String paymentTool) {
// mPaymentTool = paymentTool;
// }
//
// public String getRejectPayment() {
// return mRejectPayment;
// }
//
// public void setRejectPayment(String rejectPayment) {
// mRejectPayment = rejectPayment;
// }
//
// public String getState() {
// return mState;
// }
//
// public void setState(String state) {
// mState = state;
//
// try {
// mStateAsInt = Integer.parseInt(state);
// } catch (NumberFormatException e) {
// mStateAsInt = -1;
// }
// }
//
// public String getStateComment() {
// return mStateComment;
// }
//
// public void setStateComment(String stateComment) {
// mStateComment = stateComment;
// }
//
// public String getStateTime() {
// return mStateTime;
// }
//
// public void setStateTime(String stateTime) {
// mStateTime = stateTime;
// }
//
// public String getAccount() {
// return mAccount;
// }
//
// public void setAccount(String account) {
// mAccount = account;
// }
//
// public int getStateAsInt() {
// return this.mStateAsInt;
// }
//
// @Override
// public String toString() {
// return this.mAccount;
// }
//
//// @Override
//// public int compareTo(Payment another) {
// // return Long.compare(another.getTimeLong(), mTimeLong);
//
//// }
//
// @Override
// public int compareTo(Object o) {
// Payment payment = (Payment) o;
// return Long.compare(payment.getTimeLong(), mTimeLong);
//
//// return 0;
// }
//
//
// public String getServiceName() {
// return mServiceName;
// }
//
// public void setServiceName(String serviceName) {
// mServiceName = serviceName;
// }
//
// public String getServerPaymentId() {
// return mServerPaymentId;
// }
//
// public void setServerPaymentId(String serverPaymentId) {
// mServerPaymentId = serverPaymentId;
// }
//
// public String getParamValue(String paramName) {
// try {
// for (PaymentParam param : mParams) {
// if (param.getName().equalsIgnoreCase(paramName)) {
// return param.getValue();
// }
// }
// } catch (Exception e) {
// // TODO: handle exception
// }
// return null;
// }
//
// public static class PaymentParam {
//
// public static final int TYPE_INPUT = 1;
// public static final int TYPE_OUTPUT = 2;
// public static final int TYPE_INPUT_OUTPUT = 3;
// public static final int TYPE_INTERNAL_DEVICE = 4;
// private String mName;
// private String mValue;
// private int mType = TYPE_INPUT;
//
// public PaymentParam(String name, String value) {
// mName = name;
// mValue = value;
// }
//
// public PaymentParam(String name, String value, int type) {
// this(name, value);
// mType = type;
//
// }
//
// public int getType() {
// return mType;
// }
//
// public void setType(int type) {
// mType = type;
// }
//
// public String getName() {
// return mName;
// }
//
// public void setName(String name) {
// mName = name;
// }
//
// public String getValue() {
// return mValue;
// }
//
// public void setValue(String value) {
// mValue = value;
// }
// }
// }
//
// public static class PaypointException extends Exception {
// private String mErrorCode;
//
// public String getErrorCode() {
// return mErrorCode;
// }
//
// PaypointException(String message, String errorCode) {
// super(message);
// mErrorCode = errorCode;
// }
// }
//}
\ No newline at end of file
src/com/library/util/Paygo24Utils.java
View file @
346342bd
package
com
.
library
.
util
;
package
com
.
library
.
util
;
import
com.google.gson.Gson
;
import
com.google.gson.Gson
;
import
com.library.util.currency.DiscountFileUtils
;
import
com.paygo24.v3.protocol.*
;
import
com.paygo24.v3.protocol.*
;
import
org.apache.commons.lang3.StringUtils
;
import
org.tempuri.PayGoService
;
import
org.tempuri.PayGoService
;
import
org.tempuri.PayGoServiceSoap
;
import
org.tempuri.PayGoServiceSoap
;
import
org.tempuri.SendRequest
;
import
org.tempuri.SendRequest
;
...
@@ -19,15 +17,16 @@ import java.math.BigInteger;
...
@@ -19,15 +17,16 @@ import java.math.BigInteger;
import
java.net.URL
;
import
java.net.URL
;
import
java.util.Date
;
import
java.util.Date
;
import
java.util.GregorianCalendar
;
import
java.util.GregorianCalendar
;
import
java.util.Map
;
import
java.util.UUID
;
import
java.util.UUID
;
/**
/**
* Description: Paygo24手机充值工具类 Company: youjiang
* Description: Paygo24手机充值工具类 Company: youjiang
* <p>
* 接口文档地址: http://developers.paygo24.com/api-dealers-api-v3
*
*
* @author Kwum
* @author Kwum
* @date 2017年9月8日 下午4:58:14
* @version 1.0
* @version 1.0
* @date 2017年9月8日 下午4:58:14
*/
*/
public
class
Paygo24Utils
{
public
class
Paygo24Utils
{
...
@@ -58,15 +57,13 @@ public class Paygo24Utils {
...
@@ -58,15 +57,13 @@ public class Paygo24Utils {
/**
/**
* 配置文件中的paygo24 id
* 配置文件中的paygo24 id
*/
*/
private
static
Integer
POINT_ID
;
private
static
Integer
POINT_ID
=
451717
;
/**
/**
* 配置文件中的paygo24 密码
* 配置文件中的paygo24 密码
*/
*/
private
static
String
PASSWORD
;
private
static
String
PASSWORD
=
"iWoQosQ+z9YFXqKuyPyRNg=="
;
/**
* 配置文件中是否存在paygo24账号
*/
private
static
boolean
hasAccount
=
true
;
/**
/**
* 付款后余额
* 付款后余额
*/
*/
...
@@ -77,45 +74,10 @@ public class Paygo24Utils {
...
@@ -77,45 +74,10 @@ public class Paygo24Utils {
private
BigDecimal
currentBalance
;
private
BigDecimal
currentBalance
;
/*** 重新查询的次数 ****/
/*** 重新查询的次数 ****/
private
Integer
count
;
private
Integer
count
;
private
static
boolean
ISTEST
;
static
{
Map
<
String
,
String
>
map
;
try
{
map
=
DiscountFileUtils
.
loopRead
(
"/exchangerate.properties"
);
if
(
map
.
get
(
"paygo.pointid"
)
!=
null
&&
map
.
get
(
"paygo.password"
)
!=
null
)
{
// POINT_ID = Integer.parseInt(map.get("paygo.pointid"));
// PASSWORD = AESUtils.decryptData(AESUtils.DEFAULT_KEY, map.get("paygo.password"));
// POINT_ID =326386 ;
// PASSWORD = "5TNO+4kpAXtphf1eIlGCLw==";
System
.
out
.
println
(
PASSWORD
);
// paygo.pointid=326386
// paygo.password=5TNO+4kpAXtphf1eIlGCLw==
}
else
{
hasAccount
=
false
;
}
String
strIsTest
=
map
.
get
(
"paygo.test.is"
);
if
(
StringUtils
.
isNotBlank
(
strIsTest
)){
if
(
strIsTest
.
equalsIgnoreCase
(
"true"
)){
ISTEST
=
true
;
}
else
{
ISTEST
=
false
;
}
}
else
{
ISTEST
=
false
;
}
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
hasAccount
=
false
;
ISTEST
=
false
;
}
}
public
static
void
main
(
String
[]
args
)
{
public
static
void
main
(
String
[]
args
)
{
Paygo24Utils
paygo24Utils
=
new
Paygo24Utils
();
Paygo24Utils
paygo24Utils
=
new
Paygo24Utils
();
String
result
=
paygo24Utils
.
payment
(
"0
960000000"
,
2
,
new
BigDecimal
(
1.0
));
String
result
=
paygo24Utils
.
payment
(
"0
887038371"
,
4
,
new
BigDecimal
(
1.0
));
System
.
out
.
println
(
"result:"
+
result
);
System
.
out
.
println
(
"result:"
+
result
);
}
}
...
@@ -132,23 +94,12 @@ public class Paygo24Utils {
...
@@ -132,23 +94,12 @@ public class Paygo24Utils {
* @author kwum
* @author kwum
*/
*/
public
String
payment
(
String
phone
,
Integer
serviceId
,
BigDecimal
money
)
{
public
String
payment
(
String
phone
,
Integer
serviceId
,
BigDecimal
money
)
{
if
(!
hasAccount
)
{
// 配置文件中不存在paygo账号
return
"Paygo account doesn't exist"
;
}
try
{
try
{
//https://api2.paygo24.com/paygoservice.asmx?wsdl
// PayGoService service = new PayGoService(new URL("https://processing2.paygo24.com/paygoservice.asmx"),
// QName.valueOf("{http://tempuri.org/}PayGoService"));
PayGoService
service
;
ISTEST
=
true
;
PayGoService
service
;
if
(
ISTEST
)
{
service
=
new
PayGoService
(
new
URL
(
"https://api2.paygo24.com/paygoservice.asmx"
),
QName
.
valueOf
(
"{http://tempuri.org/}PayGoService"
));
}
else
{
service
=
new
PayGoService
(
new
URL
(
"https://processing2.paygo24.com/paygoservice.asmx"
),
service
=
new
PayGoService
(
new
URL
(
"https://processing2.paygo24.com/paygoservice.asmx"
),
QName
.
valueOf
(
"{http://tempuri.org/}PayGoService"
));
QName
.
valueOf
(
"{http://tempuri.org/}PayGoService"
));
}
PayGoServiceSoap
soap
=
service
.
getPayGoServiceSoap
();
PayGoServiceSoap
soap
=
service
.
getPayGoServiceSoap
();
SendRequest
sendRequest
=
new
SendRequest
();
SendRequest
sendRequest
=
new
SendRequest
();
sendRequest
.
setPointId
(
POINT_ID
);
sendRequest
.
setPointId
(
POINT_ID
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment