正在显示
4 个修改的文件
包含
13 行增加
和
130 行删除
@@ -3,8 +3,8 @@ | @@ -3,8 +3,8 @@ | ||
3 | namespace app\api\controller; | 3 | namespace app\api\controller; |
4 | 4 | ||
5 | use app\common\controller\Api; | 5 | use app\common\controller\Api; |
6 | -use function fast\e; | ||
7 | use think\Db; | 6 | use think\Db; |
7 | +use EasyWeChat\Foundation\Application; | ||
8 | 8 | ||
9 | /** | 9 | /** |
10 | * 用户接口 | 10 | * 用户接口 |
@@ -781,7 +781,18 @@ class User extends Api | @@ -781,7 +781,18 @@ class User extends Api | ||
781 | */ | 781 | */ |
782 | public function MobileVi() | 782 | public function MobileVi() |
783 | { | 783 | { |
784 | - | 784 | + $options = [ |
785 | + 'mini_program' => [ | ||
786 | + 'app_id' => 'component-app-id', | ||
787 | + 'secret' => 'component-app-secret', | ||
788 | + 'token' => 'component-token', | ||
789 | + 'aes_key' => 'component-aes-key' | ||
790 | + ], | ||
791 | + ]; | ||
792 | + $app = new Application($options); | ||
793 | + $miniProgram = $app->mini_program; | ||
785 | $param = $this->request->param(); | 794 | $param = $this->request->param(); |
795 | + $mobile = $miniProgram->encryptor->decryptData($param['sessionKey'], $param['iv'], $param['encryptedData']); | ||
796 | + $this->success('成功', $mobile); | ||
786 | } | 797 | } |
787 | } | 798 | } |
demo/demo.php
已删除
100644 → 0
1 | -<?php | ||
2 | - | ||
3 | -include_once "wxBizDataCrypt.php"; | ||
4 | - | ||
5 | - | ||
6 | -$appid = 'wx4f4bc4dec97d474b'; | ||
7 | -$sessionKey = 'tiihtNczf5v6AKRyjwEUhQ=='; | ||
8 | - | ||
9 | -$encryptedData="CiyLU1Aw2KjvrjMdj8YKliAjtP4gsMZM | ||
10 | - QmRzooG2xrDcvSnxIMXFufNstNGTyaGS | ||
11 | - 9uT5geRa0W4oTOb1WT7fJlAC+oNPdbB+ | ||
12 | - 3hVbJSRgv+4lGOETKUQz6OYStslQ142d | ||
13 | - NCuabNPGBzlooOmB231qMM85d2/fV6Ch | ||
14 | - evvXvQP8Hkue1poOFtnEtpyxVLW1zAo6 | ||
15 | - /1Xx1COxFvrc2d7UL/lmHInNlxuacJXw | ||
16 | - u0fjpXfz/YqYzBIBzD6WUfTIF9GRHpOn | ||
17 | - /Hz7saL8xz+W//FRAUid1OksQaQx4CMs | ||
18 | - 8LOddcQhULW4ucetDf96JcR3g0gfRK4P | ||
19 | - C7E/r7Z6xNrXd2UIeorGj5Ef7b1pJAYB | ||
20 | - 6Y5anaHqZ9J6nKEBvB4DnNLIVWSgARns | ||
21 | - /8wR2SiRS7MNACwTyrGvt9ts8p12PKFd | ||
22 | - lqYTopNHR1Vf7XjfhQlVsAJdNiKdYmYV | ||
23 | - oKlaRv85IfVunYzO0IKXsyl7JCUjCpoG | ||
24 | - 20f0a04COwfneQAGGwd5oa+T8yO5hzuy | ||
25 | - Db/XcxxmK01EpqOyuxINew=="; | ||
26 | - | ||
27 | -$iv = 'r7BXXKkLb8qrSNn05n0qiA=='; | ||
28 | - | ||
29 | -$pc = new WXBizDataCrypt($appid, $sessionKey); | ||
30 | -$errCode = $pc->decryptData($encryptedData, $iv, $data ); | ||
31 | - | ||
32 | -if ($errCode == 0) { | ||
33 | - print($data . "\n"); | ||
34 | -} else { | ||
35 | - print($errCode . "\n"); | ||
36 | -} |
demo/errorCode.php
已删除
100644 → 0
1 | -<?php | ||
2 | - | ||
3 | -/** | ||
4 | - * error code 说明. | ||
5 | - * <ul> | ||
6 | - | ||
7 | - * <li>-41001: encodingAesKey 非法</li> | ||
8 | - * <li>-41003: aes 解密失败</li> | ||
9 | - * <li>-41004: 解密后得到的buffer非法</li> | ||
10 | - * <li>-41005: base64加密失败</li> | ||
11 | - * <li>-41016: base64解密失败</li> | ||
12 | - * </ul> | ||
13 | - */ | ||
14 | -class ErrorCode | ||
15 | -{ | ||
16 | - public static $OK = 0; | ||
17 | - public static $IllegalAesKey = -41001; | ||
18 | - public static $IllegalIv = -41002; | ||
19 | - public static $IllegalBuffer = -41003; | ||
20 | - public static $DecodeBase64Error = -41004; | ||
21 | -} | ||
22 | - | ||
23 | -?> |
demo/wxBizDataCrypt.php
已删除
100644 → 0
1 | -<?php | ||
2 | - | ||
3 | -/** | ||
4 | - * 对微信小程序用户加密数据的解密示例代码. | ||
5 | - * | ||
6 | - * @copyright Copyright (c) 1998-2014 Tencent Inc. | ||
7 | - */ | ||
8 | - | ||
9 | - | ||
10 | -include_once "errorCode.php"; | ||
11 | - | ||
12 | - | ||
13 | -class WXBizDataCrypt | ||
14 | -{ | ||
15 | - private $appid; | ||
16 | - private $sessionKey; | ||
17 | - | ||
18 | - /** | ||
19 | - * 构造函数 | ||
20 | - * @param $sessionKey string 用户在小程序登录后获取的会话密钥 | ||
21 | - * @param $appid string 小程序的appid | ||
22 | - */ | ||
23 | - public function __construct( $appid, $sessionKey) | ||
24 | - { | ||
25 | - $this->sessionKey = $sessionKey; | ||
26 | - $this->appid = $appid; | ||
27 | - } | ||
28 | - | ||
29 | - | ||
30 | - /** | ||
31 | - * 检验数据的真实性,并且获取解密后的明文. | ||
32 | - * @param $encryptedData string 加密的用户数据 | ||
33 | - * @param $iv string 与用户数据一同返回的初始向量 | ||
34 | - * @param $data string 解密后的原文 | ||
35 | - * | ||
36 | - * @return int 成功0,失败返回对应的错误码 | ||
37 | - */ | ||
38 | - public function decryptData( $encryptedData, $iv, &$data ) | ||
39 | - { | ||
40 | - if (strlen($this->sessionKey) != 24) { | ||
41 | - return ErrorCode::$IllegalAesKey; | ||
42 | - } | ||
43 | - $aesKey=base64_decode($this->sessionKey); | ||
44 | - | ||
45 | - | ||
46 | - if (strlen($iv) != 24) { | ||
47 | - return ErrorCode::$IllegalIv; | ||
48 | - } | ||
49 | - $aesIV=base64_decode($iv); | ||
50 | - | ||
51 | - $aesCipher=base64_decode($encryptedData); | ||
52 | - | ||
53 | - $result=openssl_decrypt( $aesCipher, "AES-128-CBC", $aesKey, 1, $aesIV); | ||
54 | - | ||
55 | - $dataObj=json_decode( $result ); | ||
56 | - if( $dataObj == NULL ) | ||
57 | - { | ||
58 | - return ErrorCode::$IllegalBuffer; | ||
59 | - } | ||
60 | - if( $dataObj->watermark->appid != $this->appid ) | ||
61 | - { | ||
62 | - return ErrorCode::$IllegalBuffer; | ||
63 | - } | ||
64 | - $data = $result; | ||
65 | - return ErrorCode::$OK; | ||
66 | - } | ||
67 | - | ||
68 | -} | ||
69 | - |
-
请 注册 或 登录 后发表评论