Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Q
qk_backend
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
quanku
qk_backend
Commits
2e44f766
Commit
2e44f766
authored
Oct 13, 2023
by
shiyu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
公众号订阅
parent
f3320628
Changes
10
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
237 additions
and
26 deletions
+237
-26
ch-dao/src/main/java/com/wwdz/ch/db/domain/OfficialAccountSubscribeRecord.java
...com/wwdz/ch/db/domain/OfficialAccountSubscribeRecord.java
+9
-0
ch-dao/src/main/java/com/wwdz/ch/db/domain/OfficialAccountSubscribeRecordExample.java
...z/ch/db/domain/OfficialAccountSubscribeRecordExample.java
+142
-0
ch-dao/src/main/java/com/wwdz/ch/db/domain/User.java
ch-dao/src/main/java/com/wwdz/ch/db/domain/User.java
+1
-0
ch-dao/src/main/java/com/wwdz/ch/db/impl/OfficialAccountSubscribeRecordDaoImpl.java
...wdz/ch/db/impl/OfficialAccountSubscribeRecordDaoImpl.java
+4
-4
ch-dao/src/main/java/com/wwdz/ch/db/mapper/OfficialAccountSubscribeRecordMapper.java
...dz/ch/db/mapper/OfficialAccountSubscribeRecordMapper.java
+0
-1
ch-dao/src/main/resources/com/wwdz/ch/db/mapper/OfficialAccountSubscribeRecordMapper.xml
...wdz/ch/db/mapper/OfficialAccountSubscribeRecordMapper.xml
+29
-13
ch-wx-api/src/main/java/com/wwdz/ch/wx/api/OfficialAccountApi.java
.../src/main/java/com/wwdz/ch/wx/api/OfficialAccountApi.java
+32
-1
ch-wx-api/src/main/java/com/wwdz/ch/wx/api/OfficialAccountCallbackController.java
...com/wwdz/ch/wx/api/OfficialAccountCallbackController.java
+9
-5
ch-wx-api/src/main/java/com/wwdz/ch/wx/manager/WxLoginManager.java
.../src/main/java/com/wwdz/ch/wx/manager/WxLoginManager.java
+4
-2
ch-wx-api/src/test/java/com/wwdz/ch/wx/api/OfficialAccountApiTest.java
.../test/java/com/wwdz/ch/wx/api/OfficialAccountApiTest.java
+7
-0
No files found.
ch-dao/src/main/java/com/wwdz/ch/db/domain/OfficialAccountSubscribeRecord.java
View file @
2e44f766
...
@@ -21,6 +21,11 @@ public class OfficialAccountSubscribeRecord implements Entity {
...
@@ -21,6 +21,11 @@ public class OfficialAccountSubscribeRecord implements Entity {
*/
*/
private
String
openid
;
private
String
openid
;
/**
* unionid
*/
private
String
unionid
;
/**
/**
* 平台类型(1微信,2支付宝,3其他)
* 平台类型(1微信,2支付宝,3其他)
*/
*/
...
@@ -56,6 +61,7 @@ public class OfficialAccountSubscribeRecord implements Entity {
...
@@ -56,6 +61,7 @@ public class OfficialAccountSubscribeRecord implements Entity {
sb
.
append
(
"Hash = "
).
append
(
hashCode
());
sb
.
append
(
"Hash = "
).
append
(
hashCode
());
sb
.
append
(
", id="
).
append
(
id
);
sb
.
append
(
", id="
).
append
(
id
);
sb
.
append
(
", openid="
).
append
(
openid
);
sb
.
append
(
", openid="
).
append
(
openid
);
sb
.
append
(
", unionid="
).
append
(
unionid
);
sb
.
append
(
", platformType="
).
append
(
platformType
);
sb
.
append
(
", platformType="
).
append
(
platformType
);
sb
.
append
(
", phone="
).
append
(
phone
);
sb
.
append
(
", phone="
).
append
(
phone
);
sb
.
append
(
", createTime="
).
append
(
createTime
);
sb
.
append
(
", createTime="
).
append
(
createTime
);
...
@@ -80,6 +86,7 @@ public class OfficialAccountSubscribeRecord implements Entity {
...
@@ -80,6 +86,7 @@ public class OfficialAccountSubscribeRecord implements Entity {
OfficialAccountSubscribeRecord
other
=
(
OfficialAccountSubscribeRecord
)
that
;
OfficialAccountSubscribeRecord
other
=
(
OfficialAccountSubscribeRecord
)
that
;
return
(
this
.
getId
()
==
null
?
other
.
getId
()
==
null
:
this
.
getId
().
equals
(
other
.
getId
()))
return
(
this
.
getId
()
==
null
?
other
.
getId
()
==
null
:
this
.
getId
().
equals
(
other
.
getId
()))
&&
(
this
.
getOpenid
()
==
null
?
other
.
getOpenid
()
==
null
:
this
.
getOpenid
().
equals
(
other
.
getOpenid
()))
&&
(
this
.
getOpenid
()
==
null
?
other
.
getOpenid
()
==
null
:
this
.
getOpenid
().
equals
(
other
.
getOpenid
()))
&&
(
this
.
getUnionid
()
==
null
?
other
.
getUnionid
()
==
null
:
this
.
getUnionid
().
equals
(
other
.
getUnionid
()))
&&
(
this
.
getPlatformType
()
==
null
?
other
.
getPlatformType
()
==
null
:
this
.
getPlatformType
().
equals
(
other
.
getPlatformType
()))
&&
(
this
.
getPlatformType
()
==
null
?
other
.
getPlatformType
()
==
null
:
this
.
getPlatformType
().
equals
(
other
.
getPlatformType
()))
&&
(
this
.
getPhone
()
==
null
?
other
.
getPhone
()
==
null
:
this
.
getPhone
().
equals
(
other
.
getPhone
()))
&&
(
this
.
getPhone
()
==
null
?
other
.
getPhone
()
==
null
:
this
.
getPhone
().
equals
(
other
.
getPhone
()))
&&
(
this
.
getCreateTime
()
==
null
?
other
.
getCreateTime
()
==
null
:
this
.
getCreateTime
().
equals
(
other
.
getCreateTime
()))
&&
(
this
.
getCreateTime
()
==
null
?
other
.
getCreateTime
()
==
null
:
this
.
getCreateTime
().
equals
(
other
.
getCreateTime
()))
...
@@ -93,6 +100,7 @@ public class OfficialAccountSubscribeRecord implements Entity {
...
@@ -93,6 +100,7 @@ public class OfficialAccountSubscribeRecord implements Entity {
int
result
=
1
;
int
result
=
1
;
result
=
prime
*
result
+
((
getId
()
==
null
)
?
0
:
getId
().
hashCode
());
result
=
prime
*
result
+
((
getId
()
==
null
)
?
0
:
getId
().
hashCode
());
result
=
prime
*
result
+
((
getOpenid
()
==
null
)
?
0
:
getOpenid
().
hashCode
());
result
=
prime
*
result
+
((
getOpenid
()
==
null
)
?
0
:
getOpenid
().
hashCode
());
result
=
prime
*
result
+
((
getUnionid
()
==
null
)
?
0
:
getUnionid
().
hashCode
());
result
=
prime
*
result
+
((
getPlatformType
()
==
null
)
?
0
:
getPlatformType
().
hashCode
());
result
=
prime
*
result
+
((
getPlatformType
()
==
null
)
?
0
:
getPlatformType
().
hashCode
());
result
=
prime
*
result
+
((
getPhone
()
==
null
)
?
0
:
getPhone
().
hashCode
());
result
=
prime
*
result
+
((
getPhone
()
==
null
)
?
0
:
getPhone
().
hashCode
());
result
=
prime
*
result
+
((
getCreateTime
()
==
null
)
?
0
:
getCreateTime
().
hashCode
());
result
=
prime
*
result
+
((
getCreateTime
()
==
null
)
?
0
:
getCreateTime
().
hashCode
());
...
@@ -111,6 +119,7 @@ public class OfficialAccountSubscribeRecord implements Entity {
...
@@ -111,6 +119,7 @@ public class OfficialAccountSubscribeRecord implements Entity {
public
enum
Column
{
public
enum
Column
{
id
(
"id"
,
"id"
,
"INTEGER"
,
false
),
id
(
"id"
,
"id"
,
"INTEGER"
,
false
),
openid
(
"openid"
,
"openid"
,
"VARCHAR"
,
false
),
openid
(
"openid"
,
"openid"
,
"VARCHAR"
,
false
),
unionid
(
"unionid"
,
"unionid"
,
"VARCHAR"
,
false
),
platformType
(
"platform_type"
,
"platformType"
,
"INTEGER"
,
false
),
platformType
(
"platform_type"
,
"platformType"
,
"INTEGER"
,
false
),
phone
(
"phone"
,
"phone"
,
"VARCHAR"
,
false
),
phone
(
"phone"
,
"phone"
,
"VARCHAR"
,
false
),
createTime
(
"create_time"
,
"createTime"
,
"TIMESTAMP"
,
false
),
createTime
(
"create_time"
,
"createTime"
,
"TIMESTAMP"
,
false
),
...
...
ch-dao/src/main/java/com/wwdz/ch/db/domain/OfficialAccountSubscribeRecordExample.java
View file @
2e44f766
...
@@ -422,6 +422,148 @@ public class OfficialAccountSubscribeRecordExample {
...
@@ -422,6 +422,148 @@ public class OfficialAccountSubscribeRecordExample {
return
(
Criteria
)
this
;
return
(
Criteria
)
this
;
}
}
public
Criteria
andUnionidIsNull
()
{
addCriterion
(
"unionid is null"
);
return
(
Criteria
)
this
;
}
public
Criteria
andUnionidIsNotNull
()
{
addCriterion
(
"unionid is not null"
);
return
(
Criteria
)
this
;
}
public
Criteria
andUnionidEqualTo
(
String
value
)
{
addCriterion
(
"unionid ="
,
value
,
"unionid"
);
return
(
Criteria
)
this
;
}
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table official_account_subscribe_record
*
* @mbg.generated
* @project https://github.com/itfsw/mybatis-generator-plugin
*/
public
Criteria
andUnionidEqualToColumn
(
OfficialAccountSubscribeRecord
.
Column
column
)
{
addCriterion
(
new
StringBuilder
(
"unionid = "
).
append
(
column
.
getEscapedColumnName
()).
toString
());
return
(
Criteria
)
this
;
}
public
Criteria
andUnionidNotEqualTo
(
String
value
)
{
addCriterion
(
"unionid <>"
,
value
,
"unionid"
);
return
(
Criteria
)
this
;
}
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table official_account_subscribe_record
*
* @mbg.generated
* @project https://github.com/itfsw/mybatis-generator-plugin
*/
public
Criteria
andUnionidNotEqualToColumn
(
OfficialAccountSubscribeRecord
.
Column
column
)
{
addCriterion
(
new
StringBuilder
(
"unionid <> "
).
append
(
column
.
getEscapedColumnName
()).
toString
());
return
(
Criteria
)
this
;
}
public
Criteria
andUnionidGreaterThan
(
String
value
)
{
addCriterion
(
"unionid >"
,
value
,
"unionid"
);
return
(
Criteria
)
this
;
}
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table official_account_subscribe_record
*
* @mbg.generated
* @project https://github.com/itfsw/mybatis-generator-plugin
*/
public
Criteria
andUnionidGreaterThanColumn
(
OfficialAccountSubscribeRecord
.
Column
column
)
{
addCriterion
(
new
StringBuilder
(
"unionid > "
).
append
(
column
.
getEscapedColumnName
()).
toString
());
return
(
Criteria
)
this
;
}
public
Criteria
andUnionidGreaterThanOrEqualTo
(
String
value
)
{
addCriterion
(
"unionid >="
,
value
,
"unionid"
);
return
(
Criteria
)
this
;
}
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table official_account_subscribe_record
*
* @mbg.generated
* @project https://github.com/itfsw/mybatis-generator-plugin
*/
public
Criteria
andUnionidGreaterThanOrEqualToColumn
(
OfficialAccountSubscribeRecord
.
Column
column
)
{
addCriterion
(
new
StringBuilder
(
"unionid >= "
).
append
(
column
.
getEscapedColumnName
()).
toString
());
return
(
Criteria
)
this
;
}
public
Criteria
andUnionidLessThan
(
String
value
)
{
addCriterion
(
"unionid <"
,
value
,
"unionid"
);
return
(
Criteria
)
this
;
}
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table official_account_subscribe_record
*
* @mbg.generated
* @project https://github.com/itfsw/mybatis-generator-plugin
*/
public
Criteria
andUnionidLessThanColumn
(
OfficialAccountSubscribeRecord
.
Column
column
)
{
addCriterion
(
new
StringBuilder
(
"unionid < "
).
append
(
column
.
getEscapedColumnName
()).
toString
());
return
(
Criteria
)
this
;
}
public
Criteria
andUnionidLessThanOrEqualTo
(
String
value
)
{
addCriterion
(
"unionid <="
,
value
,
"unionid"
);
return
(
Criteria
)
this
;
}
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table official_account_subscribe_record
*
* @mbg.generated
* @project https://github.com/itfsw/mybatis-generator-plugin
*/
public
Criteria
andUnionidLessThanOrEqualToColumn
(
OfficialAccountSubscribeRecord
.
Column
column
)
{
addCriterion
(
new
StringBuilder
(
"unionid <= "
).
append
(
column
.
getEscapedColumnName
()).
toString
());
return
(
Criteria
)
this
;
}
public
Criteria
andUnionidLike
(
String
value
)
{
addCriterion
(
"unionid like"
,
value
,
"unionid"
);
return
(
Criteria
)
this
;
}
public
Criteria
andUnionidNotLike
(
String
value
)
{
addCriterion
(
"unionid not like"
,
value
,
"unionid"
);
return
(
Criteria
)
this
;
}
public
Criteria
andUnionidIn
(
List
<
String
>
values
)
{
addCriterion
(
"unionid in"
,
values
,
"unionid"
);
return
(
Criteria
)
this
;
}
public
Criteria
andUnionidNotIn
(
List
<
String
>
values
)
{
addCriterion
(
"unionid not in"
,
values
,
"unionid"
);
return
(
Criteria
)
this
;
}
public
Criteria
andUnionidBetween
(
String
value1
,
String
value2
)
{
addCriterion
(
"unionid between"
,
value1
,
value2
,
"unionid"
);
return
(
Criteria
)
this
;
}
public
Criteria
andUnionidNotBetween
(
String
value1
,
String
value2
)
{
addCriterion
(
"unionid not between"
,
value1
,
value2
,
"unionid"
);
return
(
Criteria
)
this
;
}
public
Criteria
andPlatformTypeIsNull
()
{
public
Criteria
andPlatformTypeIsNull
()
{
addCriterion
(
"platform_type is null"
);
addCriterion
(
"platform_type is null"
);
return
(
Criteria
)
this
;
return
(
Criteria
)
this
;
...
...
ch-dao/src/main/java/com/wwdz/ch/db/domain/User.java
View file @
2e44f766
...
@@ -95,6 +95,7 @@ public class User implements Serializable {
...
@@ -95,6 +95,7 @@ public class User implements Serializable {
/**
/**
* 微信登录openid
* 微信登录openid
* 存的是unionid
*/
*/
private
String
weixinOpenid
;
private
String
weixinOpenid
;
...
...
ch-dao/src/main/java/com/wwdz/ch/db/impl/OfficialAccountSubscribeRecordDaoImpl.java
View file @
2e44f766
...
@@ -30,18 +30,18 @@ public class OfficialAccountSubscribeRecordDaoImpl implements OfficialAccountSub
...
@@ -30,18 +30,18 @@ public class OfficialAccountSubscribeRecordDaoImpl implements OfficialAccountSub
}
}
@Override
@Override
public
boolean
isExisted
(
String
ope
nid
)
{
public
boolean
isExisted
(
String
unio
nid
)
{
OfficialAccountSubscribeRecordExample
example
=
new
OfficialAccountSubscribeRecordExample
();
OfficialAccountSubscribeRecordExample
example
=
new
OfficialAccountSubscribeRecordExample
();
OfficialAccountSubscribeRecordExample
.
Criteria
criteria
=
example
.
createCriteria
();
OfficialAccountSubscribeRecordExample
.
Criteria
criteria
=
example
.
createCriteria
();
criteria
.
and
OpenidEqualTo
(
ope
nid
);
criteria
.
and
UnionidEqualTo
(
unio
nid
);
return
officialAccountSubscribeRecordMapper
.
countByExample
(
example
)
>
0
;
return
officialAccountSubscribeRecordMapper
.
countByExample
(
example
)
>
0
;
}
}
@Override
@Override
public
boolean
isSubscribed
(
String
ope
nid
)
{
public
boolean
isSubscribed
(
String
unio
nid
)
{
OfficialAccountSubscribeRecordExample
example
=
new
OfficialAccountSubscribeRecordExample
();
OfficialAccountSubscribeRecordExample
example
=
new
OfficialAccountSubscribeRecordExample
();
OfficialAccountSubscribeRecordExample
.
Criteria
criteria
=
example
.
createCriteria
();
OfficialAccountSubscribeRecordExample
.
Criteria
criteria
=
example
.
createCriteria
();
criteria
.
and
OpenidEqualTo
(
ope
nid
);
criteria
.
and
UnionidEqualTo
(
unio
nid
);
criteria
.
andEnabledEqualTo
(
1
);
criteria
.
andEnabledEqualTo
(
1
);
return
officialAccountSubscribeRecordMapper
.
countByExample
(
example
)
>
0
;
return
officialAccountSubscribeRecordMapper
.
countByExample
(
example
)
>
0
;
}
}
...
...
ch-dao/src/main/java/com/wwdz/ch/db/mapper/OfficialAccountSubscribeRecordMapper.java
View file @
2e44f766
...
@@ -7,7 +7,6 @@ import java.util.List;
...
@@ -7,7 +7,6 @@ import java.util.List;
import
org.apache.ibatis.annotations.Mapper
;
import
org.apache.ibatis.annotations.Mapper
;
import
org.apache.ibatis.annotations.Param
;
import
org.apache.ibatis.annotations.Param
;
@Mapper
@Mapper
public
interface
OfficialAccountSubscribeRecordMapper
{
public
interface
OfficialAccountSubscribeRecordMapper
{
long
countByExample
(
OfficialAccountSubscribeRecordExample
example
);
long
countByExample
(
OfficialAccountSubscribeRecordExample
example
);
...
...
ch-dao/src/main/resources/com/wwdz/ch/db/mapper/OfficialAccountSubscribeRecordMapper.xml
View file @
2e44f766
...
@@ -4,6 +4,7 @@
...
@@ -4,6 +4,7 @@
<resultMap
id=
"BaseResultMap"
type=
"com.wwdz.ch.db.domain.OfficialAccountSubscribeRecord"
>
<resultMap
id=
"BaseResultMap"
type=
"com.wwdz.ch.db.domain.OfficialAccountSubscribeRecord"
>
<id
column=
"id"
jdbcType=
"INTEGER"
property=
"id"
/>
<id
column=
"id"
jdbcType=
"INTEGER"
property=
"id"
/>
<result
column=
"openid"
jdbcType=
"VARCHAR"
property=
"openid"
/>
<result
column=
"openid"
jdbcType=
"VARCHAR"
property=
"openid"
/>
<result
column=
"unionid"
jdbcType=
"VARCHAR"
property=
"unionid"
/>
<result
column=
"platform_type"
jdbcType=
"INTEGER"
property=
"platformType"
/>
<result
column=
"platform_type"
jdbcType=
"INTEGER"
property=
"platformType"
/>
<result
column=
"phone"
jdbcType=
"VARCHAR"
property=
"phone"
/>
<result
column=
"phone"
jdbcType=
"VARCHAR"
property=
"phone"
/>
<result
column=
"create_time"
jdbcType=
"TIMESTAMP"
property=
"createTime"
/>
<result
column=
"create_time"
jdbcType=
"TIMESTAMP"
property=
"createTime"
/>
...
@@ -69,7 +70,7 @@
...
@@ -69,7 +70,7 @@
</where>
</where>
</sql>
</sql>
<sql
id=
"Base_Column_List"
>
<sql
id=
"Base_Column_List"
>
id, openid, platform_type, phone, create_time, update_time, enabled
id, openid,
unionid,
platform_type, phone, create_time, update_time, enabled
</sql>
</sql>
<select
id=
"selectByExample"
parameterType=
"com.wwdz.ch.db.domain.OfficialAccountSubscribeRecordExample"
resultMap=
"BaseResultMap"
>
<select
id=
"selectByExample"
parameterType=
"com.wwdz.ch.db.domain.OfficialAccountSubscribeRecordExample"
resultMap=
"BaseResultMap"
>
select
select
...
@@ -98,13 +99,13 @@
...
@@ -98,13 +99,13 @@
distinct
distinct
</if>
</if>
<choose>
<choose>
<when
test=
"selective != null and selective.length
>
0"
>
<when
test=
"selective != null and selective.length
>
0"
>
<foreach
collection=
"selective"
item=
"column"
separator=
","
>
<foreach
collection=
"selective"
item=
"column"
separator=
","
>
${column.escapedColumnName}
${column.escapedColumnName}
</foreach>
</foreach>
</when>
</when>
<otherwise>
<otherwise>
id, openid, platform_type, phone, create_time, update_time, enabled
id, openid,
unionid,
platform_type, phone, create_time, update_time, enabled
</otherwise>
</otherwise>
</choose>
</choose>
from official_account_subscribe_record
from official_account_subscribe_record
...
@@ -129,13 +130,13 @@
...
@@ -129,13 +130,13 @@
-->
-->
select
select
<choose>
<choose>
<when
test=
"selective != null and selective.length
>
0"
>
<when
test=
"selective != null and selective.length
>
0"
>
<foreach
collection=
"selective"
item=
"column"
separator=
","
>
<foreach
collection=
"selective"
item=
"column"
separator=
","
>
${column.escapedColumnName}
${column.escapedColumnName}
</foreach>
</foreach>
</when>
</when>
<otherwise>
<otherwise>
id, openid, platform_type, phone, create_time, update_time, enabled
id, openid,
unionid,
platform_type, phone, create_time, update_time, enabled
</otherwise>
</otherwise>
</choose>
</choose>
from official_account_subscribe_record
from official_account_subscribe_record
...
@@ -155,12 +156,12 @@
...
@@ -155,12 +156,12 @@
<selectKey
keyProperty=
"id"
order=
"AFTER"
resultType=
"java.lang.Integer"
>
<selectKey
keyProperty=
"id"
order=
"AFTER"
resultType=
"java.lang.Integer"
>
SELECT LAST_INSERT_ID()
SELECT LAST_INSERT_ID()
</selectKey>
</selectKey>
insert into official_account_subscribe_record (openid,
platform_type, phon
e,
insert into official_account_subscribe_record (openid,
unionid, platform_typ
e,
create_time, update_time, enabled
phone, create_time, update_time,
)
enabled
)
values (#{openid,jdbcType=VARCHAR}, #{
platformType,jdbcType=INTEGER}, #{phone,jdbcType=VARCHA
R},
values (#{openid,jdbcType=VARCHAR}, #{
unionid,jdbcType=VARCHAR}, #{platformType,jdbcType=INTEGE
R},
#{
createTime,jdbcType=TIMESTAMP}, #{updateTime,jdbcType=TIMESTAMP}, #{enabled,jdbcType=INTEGER}
#{
phone,jdbcType=VARCHAR}, #{createTime,jdbcType=TIMESTAMP}, #{updateTime,jdbcType=TIMESTAMP},
)
#{enabled,jdbcType=INTEGER}
)
</insert>
</insert>
<insert
id=
"insertSelective"
parameterType=
"com.wwdz.ch.db.domain.OfficialAccountSubscribeRecord"
>
<insert
id=
"insertSelective"
parameterType=
"com.wwdz.ch.db.domain.OfficialAccountSubscribeRecord"
>
<selectKey
keyProperty=
"id"
order=
"AFTER"
resultType=
"java.lang.Integer"
>
<selectKey
keyProperty=
"id"
order=
"AFTER"
resultType=
"java.lang.Integer"
>
...
@@ -171,6 +172,9 @@
...
@@ -171,6 +172,9 @@
<if
test=
"openid != null"
>
<if
test=
"openid != null"
>
openid,
openid,
</if>
</if>
<if
test=
"unionid != null"
>
unionid,
</if>
<if
test=
"platformType != null"
>
<if
test=
"platformType != null"
>
platform_type,
platform_type,
</if>
</if>
...
@@ -191,6 +195,9 @@
...
@@ -191,6 +195,9 @@
<if
test=
"openid != null"
>
<if
test=
"openid != null"
>
#{openid,jdbcType=VARCHAR},
#{openid,jdbcType=VARCHAR},
</if>
</if>
<if
test=
"unionid != null"
>
#{unionid,jdbcType=VARCHAR},
</if>
<if
test=
"platformType != null"
>
<if
test=
"platformType != null"
>
#{platformType,jdbcType=INTEGER},
#{platformType,jdbcType=INTEGER},
</if>
</if>
...
@@ -223,6 +230,9 @@
...
@@ -223,6 +230,9 @@
<if
test=
"record.openid != null"
>
<if
test=
"record.openid != null"
>
openid = #{record.openid,jdbcType=VARCHAR},
openid = #{record.openid,jdbcType=VARCHAR},
</if>
</if>
<if
test=
"record.unionid != null"
>
unionid = #{record.unionid,jdbcType=VARCHAR},
</if>
<if
test=
"record.platformType != null"
>
<if
test=
"record.platformType != null"
>
platform_type = #{record.platformType,jdbcType=INTEGER},
platform_type = #{record.platformType,jdbcType=INTEGER},
</if>
</if>
...
@@ -247,6 +257,7 @@
...
@@ -247,6 +257,7 @@
update official_account_subscribe_record
update official_account_subscribe_record
set id = #{record.id,jdbcType=INTEGER},
set id = #{record.id,jdbcType=INTEGER},
openid = #{record.openid,jdbcType=VARCHAR},
openid = #{record.openid,jdbcType=VARCHAR},
unionid = #{record.unionid,jdbcType=VARCHAR},
platform_type = #{record.platformType,jdbcType=INTEGER},
platform_type = #{record.platformType,jdbcType=INTEGER},
phone = #{record.phone,jdbcType=VARCHAR},
phone = #{record.phone,jdbcType=VARCHAR},
create_time = #{record.createTime,jdbcType=TIMESTAMP},
create_time = #{record.createTime,jdbcType=TIMESTAMP},
...
@@ -262,6 +273,9 @@
...
@@ -262,6 +273,9 @@
<if
test=
"openid != null"
>
<if
test=
"openid != null"
>
openid = #{openid,jdbcType=VARCHAR},
openid = #{openid,jdbcType=VARCHAR},
</if>
</if>
<if
test=
"unionid != null"
>
unionid = #{unionid,jdbcType=VARCHAR},
</if>
<if
test=
"platformType != null"
>
<if
test=
"platformType != null"
>
platform_type = #{platformType,jdbcType=INTEGER},
platform_type = #{platformType,jdbcType=INTEGER},
</if>
</if>
...
@@ -283,6 +297,7 @@
...
@@ -283,6 +297,7 @@
<update
id=
"updateByPrimaryKey"
parameterType=
"com.wwdz.ch.db.domain.OfficialAccountSubscribeRecord"
>
<update
id=
"updateByPrimaryKey"
parameterType=
"com.wwdz.ch.db.domain.OfficialAccountSubscribeRecord"
>
update official_account_subscribe_record
update official_account_subscribe_record
set openid = #{openid,jdbcType=VARCHAR},
set openid = #{openid,jdbcType=VARCHAR},
unionid = #{unionid,jdbcType=VARCHAR},
platform_type = #{platformType,jdbcType=INTEGER},
platform_type = #{platformType,jdbcType=INTEGER},
phone = #{phone,jdbcType=VARCHAR},
phone = #{phone,jdbcType=VARCHAR},
create_time = #{createTime,jdbcType=TIMESTAMP},
create_time = #{createTime,jdbcType=TIMESTAMP},
...
@@ -317,13 +332,13 @@
...
@@ -317,13 +332,13 @@
select
select
'true' as QUERYID,
'true' as QUERYID,
<choose>
<choose>
<when
test=
"selective != null and selective.length
>
0"
>
<when
test=
"selective != null and selective.length
>
0"
>
<foreach
collection=
"selective"
item=
"column"
separator=
","
>
<foreach
collection=
"selective"
item=
"column"
separator=
","
>
${column.escapedColumnName}
${column.escapedColumnName}
</foreach>
</foreach>
</when>
</when>
<otherwise>
<otherwise>
id, openid, platform_type, phone, create_time, update_time, enabled
id, openid,
unionid,
platform_type, phone, create_time, update_time, enabled
</otherwise>
</otherwise>
</choose>
</choose>
from official_account_subscribe_record
from official_account_subscribe_record
...
@@ -335,4 +350,5 @@
...
@@ -335,4 +350,5 @@
</if>
</if>
limit 1
limit 1
</select>
</select>
</mapper>
</mapper>
\ No newline at end of file
ch-wx-api/src/main/java/com/wwdz/ch/wx/api/OfficialAccountApi.java
View file @
2e44f766
...
@@ -28,6 +28,8 @@ public class OfficialAccountApi {
...
@@ -28,6 +28,8 @@ public class OfficialAccountApi {
private
final
static
String
GET_ACCESSTOKEN_URL
=
"https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential"
;
private
final
static
String
GET_ACCESSTOKEN_URL
=
"https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential"
;
private
final
static
String
GET_USER_BASE_INFO_URL
=
"https://api.weixin.qq.com/cgi-bin/user/info?lang=zh_CN"
;
@Autowired
@Autowired
RedisUtils
redisUtils
;
RedisUtils
redisUtils
;
...
@@ -45,7 +47,7 @@ public class OfficialAccountApi {
...
@@ -45,7 +47,7 @@ public class OfficialAccountApi {
OkHttpUtil
okHttpUtil
=
OkHttpUtil
.
builder
().
url
(
url
);
OkHttpUtil
okHttpUtil
=
OkHttpUtil
.
builder
().
url
(
url
);
okHttpUtil
.
get
();
okHttpUtil
.
get
();
String
responseStr
=
okHttpUtil
.
async
();
String
responseStr
=
okHttpUtil
.
async
();
logger
.
info
(
"appid : {}, 获取token response :{}"
,
responseStr
);
logger
.
info
(
"appid : {}, 获取token response :{}"
,
APPID
,
responseStr
);
if
(!
responseStr
.
contains
(
"access_token"
))
{
if
(!
responseStr
.
contains
(
"access_token"
))
{
String
errorCode
=
JsonUtils
.
getValueByPath
(
responseStr
,
"errcode"
);
String
errorCode
=
JsonUtils
.
getValueByPath
(
responseStr
,
"errcode"
);
String
errmsg
=
JsonUtils
.
getValueByPath
(
responseStr
,
"errmsg"
);
String
errmsg
=
JsonUtils
.
getValueByPath
(
responseStr
,
"errmsg"
);
...
@@ -58,4 +60,33 @@ public class OfficialAccountApi {
...
@@ -58,4 +60,33 @@ public class OfficialAccountApi {
return
token
;
return
token
;
}
}
/**
* 返回unionid
* @param openid
* @return
*/
public
String
getUnionidByopenid
(
String
openid
)
{
String
token
=
getAccessToken
();
String
url
=
GET_USER_BASE_INFO_URL
+
"&access_token="
+
token
+
"&openid="
+
openid
;
OkHttpUtil
okHttpUtil
=
OkHttpUtil
.
builder
().
url
(
url
);
okHttpUtil
.
get
();
String
responseStr
=
okHttpUtil
.
async
();
logger
.
info
(
"openid : {}, 获取用户基本信息 response :{}"
,
openid
,
responseStr
);
if
(!
responseStr
.
contains
(
"unionid"
))
{
String
errorCode
=
JsonUtils
.
getValueByPath
(
responseStr
,
"errcode"
);
String
errmsg
=
JsonUtils
.
getValueByPath
(
responseStr
,
"errmsg"
);
//token失效
if
((
"40001"
).
equals
(
errorCode
))
{
refreshAccessToken
();
}
logger
.
error
(
"openid : {}, 获取用户基本信息, errorCode : {}, errmsg : {} "
,
openid
,
errorCode
,
errmsg
);
return
null
;
}
String
unionid
=
JsonUtils
.
getValueByPath
(
responseStr
,
"unionid"
);
logger
.
info
(
"openid : {}, 对应的 unionid:{}"
,
openid
,
unionid
);
return
unionid
;
}
}
}
ch-wx-api/src/main/java/com/wwdz/ch/wx/api/OfficialAccountCallbackController.java
View file @
2e44f766
...
@@ -87,10 +87,13 @@ public class OfficialAccountCallbackController {
...
@@ -87,10 +87,13 @@ public class OfficialAccountCallbackController {
if
(
SUBSCRIBE_EVENT
.
equals
(
event
)
||
UNSUBSCRIBE_EVENT
.
equals
(
event
))
{
if
(
SUBSCRIBE_EVENT
.
equals
(
event
)
||
UNSUBSCRIBE_EVENT
.
equals
(
event
))
{
String
userOpenId
=
contentMap
.
get
(
"FromUserName"
);
String
userOpenId
=
contentMap
.
get
(
"FromUserName"
);
String
createTime
=
contentMap
.
get
(
"CreateTime"
);
String
createTime
=
contentMap
.
get
(
"CreateTime"
);
Date
date
=
new
Date
(
Long
.
valueOf
(
createTime
));
Date
date
=
new
Date
(
Long
.
valueOf
(
createTime
)
*
1000L
);
logger
.
info
(
"解析xml得到 openId:{}, event :{}, time:{}"
,
userOpenId
,
event
,
date
);
logger
.
info
(
"解析xml得到 openId:{}, event :{}, time:{}"
,
userOpenId
,
event
,
date
);
//新增或更新订阅记录
//新增或更新订阅记录
OfficialAccountSubscribeRecord
officialAccountSubscribeRecord
=
new
OfficialAccountSubscribeRecord
();
OfficialAccountSubscribeRecord
officialAccountSubscribeRecord
=
new
OfficialAccountSubscribeRecord
();
//根据openid获取unionid
String
unionid
=
officialAccountApi
.
getUnionidByopenid
(
userOpenId
);
officialAccountSubscribeRecord
.
setUnionid
(
unionid
);
officialAccountSubscribeRecord
.
setOpenid
(
userOpenId
);
officialAccountSubscribeRecord
.
setOpenid
(
userOpenId
);
if
(
SUBSCRIBE_EVENT
.
equals
(
event
))
{
if
(
SUBSCRIBE_EVENT
.
equals
(
event
))
{
officialAccountSubscribeRecord
.
setEnabled
(
1
);
officialAccountSubscribeRecord
.
setEnabled
(
1
);
...
@@ -98,13 +101,13 @@ public class OfficialAccountCallbackController {
...
@@ -98,13 +101,13 @@ public class OfficialAccountCallbackController {
officialAccountSubscribeRecord
.
setEnabled
(
0
);
officialAccountSubscribeRecord
.
setEnabled
(
0
);
}
}
//查询有无历史订阅记录
//查询有无历史订阅记录
boolean
isExisted
=
officialAccountSubscribeRecordService
.
isExisted
(
u
serOpenI
d
);
boolean
isExisted
=
officialAccountSubscribeRecordService
.
isExisted
(
u
nioni
d
);
if
(
isExisted
)
{
if
(
isExisted
)
{
officialAccountSubscribeRecord
.
setUpdateTime
(
date
);
officialAccountSubscribeRecord
.
setUpdateTime
(
date
);
officialAccountSubscribeRecordService
.
update
(
officialAccountSubscribeRecord
);
officialAccountSubscribeRecordService
.
update
(
officialAccountSubscribeRecord
);
}
else
{
}
else
{
//没有历史订阅记录,先根据
ope
nid查询手机号
//没有历史订阅记录,先根据
unio
nid查询手机号
User
user
=
userDao
.
queryByOid
(
u
serOpenI
d
);
User
user
=
userDao
.
queryByOid
(
u
nioni
d
);
if
(
user
!=
null
)
{
if
(
user
!=
null
)
{
officialAccountSubscribeRecord
.
setPhone
(
user
.
getMobile
());
officialAccountSubscribeRecord
.
setPhone
(
user
.
getMobile
());
}
}
...
@@ -113,6 +116,7 @@ public class OfficialAccountCallbackController {
...
@@ -113,6 +116,7 @@ public class OfficialAccountCallbackController {
officialAccountSubscribeRecord
.
setPlatformType
(
OfficalAccountEnum
.
PlatformTypeEnum
.
WECHAT
.
getCode
());
officialAccountSubscribeRecord
.
setPlatformType
(
OfficalAccountEnum
.
PlatformTypeEnum
.
WECHAT
.
getCode
());
officialAccountSubscribeRecordService
.
insert
(
officialAccountSubscribeRecord
);
officialAccountSubscribeRecordService
.
insert
(
officialAccountSubscribeRecord
);
}
}
logger
.
info
(
"=============== 更新订阅记录成功 =============="
);
}
}
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
logger
.
error
(
"微信公众号通知回调接口 error : {}"
,
e
);
logger
.
error
(
"微信公众号通知回调接口 error : {}"
,
e
);
...
@@ -152,7 +156,7 @@ public class OfficialAccountCallbackController {
...
@@ -152,7 +156,7 @@ public class OfficialAccountCallbackController {
if
(
SUBSCRIBE_EVENT
.
equals
(
event
)
||
UNSUBSCRIBE_EVENT
.
equals
(
event
))
{
if
(
SUBSCRIBE_EVENT
.
equals
(
event
)
||
UNSUBSCRIBE_EVENT
.
equals
(
event
))
{
String
userOpenId
=
contentMap
.
get
(
"FromUserName"
);
String
userOpenId
=
contentMap
.
get
(
"FromUserName"
);
String
createTime
=
contentMap
.
get
(
"CreateTime"
);
String
createTime
=
contentMap
.
get
(
"CreateTime"
);
Date
date
=
new
Date
(
Long
.
valueOf
(
createTime
));
Date
date
=
new
Date
(
Long
.
valueOf
(
createTime
)
*
1000L
);
System
.
out
.
println
(
userOpenId
+
">>"
+
event
+
">>"
+
date
);
System
.
out
.
println
(
userOpenId
+
">>"
+
event
+
">>"
+
date
);
}
}
}
}
...
...
ch-wx-api/src/main/java/com/wwdz/ch/wx/manager/WxLoginManager.java
View file @
2e44f766
...
@@ -44,7 +44,7 @@ public class WxLoginManager {
...
@@ -44,7 +44,7 @@ public class WxLoginManager {
/**
/**
* 获取微信openid
* 获取微信openid
*
*
为了公众号发送消息,这里实际获取的是unionid,同一用户小程序和公众号unionid相同
* @param loginCode
* @param loginCode
* @return
* @return
*/
*/
...
@@ -53,7 +53,9 @@ public class WxLoginManager {
...
@@ -53,7 +53,9 @@ public class WxLoginManager {
String
openId
=
""
;
String
openId
=
""
;
try
{
try
{
WxMaJscode2SessionResult
result
=
this
.
wxMaService
.
getUserService
().
getSessionInfo
(
loginCode
);
WxMaJscode2SessionResult
result
=
this
.
wxMaService
.
getUserService
().
getSessionInfo
(
loginCode
);
openId
=
result
.
getOpenid
();
//实际获取的是unionid,为了和公众号订阅用户关联
openId
=
result
.
getUnionid
();
logger
.
info
(
"获取WxMaJscode2SessionResult :{}"
,
result
);
logger
.
info
(
"loginCode:{},获取openId成功 openId :{}"
,
loginCode
,
openId
);
logger
.
info
(
"loginCode:{},获取openId成功 openId :{}"
,
loginCode
,
openId
);
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
logger
.
error
(
"loginCode:{}, 获取微信登录用户的openId失败:{}"
,
loginCode
,
e
);
logger
.
error
(
"loginCode:{}, 获取微信登录用户的openId失败:{}"
,
loginCode
,
e
);
...
...
ch-wx-api/src/test/java/com/wwdz/ch/wx/api/OfficialAccountApiTest.java
View file @
2e44f766
...
@@ -19,4 +19,11 @@ public class OfficialAccountApiTest {
...
@@ -19,4 +19,11 @@ public class OfficialAccountApiTest {
public
void
refreshAccessToken
()
{
public
void
refreshAccessToken
()
{
officialAccountApi
.
getAccessToken
();
officialAccountApi
.
getAccessToken
();
}
}
@Test
public
void
getUserBaseInfo
()
{
String
openid
=
"oNPTN6QaVliZfKB53OzZRPBZr_r8"
;
officialAccountApi
.
getUnionidByopenid
(
openid
);
}
}
}
\ No newline at end of file
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