w
0-目的是封装成一个类、方法,方便在不同入口下,比如不是在微信公众号内而是在他人分享的url,获取opeid,且便于路由控制,将路由控制交给且仅交给codeigniter;
1-任何一个网站都可以整合到一个单一的脚本中(暂设为以php css js 构成的的),任何一个database都可以放入一张表table中(暂设mysql);任何一个网站也可以通过单一页面完成所有功能。
www.w.com/wb
<?php $wxwid = ‘appid‘; $wstate = intval($_REQUEST[‘wstate‘]); $wxurl = ‘https://open.weixin.qq.com/connect/oauth2/authorize?appid=‘ . $wxwid . ‘&redirect_uri=http://www.icarei.cn/wb/?wback=1&response_type=code&scope=snsapi_base&state=‘ . $wstate . ‘#wechat_redirect‘; if (!isset($_REQUEST[‘wback‘])) header(‘Location: ‘ . $wxurl); $wxr_state = intval($_REQUEST[‘state‘]); $wxwid = ‘appid‘; $wxws = ‘apps‘; $wxurl = ‘https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=‘ . $wxwid . ‘&secret=‘ . $wxws; $wxr_code = $_REQUEST[‘code‘]; $wxurl = ‘https://api.weixin.qq.com/sns/oauth2/access_token?appid=‘ . $wxwid . ‘&secret=‘ . $wxws . ‘&code=‘ . $wxr_code . ‘&grant_type=authorization_code‘; $result = file_get_contents($wxurl); $res = json_decode($result, true); var_dump($res); die();