FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
weworkapi_php/callback/xmlparse.php at master · EternalSuno/weworkapi_php · GitHub
EternalSuno
/
weworkapi_php
Public
forked from
sbzhu/weworkapi_php
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
weworkapi_php
/
callback
/
xmlparse.php
Copy path
More file actions
More file actions
Latest commit
History
History
History
61 lines (54 loc) · 1.46 KB
Breadcrumbs
weworkapi_php
/
callback
/
xmlparse.php
Copy path
File metadata and controls
61 lines (54 loc) · 1.46 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<?php
include_once
"
errorCode.php
"
;
/**
* XMLParse class
*
* 提供提取消息格式中的密文及生成回复消息格式的接口.
*/
class
XMLParse
{
/**
* 提取出xml数据包中的加密消息
* @param string $xmltext 待提取的xml字符串
* @return string 提取出的加密消息字符串
*/
public
function
extract
(
$
xmltext
)
{
try
{
$
xml
=
new
DOMDocument
();
$
xml
->
loadXML
(
$
xmltext
);
$
array_e
=
$
xml
->
getElementsByTagName
(
'
Encrypt
'
);
$
encrypt
=
$
array_e
->
item
(
0
)->
nodeValue
;
return
array
(
0
,
$
encrypt
);
}
catch
(
Exception
$
e
) {
print
$
e
.
"\n"
;
return
array
(ErrorCode::
$
ParseXmlError
,
null
);
}
}
/**
* 生成xml消息
* @param string $encrypt 加密后的消息密文
* @param string $signature 安全签名
* @param string $timestamp 时间戳
* @param string $nonce 随机字符串
*/
public
function
generate
(
$
encrypt
,
$
signature
,
$
timestamp
,
$
nonce
)
{
$
format
=
"
<xml>
<Encrypt><![CDATA[%s]]></Encrypt>
<MsgSignature><![CDATA[%s]]></MsgSignature>
<TimeStamp>%s</TimeStamp>
<Nonce><![CDATA[%s]]></Nonce>
</xml>
"
;
return
sprintf
(
$
format
,
$
encrypt
,
$
signature
,
$
timestamp
,
$
nonce
);
}
}
//
// Test
/*
$sPostData = "<xml><ToUserName><![CDATA[toUser]]></ToUserName><AgentID><![CDATA[toAgentID]]></AgentID><Encrypt><![CDATA[msg_encrypt]]></Encrypt></xml>";
$xmlparse = new XMLParse;
$array = $xmlparse->extract($sPostData);
var_dump($array);
*/
?>
Back
|
FazBrowse Home
|
New Git URL