123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 |
- <?php
- namespace Home\Controller;
- use Think\Controller;
- class SqCsController extends Controller
- {
- public function getsq()
- {
- echo 1;
- $http = 'https://';
- $code = I('get.code');
- if (empty($code)) {
- $tourl = urlencode($http . $_SERVER['SERVER_NAME'] . $_SERVER["REQUEST_URI"]);
- header('Location:https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx41e478e592f9e04a&redirect_uri=' . $tourl . '&response_type=code&scope=snsapi_base&state=abc123#wechat_redirect ');
- }else{
- $user_openid = $this->s_curl('https://api.weixin.qq.com/sns/oauth2/access_token?appid=wx41e478e592f9e04a&secret=fc165de4aa5cd24b628baa30b100e146&code=' . $code . '&grant_type=authorization_code');
- $R['flag'] = false;
- $R['data'] =$user_openid;
- $R['openid'] =$user_openid['openid'];
- $R['msg'] = '操作失败,Code获取失败';
- header('Location:https://qhome.usky.cn/ceshi.html?R='.json_encode($R));
- }
- }
- //token 日志
- private final function tokenlog($token, $urls, $data = '')
- {
- try {
- M()->execute("INSERT INTO jdxf.token_log(token,url,`time`,data1) VALUES('$token','$urls',NOW(),'$data')");
- } catch (Exception $e) {
- }
- }
- //远程调用连接
- private function s_curl($url)
- {
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_URL, $url);
- curl_setopt($ch, CURLOPT_TIMEOUT, 10);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
- $file_contents = curl_exec($ch);
- curl_close($ch);
- $arr = json_decode($file_contents, true);
- return $arr;
- }
- }
|