-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathD_JDT.php
63 lines (61 loc) · 1.31 KB
/
D_JDT.php
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
62
63
<?php
class D_JDT
{
/**解析json数据
* @param $value string
* @return false|mixed
*/
function jsonParse($value=''){
try {
return json_decode($value,true);
}catch (Exception $e){
return false;
}
}
/**打包数据
* @param array $value
* @return false|string
*/
function jsonPack($value=[]){
try {
return json_encode($value,JSON_UNESCAPED_UNICODE);
}catch (Exception $e){
return false;
}
}
/**编码为base64
* @param string $str
* @return false|string
*/
function btoa($str=''){
try {
return base64_encode($str);
}catch (Exception $e){
return false;
}
}
/**解码base64
* @param string $str
* @return false|string
*/
function atob($str=''){
try {
return base64_decode($str);
}catch (Exception $e){
return false;
}
}
/**校验并解析json格式
* @param string $value
* @return false|array
*/
function checkJsonData($value) {
$res = json_decode($value, true);
$error = json_last_error();
if (!empty($error)) {
return false;
}else{
return $res;
}
}
}