Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
O
oto
Project
Project
Details
Activity
Releases
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
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
龚小红
oto
Commits
65b13a27
Commit
65b13a27
authored
Aug 05, 2021
by
龚小红
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
封装取关和关注公众号、禁用和切换会员
parent
07383f9d
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
279 additions
and
118 deletions
+279
-118
NoviceGuidance.java
...est/java/com/kjj/cases/assistant/menu/NoviceGuidance.java
+23
-115
KjyUserDB.java
src/test/java/com/kjj/sql/KjyUserDB.java
+143
-0
UserSqlFactory.java
src/test/java/com/kjj/sql/UserSqlFactory.java
+10
-0
BaseUtils.java
src/test/java/com/kjj/utils/BaseUtils.java
+103
-3
No files found.
src/test/java/com/kjj/cases/assistant/menu/NoviceGuidance.java
View file @
65b13a27
...
...
@@ -8,7 +8,7 @@ import org.testng.Assert;
import
org.testng.annotations.*
;
import
java.io.UnsupportedEncodingException
;
import
java.
net.URLEncoder
;
import
java.
sql.SQLException
;
import
java.util.HashMap
;
import
java.util.Map
;
...
...
@@ -17,12 +17,11 @@ import static com.kjj.utils.BaseUtils.*;
import
static
com
.
kjj
.
utils
.
ThreadSleepUtils
.
sleep
;
public
class
NoviceGuidance
implements
Authorization
{
private
int
userId
;
//小葡萄的用户id
private
int
sellerId
;
//小葡萄的销售id
private
long
userId
;
//小葡萄的用户id
private
long
sellerId
;
//小葡萄的销售id
private
String
grasscontentId
;
//文章id
private
String
scid
;
//转发文章的scid
private
String
visitId
;
//访问id
private
String
tku
;
//小葡萄的tku
private
static
final
NetworkUtils
network
=
NetworkUtils
.
getInstance
();
@BeforeClass
public
void
setUp
(){
...
...
@@ -30,111 +29,22 @@ public class NoviceGuidance implements Authorization {
}
@Test
(
description
=
"禁用代理人小葡萄"
,
priority
=
1
)
public
void
禁用代理人小葡萄
()
throws
UnsupportedEncodingException
{
public
void
禁用代理人小葡萄
()
throws
UnsupportedEncodingException
,
SQLException
{
//取关公众号
network
.
agentHeaders
.
put
(
"Content-Type"
,
"text/plain"
);
String
str
=
"<xml><ToUserName><![CDATA[gh_3b9884c7b0ee]]></ToUserName><FromUserName><![CDATA[osi5w5kT-smQ42Fc-ByO4G8C-E1M]]></FromUserName><CreateTime>1628040963</CreateTime><MsgType><![CDATA[event]]></MsgType><Event><![CDATA[unsubscribe]]></Event></xml>"
;
Response
response
=
network
.
postXMLResponse
(
str
,
MANAGER_oamsg
);
System
.
out
.
println
(
"取关\n"
+
response
.
body
().
asString
());
network
.
agentHeaders
.
put
(
"Content-Type"
,
"application/json"
);
//找到小葡萄的用户id
Map
<
String
,
Object
>
params
=
new
HashMap
<
String
,
Object
>();
params
.
put
(
"sellerName"
,
"小葡萄"
);
params
.
put
(
"sellerId"
,
""
);
params
.
put
(
"pageNo"
,
1
);
params
.
put
(
"pageSize"
,
50
);
params
.
put
(
"agentId"
,
""
);
params
.
put
(
"phoneNumber"
,
""
);
response
=
network
.
getResponse
(
params
,
MANAGER_vipList
);
System
.
out
.
println
(
params
.
toString
());
boolean
success
=
response
.
jsonPath
().
getBoolean
(
"success"
);
Object
data
=
response
.
jsonPath
().
getJsonObject
(
"data"
);
System
.
out
.
println
(
response
.
body
().
asString
());
Assert
.
assertTrue
(
success
,
network
.
message
(
params
,
MANAGER_vipList
,
"接口返回失败"
,
response
.
body
().
asString
()));
Assert
.
assertNotNull
(
data
,
network
.
message
(
params
,
MANAGER_vipList
,
"返回数据为空"
,
response
.
body
().
asString
()));
userId
=
response
.
jsonPath
().
getInt
(
"data.list.get(0).userId"
);
sellerId
=
response
.
jsonPath
().
getInt
(
"data.list.get(0).userVersionList.get(0).sellerId"
);
userId
=
(
long
)
unsubscribe
();
//禁用账号
params
.
put
(
"userId"
,
userId
);
response
=
network
.
postResponse
(
params
,
MANAGER_disableUser
);
success
=
response
.
jsonPath
().
getBoolean
(
"success"
);
boolean
result
=
response
.
jsonPath
().
getBoolean
(
"data"
);
System
.
out
.
println
(
"禁用:"
+
response
.
body
().
asString
());
Assert
.
assertTrue
(
success
,
network
.
message
(
params
,
MANAGER_disableUser
,
"接口返回失败"
,
response
.
body
().
asString
()));
Assert
.
assertTrue
(
result
,
network
.
message
(
params
,
MANAGER_disableUser
,
"返回数据为空"
,
response
.
body
().
asString
()));
disableUser
(
userId
);
}
@Test
(
description
=
"小葡萄关注公众号"
,
priority
=
2
)
public
void
小葡萄关注公众号
()
{
@Test
(
description
=
"小葡萄关注公众号
并切换为会员
"
,
priority
=
2
)
public
void
小葡萄关注公众号
并切换为会员
()
throws
SQLException
{
//关注公众号
network
.
agentHeaders
.
put
(
"Content-Type"
,
"text/plain"
);
String
str
=
"<xml><ToUserName><![CDATA[gh_3b9884c7b0ee]]></ToUserName><FromUserName><![CDATA[osi5w5kT-smQ42Fc-ByO4G8C-E1M]]></FromUserName><CreateTime>1628040971</CreateTime><MsgType><![CDATA[event]]></MsgType><Event><![CDATA[subscribe]]></Event></xml>"
;
Response
response
=
network
.
postXMLResponse
(
str
,
MANAGER_oamsg
);
System
.
out
.
println
(
"关注\n"
+
response
.
body
().
asString
());
sleep
(
5000
);
network
.
agentHeaders
.
put
(
"Content-Type"
,
"application/json"
);
//找到小葡萄的用户id
Map
<
String
,
Object
>
params
=
new
HashMap
<
String
,
Object
>();
params
.
put
(
"sellerName"
,
"小葡萄"
);
params
.
put
(
"sellerId"
,
""
);
params
.
put
(
"pageNo"
,
1
);
params
.
put
(
"pageSize"
,
50
);
params
.
put
(
"agentId"
,
""
);
params
.
put
(
"phoneNumber"
,
""
);
response
=
network
.
getResponse
(
params
,
MANAGER_vipList
);
System
.
out
.
println
(
params
.
toString
());
boolean
success
=
response
.
jsonPath
().
getBoolean
(
"success"
);
Object
data
=
response
.
jsonPath
().
getJsonObject
(
"data"
);
System
.
out
.
println
(
response
.
body
().
asString
());
Assert
.
assertTrue
(
success
,
network
.
message
(
params
,
MANAGER_vipList
,
"接口返回失败"
,
response
.
body
().
asString
()));
Assert
.
assertNotNull
(
data
,
network
.
message
(
params
,
MANAGER_vipList
,
"返回数据为空"
,
response
.
body
().
asString
()));
userId
=
response
.
jsonPath
().
getInt
(
"data.list.get(0).userId"
);
sellerId
=
response
.
jsonPath
().
getInt
(
"data.list.get(0).userVersionList.get(0).sellerId"
);
//切换代理人公司
params
.
clear
();
params
.
put
(
"id"
,
sellerId
);
params
.
put
(
"companyId"
,
6
);
response
=
network
.
getResponse
(
params
,
MANAGER_changeCompany
);
System
.
out
.
println
(
params
.
toString
());
success
=
response
.
jsonPath
().
getBoolean
(
"success"
);
boolean
result
=
response
.
jsonPath
().
getBoolean
(
"data"
);
System
.
out
.
println
(
response
.
body
().
asString
());
Assert
.
assertTrue
(
success
,
network
.
message
(
params
,
MANAGER_changeCompany
,
"接口返回失败"
,
response
.
body
().
asString
()));
Assert
.
assertTrue
(
result
,
network
.
message
(
params
,
MANAGER_changeCompany
,
"返回数据为空"
,
response
.
body
().
asString
()));
userId
=
(
long
)
subscribe
();
//切换会员
params
.
put
(
"reason"
,
"测试账号"
);
params
.
put
(
"sellerId"
,
sellerId
);
params
.
put
(
"userVersion"
,
2
);
params
.
put
(
"vipEndDate"
,
"2022-08-04T07:10:03.582Z"
);
params
.
put
(
"vipStartDate"
,
"2021-08-04T07:10:03.582Z"
);
params
.
put
(
"vipType"
,
2
);
response
=
network
.
postResponse
(
params
,
MANAGER_updateTypeOrDate
);
success
=
response
.
jsonPath
().
getBoolean
(
"success"
);
result
=
response
.
jsonPath
().
getBoolean
(
"data"
);
Assert
.
assertTrue
(
success
,
network
.
message
(
params
,
MANAGER_updateTypeOrDate
,
"接口返回失败"
,
response
.
body
().
asString
()));
Assert
.
assertTrue
(
result
,
network
.
message
(
params
,
MANAGER_updateTypeOrDate
,
"返回数据为空"
,
response
.
body
().
asString
()));
}
@Test
(
description
=
"获取小葡萄的tku"
,
priority
=
3
)
public
void
获取小葡萄的
tku
(){
Map
<
String
,
Object
>
params
=
new
HashMap
<
String
,
Object
>();
params
.
put
(
"userId"
,
userId
);
params
.
put
(
"validDays"
,
365
);
Response
response
=
network
.
getResponse
(
params
,
MANAGER_encryptTku
);
boolean
success
=
response
.
jsonPath
().
getBoolean
(
"success"
);
Assert
.
assertTrue
(
success
,
network
.
message
(
ROOKIEGUIDE_homeGuide
,
"接口返回失败"
,
response
.
body
().
asString
()));
tku
=
response
.
jsonPath
().
getString
(
"data"
);
network
.
agentCookies
.
put
(
"tku"
,
tku
);
System
.
out
.
println
(
"代理人tku:"
+
tku
);
updateTypeOrDate
(
userId
);
}
@Test
(
description
=
"进入首页唤起完善名片引导"
,
priority
=
4
)
@Test
(
description
=
"进入首页唤起完善名片引导"
,
priority
=
3
)
public
void
进入首页唤起完善名片引导
(){
Response
response
=
network
.
getResponse
(
ROOKIEGUIDE_homeGuide
);
boolean
success
=
response
.
jsonPath
().
getBoolean
(
"success"
);
...
...
@@ -143,7 +53,7 @@ public class NoviceGuidance implements Authorization {
Assert
.
assertEquals
(
guideType
,
11
,
network
.
message
(
ROOKIEGUIDE_homeGuide
,
"返回数据为空"
,
response
.
body
().
asString
()));
}
@Test
(
description
=
"小葡萄保存名片基本信息"
,
priority
=
5
)
@Test
(
description
=
"小葡萄保存名片基本信息"
,
priority
=
4
)
public
void
小葡萄保存名片基本信息
()
{
HashMap
<
String
,
Object
>
params
=
new
HashMap
<
String
,
Object
>();
//修改用户信息
...
...
@@ -154,7 +64,7 @@ public class NoviceGuidance implements Authorization {
Assert
.
assertTrue
(
success
,
network
.
message
(
params
,
SELLERCARD_editBaseInfo
,
"接口返回失败状态"
,
response
.
body
().
asString
()));
}
@Test
(
description
=
"进入名片后唤起新手引导"
,
priority
=
6
)
@Test
(
description
=
"进入名片后唤起新手引导"
,
priority
=
5
)
public
void
进入名片后唤起新手引导
(){
Response
response
=
network
.
getResponse
(
SELLERCARD_CARDGUIDE
);
boolean
success
=
response
.
jsonPath
().
getBoolean
(
"success"
);
...
...
@@ -163,7 +73,7 @@ public class NoviceGuidance implements Authorization {
Assert
.
assertEquals
(
guideType
,
21
,
network
.
message
(
SELLERCARD_CARDGUIDE
,
"引导类型错误"
,
response
.
body
().
asString
()));
}
@Test
(
description
=
"完成名片的新手引导"
,
priority
=
7
)
@Test
(
description
=
"完成名片的新手引导"
,
priority
=
6
)
public
void
完成名片的新手引导
(){
Map
<
String
,
Object
>
params
=
new
HashMap
<
String
,
Object
>();
params
.
put
(
"guideType"
,
21
);
...
...
@@ -181,7 +91,7 @@ public class NoviceGuidance implements Authorization {
Assert
.
assertEquals
(
guideType
,
0
,
network
.
message
(
SELLERCARD_CARDGUIDE
,
"引导类型错误"
,
response
.
body
().
asString
()));
}
@Test
(
description
=
"再次进入首页唤起没有新手引导"
,
priority
=
8
)
@Test
(
description
=
"再次进入首页唤起没有新手引导"
,
priority
=
7
)
public
void
再次进入首页唤起没有新手引导
(){
Response
response
=
network
.
getResponse
(
ROOKIEGUIDE_homeGuide
);
boolean
success
=
response
.
jsonPath
().
getBoolean
(
"success"
);
...
...
@@ -190,7 +100,7 @@ public class NoviceGuidance implements Authorization {
Assert
.
assertEquals
(
guideType
,
12
,
network
.
message
(
ROOKIEGUIDE_homeGuide
,
"返回数据为空"
,
response
.
body
().
asString
()));
}
@Test
(
description
=
"进入谁看过我后唤起转发引导"
,
priority
=
9
)
@Test
(
description
=
"进入谁看过我后唤起转发引导"
,
priority
=
8
)
public
void
进入谁看过我后唤起转发引导
(){
Response
response
=
network
.
getResponse
(
ROOKIECLUEGUIDE
);
boolean
success
=
response
.
jsonPath
().
getBoolean
(
"success"
);
...
...
@@ -199,7 +109,7 @@ public class NoviceGuidance implements Authorization {
Assert
.
assertEquals
(
guideType
,
35
,
network
.
message
(
ROOKIECLUEGUIDE
,
"引导类型错误"
,
response
.
body
().
asString
()));
}
@Test
(
description
=
"点击完成线索的转发引导"
,
priority
=
10
)
@Test
(
description
=
"点击完成线索的转发引导"
,
priority
=
9
)
public
void
点击完成线索的转发引导
(){
Response
response
=
network
.
getResponse
(
SELLERCARD_CARDGUIDE
);
Map
<
String
,
Object
>
params
=
new
HashMap
<
String
,
Object
>();
...
...
@@ -224,7 +134,7 @@ public class NoviceGuidance implements Authorization {
Assert
.
assertEquals
(
guideType
,
0
,
network
.
message
(
ROOKIECLUEGUIDE
,
"引导类型错误"
,
response
.
body
().
asString
()));
}
@Test
(
description
=
"代理人转发文章后访客查看文章"
,
priority
=
1
1
)
@Test
(
description
=
"代理人转发文章后访客查看文章"
,
priority
=
1
0
)
public
void
代理人转发文章
(){
//获取种草素材id
Response
response
=
network
.
getResponse
(
ARTICLE_GETEXPLOSIONCONTENTLIST
);
...
...
@@ -258,7 +168,7 @@ public class NoviceGuidance implements Authorization {
Assert
.
assertNotNull
(
visitId
,
network
.
message
(
params
,
CONTENT_READ
,
"访客记录查看素材失败"
,
response
.
body
().
asString
()));
}
@Test
(
description
=
"代理人点击谁看过我显示备注引导"
,
priority
=
1
2
)
@Test
(
description
=
"代理人点击谁看过我显示备注引导"
,
priority
=
1
1
)
public
void
代理人点击谁看过我显示备注引导
(){
network
.
agentCookies
.
put
(
"tku"
,
tku
);
Response
response
=
network
.
getResponse
(
ROOKIECLUEGUIDE
);
...
...
@@ -268,7 +178,7 @@ public class NoviceGuidance implements Authorization {
Assert
.
assertEquals
(
guideType
,
34
,
network
.
message
(
ROOKIECLUEGUIDE
,
"引导类型错误"
,
response
.
body
().
asString
()));
}
@Test
(
description
=
"点击完成线索的备注引导"
,
priority
=
1
3
)
@Test
(
description
=
"点击完成线索的备注引导"
,
priority
=
1
2
)
public
void
点击完成线索的备注引导
(){
Response
response
=
network
.
getResponse
(
SELLERCARD_CARDGUIDE
);
Map
<
String
,
Object
>
params
=
new
HashMap
<
String
,
Object
>();
...
...
@@ -285,7 +195,7 @@ public class NoviceGuidance implements Authorization {
Assert
.
assertTrue
(
success
,
network
.
message
(
ROOKIECLUEGUIDE
,
"接口返回失败"
,
response
.
body
().
asString
()));
Assert
.
assertEquals
(
guideType
,
0
,
network
.
message
(
ROOKIECLUEGUIDE
,
"引导类型错误"
,
response
.
body
().
asString
()));
}
@Test
(
description
=
"代理人转发文章后访客领取资料包"
,
priority
=
1
4
)
@Test
(
description
=
"代理人转发文章后访客领取资料包"
,
priority
=
1
3
)
public
void
代理人转发文章后访客领取资料包
(){
userTku
();
sleep
(
2000
);
...
...
@@ -330,7 +240,7 @@ public class NoviceGuidance implements Authorization {
Assert
.
assertTrue
(
success
,
network
.
message
(
params
,
SELLERCARD_SENDPUSHFORSCAN
,
"接口返回失败"
,
response
.
body
().
asString
()));
Assert
.
assertEquals
(
result
,
"success"
,
network
.
message
(
params
,
SELLERCARD_SENDPUSHFORSCAN
,
"领取赠险失败"
,
response
.
body
().
asString
()));
}
@Test
(
description
=
"代理人点击谁看过我显示备注引导"
,
priority
=
1
5
)
@Test
(
description
=
"代理人点击谁看过我显示备注引导"
,
priority
=
1
4
)
public
void
代理人点击谁看过我显示跟进机会引导
(){
network
.
agentCookies
.
put
(
"tku"
,
tku
);
...
...
@@ -342,7 +252,7 @@ public class NoviceGuidance implements Authorization {
Assert
.
assertEquals
(
guideType
,
31
,
network
.
message
(
ROOKIECLUEGUIDE
,
"引导类型错误"
,
response
.
body
().
asString
()));
}
@Test
(
description
=
"点击完成线索的备注引导"
,
priority
=
1
6
)
@Test
(
description
=
"点击完成线索的备注引导"
,
priority
=
1
5
)
public
void
点击完成线索的跟进机会引导
(){
Response
response
=
network
.
getResponse
(
SELLERCARD_CARDGUIDE
);
Map
<
String
,
Object
>
params
=
new
HashMap
<
String
,
Object
>();
...
...
@@ -373,6 +283,4 @@ public class NoviceGuidance implements Authorization {
Assert
.
assertTrue
(
success
,
network
.
message
(
ROOKIECLUEGUIDE
,
"接口返回失败"
,
response
.
body
().
asString
()));
Assert
.
assertEquals
(
guideType
,
0
,
network
.
message
(
ROOKIECLUEGUIDE
,
"引导类型错误"
,
response
.
body
().
asString
()));
}
}
src/test/java/com/kjj/
utils/MysqlUtils
.java
→
src/test/java/com/kjj/
sql/KjyUserDB
.java
View file @
65b13a27
package
com
.
kjj
.
utils
;
package
com
.
kjj
.
sql
;
import
java.sql.*
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
com.alibaba.fastjson.JSON
;
public
class
MysqlUtils
{
private
static
final
String
PREFIX
=
"dbseccode"
;
private
static
final
String
secret
=
"CNxgrtFG2nYQUfu"
;
import
java.sql.*
;
import
java.util.*
;
private
static
Map
<
String
,
MysqlUtils
>
pool
=
new
HashMap
<>();
public
class
KjyUserDB
{
private
static
KjyUserDB
user_Utils
;
//数据库用户名
private
String
USERNAME
;
// = "roo
t";
private
String
USERNAME
=
"auto_tes
t"
;
//数据库密码
private
String
PASSWORD
;
//= "yanzi";
private
String
PASSWORD
=
"881QYHoGGgc09Ngv"
;
//= "yanzi";
//驱动信息
private
String
DRIVER
=
"com.mysql.cj.jdbc.Driver"
;
//数据库地址
private
String
U
RL
;
// = "jdbc:mysql://localhost:3306/mydb
";
private
String
U
SER_URL
=
"jdbc:mysql://rm-bp11mkg584kvjr485.mysql.rds.aliyuncs.com:3306/kjy_user
"
;
private
Connection
connection
;
private
PreparedStatement
pstmt
;
private
ResultSet
resultSet
;
private
MysqlUtils
(
String
username
,
String
password
,
String
url
){
USERNAME
=
username
;
PASSWORD
=
decode
(
password
);
URL
=
url
;
MysqlUtils
mu
=
pool
.
get
(
url
);
if
(
mu
!=
null
){
System
.
out
.
println
(
"--------exists"
);
connection
=
mu
.
connection
;
}
else
{
connection
=
getConnection
();
pool
.
put
(
url
,
this
);
}
// if(mu!=null) {
// try {
// mu.connection.close();
// } catch (Exception e) {
// System.out.println("mysql error:" + e.getMessage());
// }
// }
//// }else {
// connection = getConnection();
// pool.put(url,this);
public
static
synchronized
KjyUserDB
getInstance
(){
if
(
Objects
.
nonNull
(
user_Utils
)){
return
user_Utils
;
}
/**
*
* @param username 用户名
* @param password 密码
* @param ip 数据库ip
* @param port 端口号
* @param databaseName 数据库名
*/
public
MysqlUtils
(
String
username
,
String
password
,
String
ip
,
String
port
,
String
databaseName
){
this
(
username
,
password
,
"jdbc:mysql://"
+
ip
+
":"
+
port
+
"/"
+
databaseName
);
user_Utils
=
new
KjyUserDB
();
user_Utils
.
initConnection
();
return
user_Utils
;
}
/**
* 阿里云数据库连接
* @param databaseName 数据库名字
*/
public
MysqlUtils
(
String
databaseName
){
this
(
"tuia_test"
,
"dbseccode2CJMouQ2xyuEXnhe4vBzGtrDpaDbuK8Lt"
,
"47.111.157.152"
,
"3306"
,
databaseName
);
}
public
static
MysqlUtils
mysqlDuiba
(
String
databaseName
){
return
new
MysqlUtils
(
"tuia_test"
,
"dbseccode2CJMouQ2xyuEXnhe4vGtrDpavyDbuK8Lt"
,
"47.111.157.152"
,
"3306"
,
databaseName
);
}
/**
* 获得数据库的连接
* @return
*/
public
Connection
getConnection
(){
private
Connection
initConnection
(){
try
{
try
{
Class
.
forName
(
DRIVER
);
...
...
@@ -86,10 +40,7 @@ public class MysqlUtils {
}
catch
(
ClassNotFoundException
e
)
{
e
.
printStackTrace
();
}
// connection = DriverManager.getConnection(URL, USERNAME, PASSWORD);
// "jdbc:mysql://"+ip+":"+port+"/"+databaseName);
String
url
=
URL
+
"?autoReconnect=true&testOnBorrow=true&testWhileIdle=true"
;
String
url
=
USER_URL
+
"?autoReconnect=true&testOnBorrow=true&testWhileIdle=true"
;
connection
=
DriverManager
.
getConnection
(
url
,
USERNAME
,
PASSWORD
);
System
.
out
.
println
(
"数据库连接成功!"
);
}
catch
(
SQLException
e
)
{
...
...
@@ -97,36 +48,7 @@ public class MysqlUtils {
}
return
connection
;
}
/**
* 增加、删除、改
* @param sql sql语句
* @param params 参数,替换 ?
* @return true or false
* @throws SQLException
*/
public
boolean
update
(
String
sql
,
Object
...
params
)
throws
SQLException
{
if
(!
connection
.
isValid
(
3
)){
System
.
out
.
println
(
"mysql connect is not vaild,reconnect."
);
connection
.
close
();
connection
=
getConnection
();
pool
.
put
(
URL
,
this
);
}
boolean
flag
=
false
;
int
result
=
-
1
;
pstmt
=
connection
.
prepareStatement
(
sql
);
int
index
=
1
;
if
(
params
!=
null
&&
!(
params
.
length
==
0
)){
for
(
int
i
=
0
;
i
<
params
.
length
;
i
++){
pstmt
.
setObject
(
index
++,
params
[
i
]);
}
}
System
.
out
.
println
(
"SQL语句"
+
pstmt
.
toString
());
result
=
pstmt
.
executeUpdate
();
flag
=
result
>
0
?
true
:
false
;
return
flag
;
}
/**
* 查询结果只有一行数据
* @param sql sql语句
...
...
@@ -138,8 +60,7 @@ public class MysqlUtils {
if
(!
connection
.
isValid
(
3
)){
System
.
out
.
println
(
"mysql connect is not vaild,reconnect."
);
connection
.
close
();
connection
=
getConnection
();
pool
.
put
(
URL
,
this
);
initConnection
();
}
Map
<
String
,
Object
>
map
=
new
HashMap
<
String
,
Object
>();
int
index
=
1
;
...
...
@@ -177,8 +98,7 @@ public class MysqlUtils {
if
(!
connection
.
isValid
(
3
)){
System
.
out
.
println
(
"mysql connect is not vaild,reconnect."
);
connection
.
close
();
connection
=
getConnection
();
pool
.
put
(
URL
,
this
);
initConnection
();
}
List
<
Map
<
String
,
Object
>>
list
=
new
ArrayList
<
Map
<
String
,
Object
>>();
int
index
=
1
;
...
...
@@ -218,22 +138,6 @@ public class MysqlUtils {
}
}
}
public
static
void
main
(
String
[]
args
)
throws
SQLException
{
MysqlUtils
jdbcUtils
=
new
MysqlUtils
(
"tuia_adver"
);
jdbcUtils
.
getConnection
();
Map
<
String
,
Object
>
map
=
jdbcUtils
.
findSimpleResult
(
"select * from account where company_name=?"
,
"兑吧科技有限公司"
);
jdbcUtils
.
releaseConn
();
}
private
static
String
decode
(
String
value
)
{
if
(
value
.
startsWith
(
PREFIX
))
{
value
=
value
.
substring
(
PREFIX
.
length
());
return
BlowfishUtils
.
decryptBlowfish
(
value
,
secret
);
}
return
value
;
}
}
src/test/java/com/kjj/sql/UserSqlFactory.java
0 → 100644
View file @
65b13a27
package
com
.
kjj
.
sql
;
public
class
UserSqlFactory
{
private
UserSqlFactory
(){}
public
static
final
String
selectUserIdByUnionId
=
"select id from tb_users where union_id=?"
;
public
static
final
String
selectUserIdByOpenId
=
"SELECT user_id FROM `tb_users_wx_ext` WHERE `open_id` = ?"
;
}
src/test/java/com/kjj/utils/BaseUtils.java
View file @
65b13a27
package
com
.
kjj
.
utils
;
import
com.kjj.sql.KjyUserDB
;
import
com.kjj.sql.UserSqlFactory
;
import
io.restassured.response.Response
;
import
org.testng.Assert
;
import
java.
io.IO
Exception
;
import
java.
util.HashMap
;
import
java.util.
Map
;
import
java.
sql.SQL
Exception
;
import
java.
text.SimpleDateFormat
;
import
java.util.
*
;
import
static
com
.
kjj
.
config
.
BasicConfig
.*;
import
static
com
.
kjj
.
utils
.
ThreadSleepUtils
.
sleep
;
public
class
BaseUtils
{
private
static
final
NetworkUtils
network
=
NetworkUtils
.
getInstance
();
public
static
String
tku
;
/**
* 登录管理后台
...
...
@@ -42,6 +46,102 @@ public class BaseUtils {
network
.
agentHeaders
.
put
(
"X-Csrf-Token"
,
ssoCookies
.
get
(
"csrf_token"
));
// 免登
network
.
agentCookies
.
put
(
"sso_ticket"
,
"autotest"
);
}
/**
* 小葡萄关注客集集微信公众号
*/
public
static
Object
subscribe
()
throws
SQLException
{
//关注公众号
// network.agentHeaders.put("Content-Type","text/plain");
String
str
=
"<xml><ToUserName><![CDATA[gh_3b9884c7b0ee]]></ToUserName><FromUserName><![CDATA[osi5w5kT-smQ42Fc-ByO4G8C-E1M]]></FromUserName><CreateTime>1628040971</CreateTime><MsgType><![CDATA[event]]></MsgType><Event><![CDATA[subscribe]]></Event></xml>"
;
Response
response
=
network
.
postXMLResponse
(
str
,
MANAGER_oamsg
);
System
.
out
.
println
(
"关注\n"
+
response
.
body
().
asString
());
sleep
(
1000
);
network
.
agentHeaders
.
put
(
"Content-Type"
,
"application/json"
);
Map
<
String
,
Object
>
result
=
KjyUserDB
.
getInstance
().
findSimpleResult
(
UserSqlFactory
.
selectUserIdByOpenId
,
"osi5w5kT-smQ42Fc-ByO4G8C-E1M"
);
Object
userId
=
result
.
get
(
"user_id"
);
Map
<
String
,
Object
>
params
=
new
HashMap
<
String
,
Object
>();
params
.
put
(
"userId"
,
userId
);
params
.
put
(
"validDays"
,
365
);
response
=
network
.
getResponse
(
params
,
MANAGER_encryptTku
);
boolean
success
=
response
.
jsonPath
().
getBoolean
(
"success"
);
Assert
.
assertTrue
(
success
,
network
.
message
(
ROOKIEGUIDE_homeGuide
,
"接口返回失败"
,
response
.
body
().
asString
()));
tku
=
response
.
jsonPath
().
getString
(
"data"
);
network
.
agentCookies
.
put
(
"tku"
,
tku
);
System
.
out
.
println
(
"小葡萄tku:"
+
tku
);
return
userId
;
}
/**
* 小葡萄取关客集集微信公众号
*/
public
static
Object
unsubscribe
()
throws
SQLException
{
//取关公众号
network
.
agentHeaders
.
put
(
"Content-Type"
,
"text/plain"
);
String
str
=
"<xml><ToUserName><![CDATA[gh_3b9884c7b0ee]]></ToUserName><FromUserName><![CDATA[osi5w5kT-smQ42Fc-ByO4G8C-E1M]]></FromUserName><CreateTime>1628040963</CreateTime><MsgType><![CDATA[event]]></MsgType><Event><![CDATA[unsubscribe]]></Event></xml>"
;
Response
response
=
network
.
postXMLResponse
(
str
,
MANAGER_oamsg
);
Map
<
String
,
Object
>
result
=
KjyUserDB
.
getInstance
().
findSimpleResult
(
UserSqlFactory
.
selectUserIdByOpenId
,
"osi5w5kT-smQ42Fc-ByO4G8C-E1M"
);
System
.
out
.
println
(
"取关\n"
+
response
.
body
().
asString
());
network
.
agentHeaders
.
put
(
"Content-Type"
,
"application/json"
);
Object
userId
=
result
.
get
(
"user_id"
);
return
userId
;
}
/**
* 禁用
*/
public
static
void
disableUser
(
long
userId
){
Map
<
String
,
Object
>
params
=
new
HashMap
<
String
,
Object
>();
params
.
put
(
"userId"
,
userId
);
Response
response
=
network
.
postResponse
(
params
,
MANAGER_disableUser
);
boolean
success
=
response
.
jsonPath
().
getBoolean
(
"success"
);
boolean
result
=
response
.
jsonPath
().
getBoolean
(
"data"
);
System
.
out
.
println
(
"禁用:"
+
response
.
body
().
asString
());
Assert
.
assertTrue
(
success
,
network
.
message
(
params
,
MANAGER_disableUser
,
"接口返回失败"
,
response
.
body
().
asString
()));
Assert
.
assertTrue
(
result
,
network
.
message
(
params
,
MANAGER_disableUser
,
"返回数据为空"
,
response
.
body
().
asString
()));
}
/**
* 切换为会员
*/
public
static
void
updateTypeOrDate
(
long
userId
){
//找到用户的sellerid
Map
<
String
,
Object
>
params
=
new
HashMap
<
String
,
Object
>();
Response
response
=
network
.
getResponse
(
USER_INFO
);
int
sellerId
=
response
.
jsonPath
().
getInt
(
"data.sellerId"
);
Assert
.
assertNotNull
(
response
.
jsonPath
().
getJsonObject
(
"data"
),
network
.
message
(
USER_INFO
,
"获取用户信息失败"
,
response
.
body
().
asString
()));
//切换代理人公司
params
.
clear
();
params
.
put
(
"id"
,
sellerId
);
params
.
put
(
"companyId"
,
6
);
response
=
network
.
getResponse
(
params
,
MANAGER_changeCompany
);
System
.
out
.
println
(
params
.
toString
());
boolean
success
=
response
.
jsonPath
().
getBoolean
(
"success"
);
boolean
result
=
response
.
jsonPath
().
getBoolean
(
"data"
);
System
.
out
.
println
(
response
.
body
().
asString
());
Assert
.
assertTrue
(
success
,
network
.
message
(
params
,
MANAGER_changeCompany
,
"接口返回失败"
,
response
.
body
().
asString
()));
Assert
.
assertTrue
(
result
,
network
.
message
(
params
,
MANAGER_changeCompany
,
"返回数据为空"
,
response
.
body
().
asString
()));
//切换会员
SimpleDateFormat
df
=
new
SimpleDateFormat
(
"yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"
);
//设置日期格式
Date
date
=
new
Date
();
// new Date()为获取当前系统时间
Calendar
cal
=
Calendar
.
getInstance
();
cal
.
setTime
(
date
);
cal
.
add
(
Calendar
.
YEAR
,
1
);
params
.
put
(
"reason"
,
"测试账号"
);
params
.
put
(
"sellerId"
,
sellerId
);
params
.
put
(
"userVersion"
,
2
);
params
.
put
(
"vipEndDate"
,
df
.
format
(
date
));
params
.
put
(
"vipStartDate"
,
df
.
format
(
cal
.
getTime
()));
params
.
put
(
"vipType"
,
2
);
response
=
network
.
postResponse
(
params
,
MANAGER_updateTypeOrDate
);
success
=
response
.
jsonPath
().
getBoolean
(
"success"
);
result
=
response
.
jsonPath
().
getBoolean
(
"data"
);
Assert
.
assertTrue
(
success
,
network
.
message
(
params
,
MANAGER_updateTypeOrDate
,
"接口返回失败"
,
response
.
body
().
asString
()));
Assert
.
assertTrue
(
result
,
network
.
message
(
params
,
MANAGER_updateTypeOrDate
,
"返回数据为空"
,
response
.
body
().
asString
()));
}
}
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