IndexController.php
4.7 KB
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
<?php
// +----------------------------------------------------------------------
// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2018 http://www.thinkcmf.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 老猫 <thinkcmf@126.com>
// +----------------------------------------------------------------------
namespace app\portal\controller;
//use cmf\controller\HomeBaseController;
use api\portal\model\MoneyDetailModel;
use api\portal\model\OrderModel;
use api\portal\model\RefundModel;
use app\portal\model\MemberModel;
use app\portal\service\PostService;
use think\Db;
use think\Request;
use think\Loader;
use traits\controller\Jump;
use think\Config;
/**
* @title 用户接口
* @description 接口说明
* @group 接口分组
*/
class IndexController extends CommonController
{
public function index()
{
return $this->fetch(':index');
}
/**
* 对密文进行解密
*
* @param string $encrypted 需要解密的密文
* @return string 解密得到的明文
*/
public function decrypt($encrypted,$key) {
$iv = substr($key, 0, 16);
$decrypted = openssl_decrypt($encrypted, 'AES-256-CBC', $key, OPENSSL_ZERO_PADDING, $iv);
//去除补位字符
$result = $this->pkcs7Unpad($decrypted);
//去除16位随机字符串 加密时添加16为随机字符串
if (strlen($result) < 16) {
return "";
}
$content = substr($result, 16, strlen($result));
$lenList = unpack("N", substr($content, 0, 4));
$contentLen = $lenList[1];
return substr($content, 4, $contentLen);
}
/**
* 对解密后的明文进行补位删除
*
* @param string $text 解密后的明文
* @return string
*
*/
private function pkcs7Unpad($text) {
$pad = ord(substr($text, -1));
if ($pad < 1 || $pad > 32) {
$pad = 0;
}
return substr($text, 0, (strlen($text) - $pad));
}
// 登录,注册
//tel 手机号
//password 密码
//sure_password 确认密码
//name 真实姓名
public function login(Request $request)
{
if($request->Post()){
// 验证
$validate = Loader::validate('User');
if(!$validate->scene('add')->check($_POST)){
return json(array('code'=>0,'msg'=>$validate->getError()));
}
// 密码
$_POST['password'] = $this->md5($_POST['password']);
// 确认密码
if($_POST['password'] != $_POST['sure_password']){
$this->apiResponse('0','两次密码不一致');
}
// 短信验证码(未完)
// 判断手机号是否已注册
$user = new MemberModel($_POST);
$where_user['tel'] = $_POST['tel'];
$is_isset = $user->where($where_user)->find();
if($is_isset){
$this->apiResponse('0','您已注册过,请直接登录');
}
$add = $user->allowField(true)->save();
if($add){
echo "<pre/>";
print_r('1');
die;
}else{
echo "<pre/>";
print_r('2');
die;
}
}else{
// 服务协议
$service = new PostService();
$list = $service->publishedArticle(1,1)->toArray();
// 推荐人(未完)
if($list){
$this->apiResponse('1','成功',$list);
}else{
$this->apiResponse('0','暂无内容');
}
}
}
// 微信支付二维码
public function qrcode() {
$data = $this->request->param('data');
require_once VENDOR_PATH.'WxpayAPI/example/phpqrcode/phpqrcode.php';
$url = urldecode($data);
\QRcode::png($url);
}
// 检测微信支付是否完成
public function checkStatus() {
if($this->request->isAjax()) {
$order_sn = $this->request->param('order_sn');
$order_model = new OrderModel();
$status = $order_model->where(['order_sn'=>$order_sn])->value('status');
if(empty($status)) {
$this->apiResponse(0,'订单不存在');
}
if($status == 1 || $status == 9) {
$this->apiResponse(0,'未支付成功');
}
if($status == 2) {
$this->apiResponse(1,'支付成功');
}
}
}
}