mirror of
https://gitee.com/apiadmin/ApiAdmin.git
synced 2025-04-06 03:58:00 +08:00
added 微信小程序的支持
This commit is contained in:
parent
f45c95897c
commit
6482ccf02b
48
Application/Home/Api/User.class.php
Normal file
48
Application/Home/Api/User.class.php
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* 小程序自动获取体验账号实现
|
||||||
|
* @since 2017/04/24 创建
|
||||||
|
* @author zhaoxiang <zhaoxiang051405@gmail.com>
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Home\Api;
|
||||||
|
|
||||||
|
|
||||||
|
use Home\ORG\Str;
|
||||||
|
|
||||||
|
class User extends Base {
|
||||||
|
public function index($param) {
|
||||||
|
$openId = $this->getOpenId($param);
|
||||||
|
$old = D('ApiUser')->where(array('openId' => $openId))->find();
|
||||||
|
if ($old) {
|
||||||
|
return array('username' => $old['username'], 'password' => '******');
|
||||||
|
}
|
||||||
|
$data['username'] = Str::randString(6, 1);
|
||||||
|
$pwd = Str::randString(6, 1);
|
||||||
|
$data['password'] = user_md5($pwd);
|
||||||
|
$data['regTime'] = time();
|
||||||
|
$data['openId'] = $openId;
|
||||||
|
$newId = D('ApiUser')->add($data);
|
||||||
|
D('ApiAuthGroupAccess')->add(array('uid' => $newId, 'groupId' => 1));
|
||||||
|
|
||||||
|
return array('username' => $data['username'], 'password' => $pwd);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function re($param) {
|
||||||
|
$openId = $this->getOpenId($param);
|
||||||
|
$pwd = Str::randString(6, 1);
|
||||||
|
$data['password'] = user_md5($pwd);
|
||||||
|
$old = D('ApiUser')->where(array('openId' => $openId))->find();
|
||||||
|
D('ApiUser')->where(array('openId' => $openId))->save($data);
|
||||||
|
|
||||||
|
return array('username' => $old['username'], 'password' => $pwd);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function getOpenId($param) {
|
||||||
|
$url = "https://api.weixin.qq.com/sns/jscode2session?appid=wx436e089d55174f47&secret=f4684158a0efd56ff2332582dc62f3db&js_code={$param['code']}&grant_type=authorization_code";
|
||||||
|
$res = file_get_contents($url);
|
||||||
|
$resArr = json_decode($res, true);
|
||||||
|
|
||||||
|
return $resArr['openid'];
|
||||||
|
}
|
||||||
|
}
|
@ -8,11 +8,11 @@
|
|||||||
namespace Home\Controller;
|
namespace Home\Controller;
|
||||||
|
|
||||||
|
|
||||||
|
use Home\Api\User;
|
||||||
use Home\ORG\ApiLog;
|
use Home\ORG\ApiLog;
|
||||||
use Home\ORG\Filter;
|
use Home\ORG\Filter;
|
||||||
use Home\ORG\Response;
|
use Home\ORG\Response;
|
||||||
use Home\ORG\ReturnCode;
|
use Home\ORG\ReturnCode;
|
||||||
use Think\Log;
|
|
||||||
|
|
||||||
class ApiController extends BaseController {
|
class ApiController extends BaseController {
|
||||||
|
|
||||||
@ -62,6 +62,11 @@ class ApiController extends BaseController {
|
|||||||
$this->param = $getArr;
|
$this->param = $getArr;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
if( $this->header['USER-AGENT'] == 'wx' ){
|
||||||
|
$data = file_get_contents("php://input");
|
||||||
|
$data = json_decode($data, true);
|
||||||
|
$this->param = $data;
|
||||||
|
}
|
||||||
ApiLog::setRequest($this->param);
|
ApiLog::setRequest($this->param);
|
||||||
$this->iniApi();
|
$this->iniApi();
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user