You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

53 lines
1.5 KiB
PHTML

3 years ago
<?php
namespace Admin\Controller;
use User\Api\UserApi;
use Com\Wechat;
use Com\WechatAuth;
use Base\Tool\TaskClient;
/**
* 小程序
*/
class MiniProgramController extends \Think\Controller
{
private $secert = 'fcd494b677bf0c9819e137538be93f10';
private $appId = 'wxb7264c023beac13c';
public function getOpenId() {
$code = I('code', '');
3 years ago
if (!$code) {
return $this->ajaxReturn([
'status' => 0,
'msg' => 'code不能为空',
]);
}
3 years ago
$url = "https://api.weixin.qq.com/sns/jscode2session?appid={$this->appId}&secret={$this->secert}&js_code={$code}";
$r = file_get_contents($url);
$wxInfo = I('userInfo');
$wxUser =json_decode($r, true);
$exist = M('mini_program_user', 'tab_')->where([
'openid' => $wxUser['openid']
])->find();
if (!$exist) {
$wxInfoDeJson = json_decode($wxInfo, true);
M('mini_program_user', 'tab_')->add([
'openid' => $wxUser['openid'],
'unionid' => $wxUser['unionid'],
'wx_json' => $wxInfo,
'avatar' => $wxInfoDeJson['avatarUrl'],
'nickname' => $wxInfoDeJson['nickName'],
'city' => $wxInfoDeJson['city'],
'province' => $wxInfoDeJson['province'],
'country' => $wxInfoDeJson['country'],
'create_time' => time()
]);
}
3 years ago
echo $r;
}
}