Browse Source

微信网页授权

master
ZLW-PC\Administrator 7 years ago
parent
commit
fd219f5cf5
  1. 45
      app/Common/WechatAuth.php
  2. 40
      app/Http/Controllers/Weixin/UserController.php
  3. 53
      resources/views/weixin/index/index.blade.php
  4. 4
      resources/views/weixin/user/login.blade.php
  5. 2
      resources/views/weixin/user/register.blade.php

45
app/Common/WechatAuth.php

@ -0,0 +1,45 @@
<?php
namespace App\Common;
/**
* OAuth2.0微信授权登录实现
*
* @author FLi
* @文件名:GetWxUserInfo.php
*/
class WechatAuth
{
//高级功能->开发者模式->获取
private $app_id = 'xxx';
private $app_secret = 'xxxxxxx';
//$registration_id = getenv('registration_id');
public static function send($msg, $param='')
{
$client = new JPushMsg(self::APP_KEY, self::APP_SECRET, null);
$push_payload = $client->push();
$push_payload = $push_payload->setPlatform('all');
if(isset($param['mobile'])){$push_payload = $push_payload->addAlias(md5($param['mobile']));}
$push_payload = $push_payload->addAllAudience();
$push_payload = $push_payload->setNotificationAlert($msg);
try
{
$push_payload->send();
}
catch (JPushMsg\Exceptions\APIConnectionException $e)
{
Log::info($e);
return false;
}
catch (JPushMsg\Exceptions\APIRequestException $e)
{
Log::info($e);
return false;
}
return true;
}
}

40
app/Http/Controllers/Weixin/UserController.php

@ -271,6 +271,44 @@ class UserController extends CommonController
$this->success_jump(ReturnCode::SUCCESS);
}
//微信网页授权登录
public function oauth(Request $request)
{
if(isset($_SESSION['weixin_user_info']))
{
if(isset($_SERVER["HTTP_REFERER"])){header('Location: '.$_SERVER["HTTP_REFERER"]);exit;}
header('Location: '.route('weixin_user'));exit;
}
if($_SERVER['REQUEST_METHOD'] == 'POST')
{
if($_POST['user_name'] == '')
{
$this->error_jump('账号不能为空');
}
if($_POST['password'] == '')
{
$this->error_jump('密码不能为空');
}
$postdata = array(
'user_name' => $_POST['user_name'],
'password' => md5($_POST['password'])
);
$url = env('APP_API_URL')."/wx_login";
$res = curl_request($url,$postdata,'POST');
if($res['code'] != ReturnCode::SUCCESS_CODE){$this->error_jump('登录失败');}
$_SESSION['weixin_user_info'] = $res['data'];
header('Location: '.route('weixin_user'));exit;
}
return view('weixin.user.login');
}
//登录
public function login(Request $request)
{
@ -324,7 +362,7 @@ class UserController extends CommonController
public function logout(Request $request)
{
session_unset();
session_destroy();// 退出登录,清除session
session_destroy(); // 退出登录,清除session
$this->success_jump('退出成功',route('weixin'));
}

53
resources/views/weixin/index/index.blade.php

@ -146,59 +146,6 @@ var swiper = new Swiper('.swiper-nav', {
</ul>
</div>
</div>
<script>
$(function(){
var ajaxload=false;
var maxpage=false;
var startpage=1;
var totalpage="{$totalpage}";
var tmp_url = window.location.href;
msg = tmp_url.split("#");
tmp_url = msg[0];
$(window).scroll(function ()
{
var listheight = $("#goods_list").outerHeight();
if ($(document).scrollTop() + $(window).height() >= listheight) {
if(startpage>=totalpage){
//$("#submit_bt_one").html("已是最后一页,没有更多数据!");
return false;
}
if(!ajaxload&&!maxpage){
ajaxload=true;
//$("#submit_bt_one").html("努力加载中...");
var url = tmp_url;
var nextpage = startpage+1;
var role_id = "{$role_id}";
$.post(url,{page_ajax:1,page:nextpage,role_id:role_id},function(data){
//alert(data.html);
if(data.html){
$("#goods_list").append(data.html);
startpage++;
if(startpage>=totalpage){
maxpage=true;
//$("#submit_bt_one").html("已是最后一页,没有更多数据!");
}else{
//$("#submit_bt_one").html("点击加载更多");
}
ajaxload=false;
}else{
//$("#submit_bt_one").html("请求失败,请稍候再试!");
ajaxload=false;
}
},'json');
}
}
});
});
function messageNotice(message)
{
$("#message").html(message);
$(".messageShow").show();
setInterval(function(){$(".messageShow").hide();},3000);
}
</script>
<!--猜您喜欢-end-->
<!--猜您喜欢-start-->

4
resources/views/weixin/user/login.blade.php

@ -13,7 +13,7 @@
@include('weixin.common.headerNav')
<style>
.account{text-align:center;margin-top:50px;}
.account{text-align:center;margin-top:30px;}
.account .icon{color:#FFCC00;font-size:100px;}
.bottoma{display:block;font-size:18px;padding:10px;border-radius:2px;}
@ -39,7 +39,7 @@
<a style="margin:10px;background-color:#1aad19;text-align:center;color:white;border:1px solid #179e16;" class="bottoma" href="javascript:submit();">登录</a>
</div>
<div class="box reg">
<a style="float:left;" href="<?php echo route('weixin_register'); ?>">快速注册</a> <a style="float:right;" href="">忘记密码?</a>
<a style="float:left;" href="<?php echo route('weixin_register'); ?>">快速注册</a> <a style="float:left;" href="<?php echo route('weixin_register'); ?>">微信</a> <a style="float:right;" href="">忘记密码?</a>
</div><br><br>
<script type="text/javascript" src="<?php echo env('APP_URL'); ?>/js/md5.min.js"></script>
<script type="text/javascript" src="<?php echo env('APP_URL'); ?>/js/layer/mobile/layer.js"></script>

2
resources/views/weixin/user/register.blade.php

@ -13,7 +13,7 @@
@include('weixin.common.headerNav')
<style>
.account{text-align:center;margin-top:50px;}
.account{text-align:center;margin-top:30px;}
.account .icon{color:#FFCC00;font-size:100px;}
.bottoma{display:block;font-size:18px;padding:10px;border-radius:2px;}

Loading…
Cancel
Save