Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
提交反馈
为 GitLab 提交贡献
登录
切换导航
P
pica-cloud-yunqueyilian
项目
项目
详情
动态
版本
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
收起侧边栏
Close sidebar
动态
分支图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
com.pica.cloud.wechat
pica-cloud-yunqueyilian
提交
cb6342c6
提交
cb6342c6
编写于
8月 09, 2018
作者:
chenzhehao
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
增加公众号验证、事件信息处理
上级
62f6017e
变更
17
隐藏空白字符变更
内嵌
并排
正在显示
17 个修改的文件
包含
1056 行增加
和
21 行删除
+1056
-21
.gitignore
.gitignore
+1
-1
pom.xml
common/pom.xml
+13
-0
App.java
...n/java/com/pica/cloud/wechat/yunqueyilian.common/App.java
+0
-8
CommonUtils.java
...om/pica/cloud/wechat/yunqueyilian/common/CommonUtils.java
+155
-0
Constants.java
.../com/pica/cloud/wechat/yunqueyilian/common/Constants.java
+53
-0
BaseMessage.java
...ica/cloud/wechat/yunqueyilian/common/req/BaseMessage.java
+54
-0
TextMessage.java
...ica/cloud/wechat/yunqueyilian/common/req/TextMessage.java
+20
-0
HttpClientUtil.java
...cloud/wechat/yunqueyilian/common/util/HttpClientUtil.java
+241
-0
pom.xml
pom.xml
+16
-6
pom.xml
server/pom.xml
+6
-6
IUserServiceClient.java
...wechat/yunqueyilian/server/client/IUserServiceClient.java
+22
-0
CoreController.java
...wechat/yunqueyilian/server/controller/CoreController.java
+44
-0
PWechatUser.java
.../cloud/wechat/yunqueyilian/server/entity/PWechatUser.java
+235
-0
PWechatUserMapper.java
.../wechat/yunqueyilian/server/mapper/PWechatUserMapper.java
+10
-0
CoreService.java
...cloud/wechat/yunqueyilian/server/service/CoreService.java
+17
-0
CoreServiceImpl.java
...hat/yunqueyilian/server/service/impl/CoreServiceImpl.java
+128
-0
PWechatUserMapper.xml
server/src/main/resources/mybatis/PWechatUserMapper.xml
+41
-0
未找到文件。
.gitignore
浏览文件 @
cb6342c6
...
@@ -56,7 +56,7 @@ buildNumber.properties
...
@@ -56,7 +56,7 @@ buildNumber.properties
*.ipr
*.ipr
*.bak
*.bak
/server/src/main/resources/mybatis-generator.xml
# IntelliJ
# IntelliJ
/out/
/out/
...
...
common/pom.xml
浏览文件 @
cb6342c6
...
@@ -21,6 +21,19 @@
...
@@ -21,6 +21,19 @@
<java.version>
1.8
</java.version>
<java.version>
1.8
</java.version>
</properties>
</properties>
<dependencies>
<dependency>
<groupId>
dom4j
</groupId>
<artifactId>
dom4j
</artifactId>
<version>
1.6.1
</version>
</dependency>
<dependency>
<groupId>
com.thoughtworks.xstream
</groupId>
<artifactId>
xstream
</artifactId>
<version>
1.3.1
</version>
</dependency>
</dependencies>
<distributionManagement>
<distributionManagement>
<repository>
<repository>
<id>
nexus
</id>
<id>
nexus
</id>
...
...
common/src/main/java/com/pica/cloud/wechat/yunqueyilian.common/App.java
已删除
100644 → 0
浏览文件 @
62f6017e
package
com
.
pica
.
cloud
.
wechat
.
common
;
public
class
App
{
public
static
void
main
(
String
[]
args
)
{
}
}
common/src/main/java/com/pica/cloud/wechat/yunqueyilian/common/CommonUtils.java
0 → 100644
浏览文件 @
cb6342c6
package
com
.
pica
.
cloud
.
wechat
.
yunqueyilian
.
common
;
import
com.pica.cloud.wechat.yunqueyilian.common.req.TextMessage
;
import
com.thoughtworks.xstream.XStream
;
import
com.thoughtworks.xstream.core.util.QuickWriter
;
import
com.thoughtworks.xstream.io.HierarchicalStreamWriter
;
import
com.thoughtworks.xstream.io.xml.PrettyPrintWriter
;
import
com.thoughtworks.xstream.io.xml.XppDriver
;
import
org.dom4j.Document
;
import
org.dom4j.Element
;
import
org.dom4j.io.SAXReader
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
javax.servlet.http.HttpServletRequest
;
import
java.io.InputStream
;
import
java.io.Writer
;
import
java.security.MessageDigest
;
import
java.security.NoSuchAlgorithmException
;
import
java.util.Arrays
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
/**
* @Auther wangyongbo
* @Date 2018/6/8 下午7:10
*/
public
class
CommonUtils
{
private
static
Logger
logger
=
LoggerFactory
.
getLogger
(
CommonUtils
.
class
);
/**
* 验证签名
*
* @param signature
* @param timestamp
* @param nonce
* @return
*/
public
static
boolean
checkSignature
(
String
signature
,
String
timestamp
,
String
nonce
)
{
String
[]
arr
=
new
String
[]
{
Constants
.
WECHAT_YQYL_TOKEN
,
timestamp
,
nonce
};
// 将token、timestamp、nonce三个参数进行字典序排序
Arrays
.
sort
(
arr
);
StringBuilder
content
=
new
StringBuilder
();
for
(
int
i
=
0
;
i
<
arr
.
length
;
i
++)
{
content
.
append
(
arr
[
i
]);
}
MessageDigest
md
=
null
;
String
tmpStr
=
null
;
try
{
md
=
MessageDigest
.
getInstance
(
"SHA-1"
);
// 将三个参数字符串拼接成一个字符串进行sha1加密
byte
[]
digest
=
md
.
digest
(
content
.
toString
().
getBytes
());
tmpStr
=
byteToStr
(
digest
);
}
catch
(
NoSuchAlgorithmException
e
)
{
logger
.
error
(
"异常抛出exception "
,
e
);
}
content
=
null
;
// 将sha1加密后的字符串可与signature对比,标识该请求来源于微信
return
tmpStr
!=
null
?
tmpStr
.
toUpperCase
().
equals
(
signature
.
toUpperCase
())
:
false
;
}
/**
* 将字节数组转换为十六进制字符串
*
* @param byteArray
* @return
*/
private
static
String
byteToStr
(
byte
[]
byteArray
)
{
String
strDigest
=
""
;
for
(
int
i
=
0
;
i
<
byteArray
.
length
;
i
++)
{
strDigest
+=
byteToHexStr
(
byteArray
[
i
]);
}
return
strDigest
;
}
/**
* 将字节转换为十六进制字符串
*
* @param mByte
* @return
*/
private
static
String
byteToHexStr
(
byte
mByte
)
{
char
[]
Digit
=
{
'0'
,
'1'
,
'2'
,
'3'
,
'4'
,
'5'
,
'6'
,
'7'
,
'8'
,
'9'
,
'A'
,
'B'
,
'C'
,
'D'
,
'E'
,
'F'
};
char
[]
tempArr
=
new
char
[
2
];
tempArr
[
0
]
=
Digit
[(
mByte
>>>
4
)
&
0X0F
];
tempArr
[
1
]
=
Digit
[
mByte
&
0X0F
];
String
s
=
new
String
(
tempArr
);
return
s
;
}
/**
* 解析微信发来的请求(XML)
*
* @param request
* @return
* @throws Exception
*/
public
static
Map
<
String
,
String
>
parseXml
(
HttpServletRequest
request
)
throws
Exception
{
// 将解析结果存储在HashMap中
Map
<
String
,
String
>
map
=
new
HashMap
<
String
,
String
>();
// 从request中取得输入流
InputStream
inputStream
=
request
.
getInputStream
();
// 读取输入流
SAXReader
reader
=
new
SAXReader
();
Document
document
=
reader
.
read
(
inputStream
);
// 得到xml根元素
Element
root
=
document
.
getRootElement
();
// 得到根元素的所有子节点
List
<
Element
>
elementList
=
root
.
elements
();
// 遍历所有子节点
for
(
Element
e
:
elementList
)
map
.
put
(
e
.
getName
(),
e
.
getText
());
// 释放资源
inputStream
.
close
();
inputStream
=
null
;
return
map
;
}
/**
* 扩展xstream,使其支持CDATA块
*
* @date 2014-12-03
*/
private
static
XStream
xstream
=
new
XStream
(
new
XppDriver
()
{
public
HierarchicalStreamWriter
createWriter
(
Writer
out
)
{
return
new
PrettyPrintWriter
(
out
)
{
// 对所有xml节点的转换都增加CDATA标记
boolean
cdata
=
true
;
protected
void
writeText
(
QuickWriter
writer
,
String
text
)
{
if
(
cdata
)
{
writer
.
write
(
"<![CDATA["
);
writer
.
write
(
text
);
writer
.
write
(
"]]>"
);
}
else
{
writer
.
write
(
text
);
}
}
};
}
});
/**
* 文本消息对象转换成xml
*
* @param textMessage 文本消息对象
* @return xml
*/
public
static
String
textMessageToXml
(
TextMessage
textMessage
)
{
xstream
.
alias
(
"xml"
,
textMessage
.
getClass
());
return
xstream
.
toXML
(
textMessage
);
}
}
common/src/main/java/com/pica/cloud/wechat/yunqueyilian/common/Constants.java
0 → 100644
浏览文件 @
cb6342c6
package
com
.
pica
.
cloud
.
wechat
.
yunqueyilian
.
common
;
/**
//考试相关常量
//@author andong
//@create 2018/7/4
*/
@SuppressWarnings
(
"unused"
)
public
class
Constants
{
// 与接口配置信息中的Token要一致
public
static
String
WECHAT_YQYL_TOKEN
=
"tokenPicaHealth"
;
//微信公众号简称
public
static
String
WECHAT_NAME_YQYL
=
"YQYL"
;
//返回消息类型:文本
public
static
final
String
RESP_MESSAGE_TYPE_TEXT
=
"text"
;
//返回消息类型:音乐
public
static
final
String
RESP_MESSAGE_TYPE_MUSIC
=
"music"
;
//返回消息类型:图文
public
static
final
String
RESP_MESSAGE_TYPE_NEWS
=
"news"
;
//请求消息类型:文本
public
static
final
String
REQ_MESSAGE_TYPE_TEXT
=
"text"
;
//请求消息类型:图片
public
static
final
String
REQ_MESSAGE_TYPE_IMAGE
=
"image"
;
//请求消息类型:链接
public
static
final
String
REQ_MESSAGE_TYPE_LINK
=
"link"
;
//请求消息类型:地理位置
public
static
final
String
REQ_MESSAGE_TYPE_LOCATION
=
"location"
;
//请求消息类型:音频
public
static
final
String
REQ_MESSAGE_TYPE_VOICE
=
"voice"
;
//请求消息类型:推送
public
static
final
String
REQ_MESSAGE_TYPE_EVENT
=
"event"
;
//事件类型:subscribe(订阅)
public
static
final
String
EVENT_TYPE_SUBSCRIBE
=
"subscribe"
;
//事件类型:unsubscribe(取消订阅)
public
static
final
String
EVENT_TYPE_UNSUBSCRIBE
=
"unsubscribe"
;
//事件类型:CLICK(自定义菜单点击事件)
public
static
final
String
EVENT_TYPE_CLICK
=
"CLICK"
;
//事件类型:VIEW(自定义菜单点击事件)
public
static
final
String
EVENT_TYPE_VIEW
=
"VIEW"
;
//事件类型:LOCATION(自定义菜单点击事件)
public
static
final
String
EVENT_TYPE_LOCATION
=
"LOCATION"
;
//事件类型:LOCATION_SELECT(自定义菜单点击事件)
public
static
final
String
EVENT_TYPE_LOCATION_SELECT
=
"LOCATION_SELECT"
;
//事件类型:SCAN(扫描二维码事件)
public
static
final
String
EVENT_TYPE_SCAN
=
"SCAN"
;
}
common/src/main/java/com/pica/cloud/wechat/yunqueyilian/common/req/BaseMessage.java
0 → 100644
浏览文件 @
cb6342c6
package
com
.
pica
.
cloud
.
wechat
.
yunqueyilian
.
common
.
req
;
/**
* 消息基类(公众帐号 -> 普通用户)
*
* @author bo.dang
* @date 2014-12-03
*/
public
class
BaseMessage
{
// 接收方帐号(收到的OpenID)
private
String
ToUserName
;
// 开发者微信号
private
String
FromUserName
;
// 消息创建时间 (整型)
private
long
CreateTime
;
// 消息类型(text/music/news)
private
String
MsgType
;
// 位0x0001被标志时,星标刚收到的消息
//private int FuncFlag;
public
String
getToUserName
()
{
return
ToUserName
;
}
public
void
setToUserName
(
String
toUserName
)
{
ToUserName
=
toUserName
;
}
public
String
getFromUserName
()
{
return
FromUserName
;
}
public
void
setFromUserName
(
String
fromUserName
)
{
FromUserName
=
fromUserName
;
}
public
long
getCreateTime
()
{
return
CreateTime
;
}
public
void
setCreateTime
(
long
createTime
)
{
CreateTime
=
createTime
;
}
public
String
getMsgType
()
{
return
MsgType
;
}
public
void
setMsgType
(
String
msgType
)
{
MsgType
=
msgType
;
}
}
common/src/main/java/com/pica/cloud/wechat/yunqueyilian/common/req/TextMessage.java
0 → 100644
浏览文件 @
cb6342c6
package
com
.
pica
.
cloud
.
wechat
.
yunqueyilian
.
common
.
req
;
/**
* 文本消息
*
* @author bo.dang
* @date 2014-12-03
*/
public
class
TextMessage
extends
BaseMessage
{
// 回复的消息内容
private
String
Content
;
public
String
getContent
()
{
return
Content
;
}
public
void
setContent
(
String
content
)
{
Content
=
content
;
}
}
\ No newline at end of file
common/src/main/java/com/pica/cloud/wechat/yunqueyilian/common/util/HttpClientUtil.java
0 → 100644
浏览文件 @
cb6342c6
package
com
.
pica
.
cloud
.
wechat
.
yunqueyilian
.
common
.
util
;
import
com.alibaba.fastjson.JSON
;
import
net.sf.json.JSONObject
;
import
org.apache.http.HttpEntity
;
import
org.apache.http.HttpStatus
;
import
org.apache.http.client.methods.CloseableHttpResponse
;
import
org.apache.http.client.methods.HttpPost
;
import
org.apache.http.entity.ContentType
;
import
org.apache.http.entity.StringEntity
;
import
org.apache.http.impl.client.CloseableHttpClient
;
import
org.apache.http.impl.client.HttpClients
;
import
org.apache.http.impl.conn.PoolingHttpClientConnectionManager
;
import
org.apache.http.util.EntityUtils
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
java.io.*
;
import
java.net.ConnectException
;
import
java.net.HttpURLConnection
;
import
java.net.URL
;
import
java.util.Map
;
/**
* @ClassName:HttpclientUtil.java
* @Description: Httpclient处理类
* @author bo.dang
* @date 2016年1月26日 下午2:45:52
* @version V1.0
*/
public
class
HttpClientUtil
{
private
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(
HttpClientUtil
.
class
);
private
static
final
CloseableHttpClient
hc
;
static
{
PoolingHttpClientConnectionManager
cm
=
new
PoolingHttpClientConnectionManager
();
cm
.
setDefaultMaxPerRoute
(
20
);
cm
.
setMaxTotal
(
200
);
hc
=
HttpClients
.
custom
().
setConnectionManager
(
cm
).
build
();
}
public
static
int
postForm
(
String
url
,
Map
<
String
,
String
>
params
,
HttpEntity
entity
)
throws
IOException
{
HttpPost
post
=
new
HttpPost
(
url
);
for
(
Map
.
Entry
<
String
,
String
>
param
:
params
.
entrySet
())
{
post
.
setHeader
(
param
.
getKey
(),
param
.
getValue
());
}
post
.
setEntity
(
entity
);
CloseableHttpResponse
resp
=
null
;
try
{
resp
=
hc
.
execute
(
post
);
return
resp
.
getStatusLine
().
getStatusCode
();
}
catch
(
Exception
e
){
logger
.
error
(
"异常抛出exception "
,
e
);
}
finally
{
if
(
resp
!=
null
)
{
try
{
resp
.
close
();
}
catch
(
IOException
e1
)
{
logger
.
error
(
"异常抛出exception "
,
e1
);
}
}
}
return
0
;
}
public
static
String
httpExecute
(
String
url
,
String
data
){
String
result
=
""
;
CloseableHttpClient
httpClient
=
null
;
CloseableHttpResponse
response
=
null
;
try
{
httpClient
=
HttpClients
.
createDefault
();
HttpPost
postRequest
=
new
HttpPost
(
url
);
postRequest
.
setHeader
(
"Content-Type"
,
"application/json;charset=utf-8"
);
postRequest
.
setHeader
(
"Accept"
,
"application/json"
);
//StringEntity input = new StringEntity("{\"token\":\"08b7377d22a88a8951e66ce97f4a06f6\"}");
StringEntity
input
=
new
StringEntity
(
data
,
ContentType
.
APPLICATION_JSON
);
logger
.
info
(
"data:"
+
data
);
postRequest
.
setEntity
(
input
);
response
=
httpClient
.
execute
(
postRequest
);
if
(
response
.
getStatusLine
().
getStatusCode
()
!=
201
)
{
int
statusCode
=
response
.
getStatusLine
().
getStatusCode
();
if
(
statusCode
==
HttpStatus
.
SC_OK
)
{
result
=
EntityUtils
.
toString
(
response
.
getEntity
(),
"utf-8"
);
}
else
{
logger
.
warn
(
"调用失败,param:{}, result:{}"
,
JSON
.
toJSONString
(
data
),
JSON
.
toJSONString
(
response
));
}
}
logger
.
info
(
"response:"
+
response
);
}
catch
(
Exception
e
)
{
logger
.
error
(
"获取session出错:"
+
e
);
}
finally
{
try
{
if
(
response
!=
null
)
{
response
.
close
();
}
}
catch
(
Exception
e
){
logger
.
warn
(
"CloseableHttpResponse关闭异常"
);
}
}
return
result
;
}
public
static
String
httpExecute
(
String
url
,
String
data
,
Map
map
){
String
result
=
""
;
CloseableHttpClient
httpClient
=
null
;
CloseableHttpResponse
response
=
null
;
try
{
httpClient
=
HttpClients
.
createDefault
();
HttpPost
postRequest
=
new
HttpPost
(
url
);
postRequest
.
setHeader
(
"Content-Type"
,
"application/json;charset=utf-8"
);
postRequest
.
setHeader
(
"Accept"
,
"application/json"
);
StringEntity
input
=
new
StringEntity
(
data
,
ContentType
.
APPLICATION_JSON
);
logger
.
warn
(
"{}-{} data:{}"
,
map
.
get
(
"module"
),
map
.
get
(
"type"
),
data
);
postRequest
.
setEntity
(
input
);
response
=
httpClient
.
execute
(
postRequest
);
if
(
response
.
getStatusLine
().
getStatusCode
()
!=
201
)
{
int
statusCode
=
response
.
getStatusLine
().
getStatusCode
();
if
(
statusCode
==
HttpStatus
.
SC_OK
)
{
result
=
EntityUtils
.
toString
(
response
.
getEntity
(),
"utf-8"
);
}
else
{
logger
.
warn
(
"{}-{} 调用失败,param:{}, result:{}"
,
map
.
get
(
"module"
),
map
.
get
(
"type"
),
JSON
.
toJSONString
(
data
),
JSON
.
toJSONString
(
response
));
}
}
logger
.
warn
(
"{}-{} response:{}"
,
map
.
get
(
"module"
),
map
.
get
(
"type"
),
JSON
.
toJSONString
(
response
));
}
catch
(
Exception
e
)
{
logger
.
error
(
"{}-{} 获取session出错:"
,
map
.
get
(
"module"
),
map
.
get
(
"type"
),
e
);
}
finally
{
try
{
if
(
response
!=
null
)
{
response
.
close
();
}
}
catch
(
Exception
e
){
logger
.
warn
(
"{}-{} CloseableHttpResponse关闭异常"
,
map
.
get
(
"module"
),
map
.
get
(
"type"
),
e
);
}
}
return
result
;
}
/**
* 发起http请求并获取结果
*
* @param requestUrl 请求地址
* @param requestMethod 请求方式(GET、POST)
* @param outputStr 提交的数据
* @return JSONObject(通过JSONObject.get(key)的方式获取json对象的属性值)
*/
public
static
JSONObject
httpRequest
(
String
requestUrl
,
String
requestMethod
,
String
outputStr
)
{
JSONObject
jsonObject
=
null
;
StringBuffer
buffer
=
new
StringBuffer
();
HttpURLConnection
httpUrlConn
=
null
;
BufferedReader
bufferedReader
=
null
;
InputStream
inputStream
=
null
;
InputStreamReader
inputStreamReader
=
null
;
try
{
URL
url
=
new
URL
(
requestUrl
);
httpUrlConn
=
(
HttpURLConnection
)
url
.
openConnection
();
httpUrlConn
.
setDoOutput
(
true
);
httpUrlConn
.
setDoInput
(
true
);
httpUrlConn
.
setUseCaches
(
false
);
// 设置请求方式(GET/POST)
httpUrlConn
.
setRequestMethod
(
requestMethod
);
if
(
"GET"
.
equalsIgnoreCase
(
requestMethod
))
{
httpUrlConn
.
connect
();
}
// 当有数据需要提交时
if
(
null
!=
outputStr
)
{
OutputStream
outputStream
=
httpUrlConn
.
getOutputStream
();
// 注意编码格式,防止中文乱码
outputStream
.
write
(
outputStr
.
getBytes
(
"UTF-8"
));
outputStream
.
close
();
}
// 将返回的输入流转换成字符串
inputStream
=
httpUrlConn
.
getInputStream
();
inputStreamReader
=
new
InputStreamReader
(
inputStream
,
"utf-8"
);
bufferedReader
=
new
BufferedReader
(
inputStreamReader
);
String
str
=
null
;
while
((
str
=
bufferedReader
.
readLine
())
!=
null
)
{
buffer
.
append
(
str
);
}
logger
.
info
(
buffer
.
toString
());
jsonObject
=
JSONObject
.
fromObject
(
buffer
.
toString
());
}
catch
(
ConnectException
ce
)
{
logger
.
error
(
"Weixin server connection timed out."
);
}
catch
(
Exception
e
)
{
logger
.
error
(
"https request error:{}"
,
e
);
}
finally
{
try
{
if
(
bufferedReader
!=
null
){
bufferedReader
.
close
();
}
if
(
inputStreamReader
!=
null
)
{
inputStreamReader
.
close
();
}
if
(
inputStream
!=
null
)
{
inputStream
.
close
();
}
if
(
httpUrlConn
!=
null
)
{
httpUrlConn
.
disconnect
();
}
}
catch
(
Exception
e
){
logger
.
warn
(
"httpUrlConn关闭异常"
);
}
}
return
jsonObject
;
}
}
pom.xml
浏览文件 @
cb6342c6
<?xml version="1.0" encoding="UTF-8"?>
<?xml version="1.0" encoding="UTF-8"?>
<project
xmlns=
"http://maven.apache.org/POM/4.0.0"
xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=
"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
>
<project
xmlns=
"http://maven.apache.org/POM/4.0.0"
xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=
"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
>
<modelVersion>
4.0.0
</modelVersion>
<modelVersion>
4.0.0
</modelVersion>
<groupId>
com.pica.cloud.wechat
</groupId>
<groupId>
com.pica.cloud.wechat
</groupId>
...
@@ -24,9 +25,18 @@
...
@@ -24,9 +25,18 @@
</plugins>
</plugins>
</build>
</build>
<modules>
<dependencies>
<module>
server
</module>
<dependency>
<module>
common
</module>
<groupId>
com.pica.cloud.foundation
</groupId>
<module>
client
</module>
<artifactId>
pica-cloud-utils
</artifactId>
</modules>
<version>
1.0.7-SNAPSHOT
</version>
<scope>
compile
</scope>
</dependency>
</dependencies>
<modules>
<module>
server
</module>
<module>
common
</module>
<module>
client
</module>
</modules>
</project>
</project>
\ No newline at end of file
server/pom.xml
浏览文件 @
cb6342c6
...
@@ -25,6 +25,12 @@
...
@@ -25,6 +25,12 @@
</properties>
</properties>
<dependencies>
<dependencies>
<dependency>
<groupId>
com.pica.cloud.wechat
</groupId>
<artifactId>
pica-cloud-yunqueyilian-common
</artifactId>
<version>
1.0.0
</version>
<scope>
compile
</scope>
</dependency>
<dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-actuator
</artifactId>
<artifactId>
spring-boot-starter-actuator
</artifactId>
...
@@ -96,12 +102,6 @@
...
@@ -96,12 +102,6 @@
<version>
1.1.2
</version>
<version>
1.1.2
</version>
</dependency>
</dependency>
<dependency>
<groupId>
com.pica.cloud.foundation
</groupId>
<artifactId>
pica-cloud-utils
</artifactId>
<version>
1.0.7-SNAPSHOT
</version>
</dependency>
<dependency>
<dependency>
<groupId>
com.zaxxer
</groupId>
<groupId>
com.zaxxer
</groupId>
<artifactId>
HikariCP
</artifactId>
<artifactId>
HikariCP
</artifactId>
...
...
server/src/main/java/com/pica/cloud/wechat/yunqueyilian/server/client/IUserServiceClient.java
0 → 100644
浏览文件 @
cb6342c6
package
com
.
pica
.
cloud
.
wechat
.
yunqueyilian
.
server
.
client
;
import
org.springframework.cloud.netflix.feign.FeignClient
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestMethod
;
import
org.springframework.web.bind.annotation.RequestParam
;
import
java.util.Map
;
/**
* @author: zhehao.chen
* @version: V1.0
* @Description:
* @date: 2018/8/9 13:15
*/
@FeignClient
(
"10102-PICA-CLOUD-WECHAT"
)
@RequestMapping
(
"/wechats"
)
public
interface
IUserServiceClient
{
@RequestMapping
(
method
=
RequestMethod
.
GET
,
value
=
"/users"
)
Map
users
(
@RequestParam
(
value
=
"wechatName"
)
String
wechatName
,
@RequestParam
(
value
=
"openId"
)
String
openId
);
}
server/src/main/java/com/pica/cloud/wechat/yunqueyilian/server/controller/CoreController.java
0 → 100644
浏览文件 @
cb6342c6
package
com
.
pica
.
cloud
.
wechat
.
yunqueyilian
.
server
.
controller
;
import
com.pica.cloud.foundation.utils.controller.BaseController
;
import
com.pica.cloud.wechat.yunqueyilian.server.service.CoreService
;
import
io.swagger.annotations.ApiOperation
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestMethod
;
import
org.springframework.web.bind.annotation.RestController
;
import
javax.servlet.http.HttpServletRequest
;
/**
* @author: zhehao.chen
* @version: V1.0
* @Description:
* @date: 2018/8/9 10:08
*/
@RestController
@RequestMapping
(
"/core"
)
public
class
CoreController
extends
BaseController
{
private
static
Logger
logger
=
LoggerFactory
.
getLogger
(
CoreController
.
class
);
@Autowired
private
CoreService
coreService
;
@ApiOperation
(
value
=
"微信验证接口"
,
response
=
String
.
class
)
@RequestMapping
(
method
=
RequestMethod
.
GET
,
produces
=
"text/xml;charset=UTF-8"
)
// @RequestMapping
public
String
check
(
final
HttpServletRequest
request
)
throws
Exception
{
// 创建一个ResponseBuilder
return
coreService
.
requestCheck
(
request
);
// 返回Response
}
@ApiOperation
(
value
=
"微信推送事件接口"
,
response
=
String
.
class
)
@RequestMapping
(
method
=
RequestMethod
.
POST
,
produces
=
"text/xml;charset=UTF-8"
)
// @RequestMapping
public
String
msg
(
final
HttpServletRequest
request
)
throws
Exception
{
// 创建一个ResponseBuilder
return
coreService
.
processRequest
(
request
);
// 返回Response
}
}
server/src/main/java/com/pica/cloud/wechat/yunqueyilian/server/entity/PWechatUser.java
0 → 100644
浏览文件 @
cb6342c6
package
com
.
pica
.
cloud
.
wechat
.
yunqueyilian
.
server
.
entity
;
import
java.util.Date
;
public
class
PWechatUser
{
private
Integer
id
;
private
String
openid
;
private
Integer
patientId
;
private
Integer
type
;
private
Integer
sex
;
private
String
nickname
;
private
String
province
;
private
String
city
;
private
String
country
;
private
String
headimgurl
;
private
String
privilege
;
private
String
unionid
;
private
Integer
subscribe
;
private
String
language
;
private
Date
subscribeTime
;
private
String
remark
;
private
String
groupid
;
private
String
tagidList
;
private
Integer
deleteFlag
;
private
Integer
creatId
;
private
Date
creatTime
;
private
Integer
modifyId
;
private
Date
modifyTime
;
public
Integer
getId
()
{
return
id
;
}
public
void
setId
(
Integer
id
)
{
this
.
id
=
id
;
}
public
String
getOpenid
()
{
return
openid
;
}
public
void
setOpenid
(
String
openid
)
{
this
.
openid
=
openid
==
null
?
null
:
openid
.
trim
();
}
public
Integer
getPatientId
()
{
return
patientId
;
}
public
void
setPatientId
(
Integer
patientId
)
{
this
.
patientId
=
patientId
;
}
public
Integer
getType
()
{
return
type
;
}
public
void
setType
(
Integer
type
)
{
this
.
type
=
type
;
}
public
Integer
getSex
()
{
return
sex
;
}
public
void
setSex
(
Integer
sex
)
{
this
.
sex
=
sex
;
}
public
String
getNickname
()
{
return
nickname
;
}
public
void
setNickname
(
String
nickname
)
{
this
.
nickname
=
nickname
==
null
?
null
:
nickname
.
trim
();
}
public
String
getProvince
()
{
return
province
;
}
public
void
setProvince
(
String
province
)
{
this
.
province
=
province
==
null
?
null
:
province
.
trim
();
}
public
String
getCity
()
{
return
city
;
}
public
void
setCity
(
String
city
)
{
this
.
city
=
city
==
null
?
null
:
city
.
trim
();
}
public
String
getCountry
()
{
return
country
;
}
public
void
setCountry
(
String
country
)
{
this
.
country
=
country
==
null
?
null
:
country
.
trim
();
}
public
String
getHeadimgurl
()
{
return
headimgurl
;
}
public
void
setHeadimgurl
(
String
headimgurl
)
{
this
.
headimgurl
=
headimgurl
==
null
?
null
:
headimgurl
.
trim
();
}
public
String
getPrivilege
()
{
return
privilege
;
}
public
void
setPrivilege
(
String
privilege
)
{
this
.
privilege
=
privilege
==
null
?
null
:
privilege
.
trim
();
}
public
String
getUnionid
()
{
return
unionid
;
}
public
void
setUnionid
(
String
unionid
)
{
this
.
unionid
=
unionid
==
null
?
null
:
unionid
.
trim
();
}
public
Integer
getSubscribe
()
{
return
subscribe
;
}
public
void
setSubscribe
(
Integer
subscribe
)
{
this
.
subscribe
=
subscribe
;
}
public
String
getLanguage
()
{
return
language
;
}
public
void
setLanguage
(
String
language
)
{
this
.
language
=
language
==
null
?
null
:
language
.
trim
();
}
public
Date
getSubscribeTime
()
{
return
subscribeTime
;
}
public
void
setSubscribeTime
(
Date
subscribeTime
)
{
this
.
subscribeTime
=
subscribeTime
;
}
public
String
getRemark
()
{
return
remark
;
}
public
void
setRemark
(
String
remark
)
{
this
.
remark
=
remark
==
null
?
null
:
remark
.
trim
();
}
public
String
getGroupid
()
{
return
groupid
;
}
public
void
setGroupid
(
String
groupid
)
{
this
.
groupid
=
groupid
==
null
?
null
:
groupid
.
trim
();
}
public
String
getTagidList
()
{
return
tagidList
;
}
public
void
setTagidList
(
String
tagidList
)
{
this
.
tagidList
=
tagidList
==
null
?
null
:
tagidList
.
trim
();
}
public
Integer
getDeleteFlag
()
{
return
deleteFlag
;
}
public
void
setDeleteFlag
(
Integer
deleteFlag
)
{
this
.
deleteFlag
=
deleteFlag
;
}
public
Integer
getCreatId
()
{
return
creatId
;
}
public
void
setCreatId
(
Integer
creatId
)
{
this
.
creatId
=
creatId
;
}
public
Date
getCreatTime
()
{
return
creatTime
;
}
public
void
setCreatTime
(
Date
creatTime
)
{
this
.
creatTime
=
creatTime
;
}
public
Integer
getModifyId
()
{
return
modifyId
;
}
public
void
setModifyId
(
Integer
modifyId
)
{
this
.
modifyId
=
modifyId
;
}
public
Date
getModifyTime
()
{
return
modifyTime
;
}
public
void
setModifyTime
(
Date
modifyTime
)
{
this
.
modifyTime
=
modifyTime
;
}
}
\ No newline at end of file
server/src/main/java/com/pica/cloud/wechat/yunqueyilian/server/mapper/PWechatUserMapper.java
0 → 100644
浏览文件 @
cb6342c6
package
com
.
pica
.
cloud
.
wechat
.
yunqueyilian
.
server
.
mapper
;
import
com.pica.cloud.wechat.yunqueyilian.server.entity.PWechatUser
;
import
java.util.Map
;
public
interface
PWechatUserMapper
{
PWechatUser
queryByOpenId
(
Map
map
);
}
\ No newline at end of file
server/src/main/java/com/pica/cloud/wechat/yunqueyilian/server/service/CoreService.java
0 → 100644
浏览文件 @
cb6342c6
package
com
.
pica
.
cloud
.
wechat
.
yunqueyilian
.
server
.
service
;
import
javax.servlet.http.HttpServletRequest
;
import
java.util.Map
;
/**
* @author: zhehao.chen
* @version: V1.0
* @Description:
* @date: 2018/8/9 10:08
*/
public
interface
CoreService
{
public
String
requestCheck
(
HttpServletRequest
request
);
public
String
processRequest
(
HttpServletRequest
request
);
}
server/src/main/java/com/pica/cloud/wechat/yunqueyilian/server/service/impl/CoreServiceImpl.java
0 → 100644
浏览文件 @
cb6342c6
package
com
.
pica
.
cloud
.
wechat
.
yunqueyilian
.
server
.
service
.
impl
;
import
com.pica.cloud.foundation.utils.utils.StringUtil
;
import
com.pica.cloud.wechat.yunqueyilian.common.CommonUtils
;
import
com.pica.cloud.wechat.yunqueyilian.common.Constants
;
import
com.pica.cloud.wechat.yunqueyilian.common.req.TextMessage
;
import
com.pica.cloud.wechat.yunqueyilian.server.client.IUserServiceClient
;
import
com.pica.cloud.wechat.yunqueyilian.server.entity.PWechatUser
;
import
com.pica.cloud.wechat.yunqueyilian.server.mapper.PWechatUserMapper
;
import
com.pica.cloud.wechat.yunqueyilian.server.service.CoreService
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
javax.servlet.http.HttpServletRequest
;
import
java.util.Date
;
import
java.util.HashMap
;
import
java.util.Map
;
/**
* @author: zhehao.chen
* @version: V1.0
* @Description:
* @date: 2018/8/9 10:09
*/
@Service
public
class
CoreServiceImpl
implements
CoreService
{
private
static
Logger
logger
=
LoggerFactory
.
getLogger
(
CoreServiceImpl
.
class
);
@Autowired
IUserServiceClient
userServiceClient
;
@Autowired
PWechatUserMapper
wechatUserMapper
;
@Override
public
String
requestCheck
(
HttpServletRequest
request
)
{
// 微信加密签名
String
signature
=
request
.
getParameter
(
"signature"
);
// 时间戳
String
timestamp
=
request
.
getParameter
(
"timestamp"
);
// 随机数
String
nonce
=
request
.
getParameter
(
"nonce"
);
// 随机字符串
String
echostr
=
request
.
getParameter
(
"echostr"
);
// 通过检验signature对请求进行校验,若校验成功则原样返回echostr,表示接入成功,否则接入失败
if
(
CommonUtils
.
checkSignature
(
signature
,
timestamp
,
nonce
))
{
return
echostr
;
}
return
null
;
}
@Override
public
String
processRequest
(
HttpServletRequest
request
)
{
String
respMessage
=
null
;
try
{
// 默认返回的文本消息内容
String
respContent
=
""
;
Map
<
String
,
String
>
requestMap
=
CommonUtils
.
parseXml
(
request
);
// xml请求解析
// 发送方帐号(open_id)
String
fromUserName
=
requestMap
.
get
(
"FromUserName"
);
// 公众帐号
String
toUserName
=
requestMap
.
get
(
"ToUserName"
);
// 消息类型
String
msgType
=
requestMap
.
get
(
"MsgType"
);
String
MsgId
=
requestMap
.
get
(
"MsgId"
);
String
Content
=
requestMap
.
get
(
"Content"
);
logger
.
info
(
"requestMap:"
+
requestMap
.
toString
());
if
(
msgType
.
equals
(
Constants
.
REQ_MESSAGE_TYPE_EVENT
))
{
// 事件推送
// 事件类型
String
eventType
=
requestMap
.
get
(
"Event"
);
logger
.
info
(
"eventType:"
+
eventType
);
//关注流程处理
if
(
eventType
.
equals
(
Constants
.
EVENT_TYPE_SUBSCRIBE
))
{
//获得openId
String
openId
=
fromUserName
;
//调用微信的接口,获取微信用户的详细信息
Map
map
=
userServiceClient
.
users
(
Constants
.
WECHAT_NAME_YQYL
,
openId
);
logger
.
info
(
map
.
toString
());
//1.首先处理p_wechat_user表,存在信息就补全,不存在就新增
// insertOrUpdataWechatDoctor(requestMap, map, userGet);
}
// 取消订阅
else
if
(
eventType
.
equals
(
Constants
.
EVENT_TYPE_UNSUBSCRIBE
))
{
String
openId
=
fromUserName
;
//获得openId
Map
mapIn
=
new
HashMap
();
mapIn
.
put
(
"type"
,
1
);
//1云鹊医联
mapIn
.
put
(
"openId"
,
openId
);
PWechatUser
userGet
=
wechatUserMapper
.
queryByOpenId
(
mapIn
);
//从wechat表中获取数据
Map
map
=
userServiceClient
.
users
(
Constants
.
WECHAT_NAME_YQYL
,
openId
);
//调用微信的接口,获取微信用户的详细信息
logger
.
info
(
map
.
toString
());
//1.首先处理p_wechat_user表,存在信息就补全,不存在就新增
// insertOrUpdataWechatDoctor(requestMap, map, userGet);
}
// 自定义菜单点击事件
else
if
(
eventType
.
equals
(
Constants
.
EVENT_TYPE_CLICK
))
{
// 事件KEY值,与创建自定义菜单时指定的KEY值对应
String
eventKey
=
requestMap
.
get
(
"EventKey"
);
logger
.
info
(
"eventKey:"
+
eventKey
);
if
(
eventKey
.
equals
(
"11"
))
{
}
else
if
(
eventKey
.
equals
(
"12"
))
{
respContent
=
"12客官别急,功能正在升级中..."
;
}
else
if
(
eventKey
.
equals
(
"13"
))
{
respContent
=
"13客官别急,功能正在升级中..."
;
}
}
}
if
(!
StringUtil
.
isEmpty
(
respContent
))
{
// 回复消息
TextMessage
textMessage
=
new
TextMessage
();
textMessage
.
setToUserName
(
fromUserName
);
textMessage
.
setFromUserName
(
toUserName
);
textMessage
.
setCreateTime
(
new
Date
().
getTime
());
textMessage
.
setMsgType
(
Constants
.
RESP_MESSAGE_TYPE_TEXT
);
textMessage
.
setContent
(
respContent
);
respMessage
=
CommonUtils
.
textMessageToXml
(
textMessage
);
}
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
return
respMessage
;
}
}
server/src/main/resources/mybatis/PWechatUserMapper.xml
0 → 100644
浏览文件 @
cb6342c6
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper
namespace=
"com.pica.cloud.wechat.yunqueyilian.server.mapper.PWechatUserMapper"
>
<resultMap
id=
"BaseResultMap"
type=
"com.pica.cloud.wechat.yunqueyilian.server.entity.PWechatUser"
>
<id
column=
"id"
property=
"id"
jdbcType=
"INTEGER"
/>
<result
column=
"openid"
property=
"openid"
jdbcType=
"VARCHAR"
/>
<result
column=
"patient_id"
property=
"patientId"
jdbcType=
"INTEGER"
/>
<result
column=
"type"
property=
"type"
jdbcType=
"INTEGER"
/>
<result
column=
"sex"
property=
"sex"
jdbcType=
"INTEGER"
/>
<result
column=
"nickname"
property=
"nickname"
jdbcType=
"VARCHAR"
/>
<result
column=
"province"
property=
"province"
jdbcType=
"VARCHAR"
/>
<result
column=
"city"
property=
"city"
jdbcType=
"VARCHAR"
/>
<result
column=
"country"
property=
"country"
jdbcType=
"VARCHAR"
/>
<result
column=
"headimgurl"
property=
"headimgurl"
jdbcType=
"VARCHAR"
/>
<result
column=
"privilege"
property=
"privilege"
jdbcType=
"VARCHAR"
/>
<result
column=
"unionid"
property=
"unionid"
jdbcType=
"VARCHAR"
/>
<result
column=
"subscribe"
property=
"subscribe"
jdbcType=
"INTEGER"
/>
<result
column=
"language"
property=
"language"
jdbcType=
"VARCHAR"
/>
<result
column=
"subscribe_time"
property=
"subscribeTime"
jdbcType=
"TIMESTAMP"
/>
<result
column=
"remark"
property=
"remark"
jdbcType=
"VARCHAR"
/>
<result
column=
"groupid"
property=
"groupid"
jdbcType=
"VARCHAR"
/>
<result
column=
"tagid_list"
property=
"tagidList"
jdbcType=
"VARCHAR"
/>
<result
column=
"delete_flag"
property=
"deleteFlag"
jdbcType=
"INTEGER"
/>
<result
column=
"creat_id"
property=
"creatId"
jdbcType=
"INTEGER"
/>
<result
column=
"creat_time"
property=
"creatTime"
jdbcType=
"TIMESTAMP"
/>
<result
column=
"modify_id"
property=
"modifyId"
jdbcType=
"INTEGER"
/>
<result
column=
"modify_time"
property=
"modifyTime"
jdbcType=
"TIMESTAMP"
/>
</resultMap>
<sql
id=
"Base_Column_List"
>
id, openid, patient_id, type, sex, nickname, province, city, country, headimgurl,
privilege, unionid, subscribe, language, subscribe_time, remark, groupid, tagid_list,
delete_flag, creat_id, creat_time, modify_id, modify_time
</sql>
<select
id=
"queryByOpenId"
resultMap=
"BaseResultMap"
parameterMap=
"java.util.Map"
>
select
<include
refid=
"Base_Column_List"
/>
from p_wechat_user
where type = #{type} and openid = #{openId}
</select>
</mapper>
\ No newline at end of file
写
预览
Markdown
格式
0%
请重试
or
附加一个文件
附加文件
取消
您添加了
0
人
到此讨论。请谨慎行事。
先完成此消息的编辑!
取消
想要评论请
注册
或
登录