|
|
@ -4,6 +4,7 @@ namespace App\Http\Controllers\Weixin; |
|
|
|
use App\Http\Controllers\Weixin\CommonController; |
|
|
|
use Illuminate\Http\Request; |
|
|
|
use App\Common\ReturnCode; |
|
|
|
use App\Common\ReturnData; |
|
|
|
use App\Common\WechatAuth; |
|
|
|
use App\Common\Helper; |
|
|
|
|
|
|
@ -27,7 +28,7 @@ class UserController extends CommonController |
|
|
|
$res = curl_request($url,$postdata,'GET'); |
|
|
|
$data['user_info'] = $res['data']; |
|
|
|
|
|
|
|
if($res['code'] != ReturnCode::SUCCESS_CODE){unset($_SESSION['weixin_user_info']);$this->error_jump('请先登录',route('weixin_login'));} |
|
|
|
if($res['code'] != ReturnData::SUCCESS){unset($_SESSION['weixin_user_info']);$this->error_jump('请先登录',route('weixin_login'));} |
|
|
|
|
|
|
|
return view('weixin.user.index', $data); |
|
|
|
} |
|
|
@ -509,7 +510,7 @@ class UserController extends CommonController |
|
|
|
$url = env('APP_API_URL')."/user_goods_history_delete"; |
|
|
|
$res = curl_request($url,$postdata,'POST'); |
|
|
|
|
|
|
|
if($res['code'] != ReturnCode::SUCCESS_CODE){$this->error_jump(ReturnCode::FAIL);} |
|
|
|
if($res['code'] != ReturnData::SUCCESS){$this->error_jump(ReturnCode::FAIL);} |
|
|
|
|
|
|
|
$this->success_jump(ReturnCode::SUCCESS); |
|
|
|
} |
|
|
@ -523,13 +524,15 @@ class UserController extends CommonController |
|
|
|
$url = env('APP_API_URL')."/user_goods_history_clear"; |
|
|
|
$res = curl_request($url,$postdata,'POST'); |
|
|
|
|
|
|
|
if($res['code'] != ReturnCode::SUCCESS_CODE){$this->error_jump(ReturnCode::FAIL);} |
|
|
|
if($res['code'] != ReturnData::SUCCESS){$this->error_jump(ReturnCode::FAIL);} |
|
|
|
|
|
|
|
$this->success_jump(ReturnCode::SUCCESS); |
|
|
|
} |
|
|
|
|
|
|
|
//微信网页授权登录
|
|
|
|
public function oauth(Request $request) |
|
|
|
{ |
|
|
|
if (!isset($_SESSION['weixin_oauth']['userinfo'])) |
|
|
|
{ |
|
|
|
$wechat_auth = new WechatAuth(sysconfig('CMS_WX_APPID'),sysconfig('CMS_WX_APPSECRET')); |
|
|
|
|
|
|
@ -547,27 +550,21 @@ class UserController extends CommonController |
|
|
|
} |
|
|
|
|
|
|
|
// 依据code码去获取openid和access_token,自己的后台服务器直接向微信服务器申请即可
|
|
|
|
if (isset($_GET['code'])) |
|
|
|
{ |
|
|
|
$_SESSION['weixin_oauth']['code'] = $_GET['code']; |
|
|
|
|
|
|
|
if($_GET['state'] != $_SESSION['weixin_oauth']['state']) |
|
|
|
{ |
|
|
|
exit("您访问的页面不存在或已被删除!"); |
|
|
|
$this->error_jump('您访问的页面不存在或已被删除'); |
|
|
|
} |
|
|
|
|
|
|
|
//得到 access_token 与 openid
|
|
|
|
$_SESSION['weixin_oauth']['token'] = $wechat_auth->get_access_token($_GET['code']); |
|
|
|
} |
|
|
|
|
|
|
|
// 依据申请到的access_token和openid,申请Userinfo信息。
|
|
|
|
if (isset($_SESSION['weixin_oauth']['token'])) |
|
|
|
{ |
|
|
|
$_SESSION['weixin_oauth']['userinfo'] = $wechat_auth->get_user_info($_SESSION['weixin_oauth']['token']['access_token'], $_SESSION['weixin_oauth']['token']['openid']); |
|
|
|
} |
|
|
|
|
|
|
|
$postdata = array( |
|
|
|
'openid' => $_SESSION['weixin_oauth']['token']['openid'], |
|
|
|
'openid' => $_SESSION['weixin_oauth']['userinfo']['openid'], |
|
|
|
'unionid' => isset($_SESSION['weixin_oauth']['userinfo']['unionid']) ? $_SESSION['weixin_oauth']['userinfo']['unionid'] : '', |
|
|
|
'nickname' => $_SESSION['weixin_oauth']['userinfo']['nickname'], |
|
|
|
'sex' => $_SESSION['weixin_oauth']['userinfo']['sex'], |
|
|
@ -578,11 +575,9 @@ class UserController extends CommonController |
|
|
|
); |
|
|
|
$url = env('APP_API_URL')."/wx_oauth_register"; |
|
|
|
$res = curl_request($url,$postdata,'POST'); |
|
|
|
|
|
|
|
if($res['code'] != ReturnCode::SUCCESS_CODE){$this->error_jump('系统错误');} |
|
|
|
if($res['code'] != ReturnData::SUCCESS){$this->error_jump('系统错误');} |
|
|
|
|
|
|
|
$_SESSION['weixin_user_info'] = $res['data']; |
|
|
|
|
|
|
|
header('Location: '.route('weixin_user'));exit; |
|
|
|
} |
|
|
|
|
|
|
@ -617,7 +612,7 @@ class UserController extends CommonController |
|
|
|
$url = env('APP_API_URL')."/wx_login"; |
|
|
|
$res = curl_request($url,$postdata,'POST'); |
|
|
|
|
|
|
|
if($res['code'] != ReturnCode::SUCCESS_CODE){$this->error_jump('登录失败');} |
|
|
|
if($res['code'] != ReturnData::SUCCESS){$this->error_jump('登录失败');} |
|
|
|
|
|
|
|
$_SESSION['weixin_user_info'] = $res['data']; |
|
|
|
|
|
|
|