Exemple #1
0
function isSub($openid)
{
    import('WechatApi');
    $tokenObj = new WechatApi(array('appid' => option('config.wechat_appid'), 'appsecret' => option('config.wechat_appsecret')));
    $access_token = $tokenObj->get_access_token();
    $url = 'https://api.weixin.qq.com/cgi-bin/user/info?openid=' . $openid . '&access_token=' . $access_token['access_token'];
    $classData = json_decode(Http::curlGet($url));
    if ($classData->subscribe == 0) {
        //没有关注
        return 0;
    } else {
        return 1;
    }
}
 public function img_download()
 {
     $url = $_POST['url'];
     if (IS_POST && !empty($url)) {
         $ext_name = strrchr($url, '.');
         if ($ext_name != '.gif' && $ext_name != '.jpg' && $ext_name != '.png' && $ext_name != '.jpeg') {
             json_return(1000, '为了网站安全考虑,<br/>网址应以(gif、jpg、png或jpeg)结尾');
         }
         import('Http');
         $http_class = new Http();
         $image_content = $http_class->curlGet($url);
         if (empty($image_content)) {
             json_return(1001, '没有获取到内容,请重试');
         }
         $img_store_id = sprintf("%09d", $this->store_session['store_id']);
         $rand_num = 'images/' . substr($img_store_id, 0, 3) . '/' . substr($img_store_id, 3, 3) . '/' . substr($img_store_id, 6, 3) . '/' . date('Ym', $_SERVER['REQUEST_TIME']) . '/';
         $upload_dir = './upload/' . $rand_num;
         if (!is_dir($upload_dir)) {
             mkdir($upload_dir, 0777, true);
         }
         $filename = uniqid() . $ext_name;
         if (file_put_contents($upload_dir . $filename, $image_content)) {
             $info = getimagesize($upload_dir . $filename);
             $ext = image_type_to_extension($info['2']);
             if (!in_array($ext, array('.gif', '.jpg', '.jpeg', '.png'))) {
                 unlink($upload_dir . $filename);
                 json_return(1002, '图片格式不允许<br/>只允许上传(gif、jpg、png或jpeg)格式的图片');
             }
             $add_result = $this->attachment_add($filename, $rand_num . $filename, filesize($upload_dir . $filename));
             if ($add_result['err_code']) {
                 unlink($upload_dir . $filename);
             } else {
                 // 上传到又拍云服务器
                 $attachment_upload_type = option('config.attachment_upload_type');
                 if ($attachment_upload_type == '1') {
                     import('source.class.upload.upyunUser');
                     upyunUser::upload('./upload/' . $rand_num . $filename, '/' . $rand_num . $filename);
                 }
                 json_return(0, array('url' => getAttachmentUrl($rand_num . $filename), 'pigcms_id' => $add_result['pigcms_id']));
             }
         } else {
             json_return(1001, '图片保存失败,请重试');
         }
     }
 }
Exemple #3
0
 public static function kuadi100($url)
 {
     import('class.Http');
     $content = Http::curlGet($url);
     return $content;
 }
 public function weixin_back()
 {
     $referer = !empty($_SESSION['weixin']['referer']) ? $_SESSION['weixin']['referer'] : U('Home/index');
     // if (isset($_GET['code']) && isset($_GET['state']) && ($_GET['state'] == $_SESSION['weixin']['state'])){
     if (isset($_GET['code'])) {
         unset($_SESSION['weixin']['state']);
         import('ORG.Net.Http');
         $http = new Http();
         $return = $http->curlGet('https://api.weixin.qq.com/sns/oauth2/access_token?appid=' . $this->config['wechat_appid'] . '&secret=' . $this->config['wechat_appsecret'] . '&code=' . $_GET['code'] . '&grant_type=authorization_code');
         $jsonrt = json_decode($return, true);
         if ($jsonrt['errcode']) {
             $error_msg_class = new GetErrorMsg();
             $this->error_tips('授权发生错误:' . $error_msg_class->wx_error_msg($jsonrt['errcode']), U('Login/index'));
         }
         $return = $http->curlGet('https://api.weixin.qq.com/sns/userinfo?access_token=' . $jsonrt['access_token'] . '&openid=' . $jsonrt['openid'] . '&lang=zh_CN');
         $jsonrt = json_decode($return, true);
         if ($jsonrt['errcode']) {
             $error_msg_class = new GetErrorMsg();
             $this->error_tips('授权发生错误:' . $error_msg_class->wx_error_msg($jsonrt['errcode']), U('Login/index'));
         }
         /*优先使用 unionid 登录*/
         if (!empty($jsonrt['unionid'])) {
             $this->autologin('union_id', $jsonrt['unionid'], $referer);
         }
         /*再次使用 openid 登录*/
         $this->autologin('openid', $jsonrt['openid'], $referer);
         /*注册用户*/
         $data_user = array('openid' => $jsonrt['openid'], 'union_id' => $jsonrt['unionid'] ? $jsonrt['unionid'] : '', 'nickname' => $jsonrt['nickname'], 'sex' => $jsonrt['sex'], 'province' => $jsonrt['province'], 'city' => $jsonrt['city'], 'avatar' => $jsonrt['headimgurl']);
         $_SESSION['weixin']['user'] = $data_user;
         $this->assign('referer', $referer);
         $this->display();
     } else {
         $this->error_tips('访问异常!请重新登录。', U('Login/index', array('referer' => urlencode($referer))));
     }
 }
Exemple #5
0
 public function authorize_openid()
 {
     if (empty($_GET["code"])) {
         $_SESSION["weixin"]["state"] = md5(uniqid());
         $customeUrl = $this->config["site_url"] . $_SERVER["REQUEST_URI"];
         //用户同意授权,获取code
         $oauthUrl = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=" . $this->config["wechat_appid"] . "&redirect_uri=" . urlencode($customeUrl) . "&response_type=code&scope=snsapi_base&state=" . $_SESSION["weixin"]["state"] . "#wechat_redirect";
         redirect($oauthUrl);
         exit;
     } else {
         if (isset($_GET['code']) && true == isset($_GET['state']) && $_GET['state'] == $_SESSION['weixin']['state']) {
             unset($_SESSION['weixin']);
             import('ORG.Net.Http');
             $http = new Http();
             //获取access_token
             $return = $http->curlGet("https://api.weixin.qq.com/sns/oauth2/access_token?appid=" . $this->config["wechat_appid"] . "&secret=" . $this->config["wechat_appsecret"] . "&code=" . $_GET["code"] . "&grant_type=authorization_code");
             $jsonrt = json_decode($return, true);
             //授权失败
             if ($jsonrt["errcode"]) {
                 $error_msg_class = new GetErrorMsg();
                 $this->error_tips("授权发生错误:" . $error_msg_class->wx_error_msg($jsonrt["errcode"]), U("Home/index"));
             }
             //授权成功
             if ($jsonrt["openid"]) {
                 $_SESSION["openid"] = $jsonrt["openid"];
                 $result = D("User")->autologin("openid", $jsonrt["openid"]);
                 if (empty($result['error_code'])) {
                     $now_user = $result['user'];
                     session('user', $now_user);
                     $this->user_session = session('user');
                 }
             } else {
                 redirect(u('Home/index'));
             }
         } else {
             redirect(u('Home/index'));
         }
     }
 }
Exemple #6
0
         } else {
             $artivce_list[$key]['url'] = $activity->createUrl($value, $value['model'], '1');
             $artivce_list[$key]['image'] = getAttachmentUrl($value['image']);
         }
     }
     json_return(0, $artivce_list);
     break;
 case 'neargoods':
     $long = $_REQUEST['long'];
     $lat = $_REQUEST['lat'];
     if (empty($long) || empty($lat)) {
         json_return(1, '没有携带地理位置');
     }
     import('Http');
     $http_class = new Http();
     $callback = $http_class->curlGet('http://api.map.baidu.com/geoconv/v1/?coords=' . $long . ',' . $lat . '&from=1&to=5&ak=4c1bb2055e24296bbaef36574877b4e2');
     $callback_arr = json_decode($callback, true);
     if (empty($callback_arr['result']) || !empty($callback_arr['status'])) {
         json_return(1, '地理位置解析错误,请重试!');
     } else {
         $long = $callback_arr['result'][0]['x'];
         $lat = $callback_arr['result'][0]['y'];
     }
     $database_store_contact = D('Store_contact');
     //$goods_list = D('')->table(array('Store_contact'=>'sc', 'Store'=>'s', 'Product' => 'p'))->field("`p`.*, ROUND(6378.138 * 2 * ASIN(SQRT(POW(SIN(({$lat}*PI()/180-`sc`.`lat`*PI()/180)/2),2)+COS({$lat}*PI()/180)*COS(`sc`.`lat`*PI()/180)*POW(SIN(({$long}*PI()/180-`sc`.`long`*PI()/180)/2),2)))*1000) AS juli")->where("`sc`.`store_id`=`s`.`store_id` AND `s`.`status`='1' and `p`.`is_recommend` = 1 AND p.supplier_id = 0")->group('p.store_id')->order("`juli` ASC")->limit(4)->select();
     $goods_list = array();
     $goods_list = D('')->table("Product as p")->join('Store as s ON s.store_id=p.store_id', 'LEFT')->join('Store_contact as sc ON sc.store_id=p.store_id', 'LEFT')->field("`p`.*, ROUND(6378.138 * 2 * ASIN(SQRT(POW(SIN(({$lat}*PI()/180-`sc`.`lat`*PI()/180)/2),2)+COS({$lat}*PI()/180)*COS(`sc`.`lat`*PI()/180)*POW(SIN(({$long}*PI()/180-`sc`.`long`*PI()/180)/2),2)))*1000) AS juli")->where("`s`.`status`='1' and `p`.`is_recommend` = 1 AND p.supplier_id = 0")->group('p.store_id')->order("`juli` asc")->limit(4)->select();
     foreach ($goods_list as $key => &$value) {
         /*if($value['juli'] > 200000){
         			unset($store_list[$key]);
         		} else {
Exemple #7
0
 public function wap_getStore($store_id)
 {
     $store = $this->db->where(array('store_id' => $store_id, 'status' => 1))->find();
     if (!empty($store)) {
         $_SESSION['tmp_store_id'] = $store_id;
         //解决用户访问不同店铺重复授权生成新用户问题
         /*if (empty($_SESSION['wap_user']) && !empty($_COOKIE['uid'])) { //COOKIE中有用户信息
               $tmp_user = M('User')->checkUser(array('uid' => $_COOKIE['uid']));
               if (!empty($tmp_user)) {
                   $_SESSION['wap_user'] = $tmp_user;
                   $tmp_seller = D('Store')->where(array('drp_supplier_id' => $store_id, 'uid' => $_COOKIE['uid'], 'status' => 1))->find();
                   if (!empty($tmp_seller)) {
                       $_SESSION['wap_drp_store'] = $tmp_seller;
                       if (!empty($tmp_seller['oauth_url'])) { //对接微店
                           $_SESSION['sync_user'] = true;
                       }
                   }
                   setcookie('uid', $_COOKIE['uid'], $_SERVER['REQUEST_TIME']+10000000, '/'); //延长cookie有效期
               } else {
                   unset($_SESSION['sync_user']); //删除同步标识
                   unset($_SESSION['wap_user']); //删除用户登录状态
               }
           }*/
         //判断是否为对接微店
         if (!empty($store['oauth_url'])) {
             if (!empty($_SESSION['wap_user']) && $_SESSION['wap_user']['store_id'] != $store_id) {
                 //非当前店铺粉丝,重新授权登陆
                 unset($_SESSION['sync_user']);
                 //删除同步标识
                 unset($_SESSION['wap_user']);
                 //删除用户登录状态
             }
         } else {
             unset($_SESSION['sync_user']);
             //非对接店铺 删除同步标识
         }
         //对接网站用户授权登陆
         //授权条件:非对接同步用户,是对接店铺,店铺管理后台未登录(不加此条件,店铺管理后台的所有链接无法在pc端打开,都会跳转授权)
         if (empty($_SESSION['sync_user']) && !empty($store['oauth_url']) && empty($_SESSION['sync_store'])) {
             $return_url = urlencode('http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
             if (!empty($store['oauth_url'])) {
                 if (stripos($store['oauth_url'], '?') === false) {
                     redirect($store['oauth_url'] . '?return_url=' . $return_url . '&store_id=' . $store_id . '&token=' . $store['token']);
                 } else {
                     redirect($store['oauth_url'] . '&return_url=' . $return_url . '&store_id=' . $store_id . '&token=' . $store['token']);
                 }
             }
         } else {
             if (empty($_SESSION['sync_user']) && empty($store['oauth_url']) && empty($_SESSION['store'])) {
                 //默认授权
                 //授权条件:非对接同步用户,非对接店铺,店铺管理后台未登录(不加此条件,店铺管理后台的所有链接无法在pc端打开,都会跳转授权)
                 /*是否移动端*/
                 $is_mobile = is_mobile();
                 /*是否微信端*/
                 $is_weixin = is_weixin();
                 //调试  清除登录信息
                 //setcookie('pigcms_sessionid','',$_SERVER['REQUEST_TIME']-10000000,'/');
                 //$_SESSION = null;
                 //session_destroy();
                 /*如果是微信端,且配置文件中配置了微信信息,得到openid*/
                 if ($is_weixin && (empty($_SESSION['openid']) || empty($_SESSION['wap_user']))) {
                     //openid存在 通过openid查找用户
                     if (!empty($_SESSION['openid'])) {
                         $userinfo = M('User')->get_user('openid', $_SESSION['openid']);
                         $_SESSION['wap_user'] = $userinfo['user'];
                         mergeSessionUserInfo(session_id(), $userinfo['user']['uid']);
                         unset($_SESSION['wap_drp_store']);
                     }
                     //用户未登录 调用授权获取openid, 通过openid查找用户,如果已经存在,设置登录,如果不存在,添加一个新用户和openid关联
                     if (empty($_SESSION['wap_user'])) {
                         $customeUrl = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
                         //判断店铺是否绑定过认证服务号
                         $wx_bind = D('Weixin_bind')->where(array('store_id' => $store['store_id']))->find();
                         if (empty($_GET['code'])) {
                             $_SESSION['weixin']['state'] = md5(uniqid());
                             if (!empty($wx_bind) && $wx_bind['service_type_info'] == 2 && $wx_bind['verify_type_info'] == 0) {
                                 $oauthUrl = 'https://open.weixin.qq.com/connect/oauth2/authorize?appid=' . $wx_bind['authorizer_appid'] . '&redirect_uri=' . urlencode($customeUrl) . '&response_type=code&scope=snsapi_userinfo&state=' . $_SESSION['weixin']['state'] . '&component_appid=' . option('config.wx_appid') . '#wechat_redirect';
                             } else {
                                 //店铺非认证服务号走总后台授权
                                 $oauthUrl = 'https://open.weixin.qq.com/connect/oauth2/authorize?appid=' . option('config.wechat_appid') . '&redirect_uri=' . urlencode($customeUrl) . '&response_type=code&scope=snsapi_userinfo&state=' . $_SESSION['weixin']['state'] . '#wechat_redirect';
                             }
                             redirect($oauthUrl);
                             exit;
                         } else {
                             if (isset($_GET['code']) && isset($_GET['state']) && $_GET['state'] == $_SESSION['weixin']['state']) {
                                 unset($_SESSION['weixin']);
                                 import('Http');
                                 $http = new Http();
                                 if (!empty($wx_bind) && $wx_bind['service_type_info'] == 2 && $wx_bind['verify_type_info'] == 0) {
                                     $component_token = M('Weixin_bind')->get_access_token($store['store_id'], true);
                                     $tokenUrl = 'https://api.weixin.qq.com/sns/oauth2/component/access_token?appid=' . $wx_bind['authorizer_appid'] . '&code=' . $_GET['code'] . '&grant_type=authorization_code&component_appid=' . option('config.wx_appid') . '&component_access_token=' . $component_token;
                                 } else {
                                     $tokenUrl = 'https://api.weixin.qq.com/sns/oauth2/access_token?appid=' . option('config.wechat_appid') . '&secret=' . option('config.wechat_appsecret') . '&code=' . $_GET['code'] . '&grant_type=authorization_code';
                                 }
                                 $return = $http->curlGet($tokenUrl);
                                 $jsonrt = json_decode($return, true);
                                 if ($jsonrt['errcode']) {
                                     $error_msg_class = new GetErrorMsg();
                                     exit('授权发生错误:' . $jsonrt['errcode']);
                                 }
                                 if ($jsonrt['openid']) {
                                     //微信中打开直接登陆
                                     $url = 'https://api.weixin.qq.com/sns/userinfo?access_token=' . $jsonrt['access_token'] . '&openid=' . $jsonrt['openid'] . '&lang=zh_CN';
                                     $wxuser = $http->curlGet($url);
                                     $wxuser = json_decode($wxuser, true);
                                     $_SESSION['openid'] = $jsonrt['openid'];
                                     $userinfo = M('User')->get_user('openid', $_SESSION['openid']);
                                     if (empty($userinfo['user'])) {
                                         //用户不存在,添加新用户,并设置登录
                                         $data = array();
                                         $data['phone'] = '';
                                         $data['nickname'] = $wxuser['nickname'];
                                         $data['openid'] = $_SESSION['openid'];
                                         $data['avatar'] = $wxuser['headimgurl'];
                                         $data['password'] = '';
                                         $data['check_phone'] = 1;
                                         $data['login_count'] = 1;
                                         $add_result = M('User')->add_user($data);
                                         if ($add_result['err_code'] == 0) {
                                             $_SESSION['wap_user'] = $add_result['err_msg'];
                                             $_SESSION['wap_user']['sex'] = $wxuser['sex'];
                                             $_SESSION['wap_user']['province'] = $wxuser['province'];
                                             $_SESSION['wap_user']['city'] = $wxuser['city'];
                                             mergeSessionUserInfo(session_id(), $add_result['err_msg']['uid']);
                                         }
                                     } else {
                                         //用户已存在,设置登录
                                         $_SESSION['wap_user'] = $userinfo['user'];
                                         $_SESSION['wap_user']['sex'] = $wxuser['sex'];
                                         $_SESSION['wap_user']['province'] = $wxuser['province'];
                                         $_SESSION['wap_user']['city'] = $wxuser['city'];
                                         mergeSessionUserInfo(session_id(), $userinfo['user']['uid']);
                                     }
                                     unset($_SESSION['wap_drp_store']);
                                     //删除保存在session中的分销店铺
                                 }
                             }
                         }
                     }
                 }
                 //}
             }
         }
         $store['url'] = option('config.wap_site_url') . '/home.php?id=' . $store['store_id'];
         if (empty($store['logo'])) {
             $store['logo'] = getAttachmentUrl('images/default_shop_2.jpg', false);
         } else {
             if (stripos($store['logo'], 'http://') === false && stripos($store['logo'], 'https://') === false) {
                 $store['logo'] = getAttachmentUrl($store['logo']);
             }
         }
         $store['ucenter_url'] = option('config.wap_site_url') . '/ucenter.php?id=' . $store['store_id'];
         $store['physical_url'] = option('config.wap_site_url') . '/physical.php?id=' . $store['store_id'];
         option('now_store', $store);
     }
     return $store;
 }
Exemple #8
0
                         $data["msg"] = $langArray['update_ok'];
                     }
                 }
             } else {
                 $data["msg"] = $langArray['update_none'];
             }
         }
     }
 } else {
     if (substr(sprintf('%o', fileperms($_SERVER['DOCUMENT_ROOT'])), -4) != '0777') {
         $data["msg"] = $langArray['update_server'];
     } else {
         require_once ROOT_PATH . '/classes/Http.class.php';
         $http = new Http();
         $url = $langArray['index'] . '/getversion';
         $version = $http->curlGet($url);
         $version = strstr($version, '[{');
         $version = json_decode($version, 1);
         $version = $version[0]["content"];
         $link = langMessageReplace($langArray['update_add'], array('version' => $version));
         if (file_exists("update.zip")) {
             unlink('update.zip');
         }
         $state = getFile($link, $config['root_path'], 'update.zip', 0);
         if ($state) {
             $data["msg"] = $langArray['update_none'];
             require_once $config['root_path'] . '/core/classes/pclzip.lib.php';
             $zip = new PclZip($config['root_path'] . '/update.zip');
             $zip->extract();
             if ($zip->extract() == 0) {
                 $data["msg"] = $langArray['update_none'];
Exemple #9
0
     // dump($_SESSION);
     $weixin_bind_info = D('Weixin_bind')->where(array('store_id' => $now_store['store_id']))->find();
     // dump($weixin_bind_info);
     if ($weixin_bind_info && $weixin_bind_info['wxpay_mchid'] && $weixin_bind_info['wxpay_key']) {
         if (empty($_GET['code'])) {
             $_SESSION['store_weixin_state'] = md5(uniqid());
             //代店铺发起获取openid
             redirect('https://open.weixin.qq.com/connect/oauth2/authorize?appid=' . $weixin_bind_info['authorizer_appid'] . '&redirect_uri=' . urlencode($config['site_url'] . $_SERVER['REQUEST_URI']) . '&response_type=code&scope=snsapi_base&state=' . $_SESSION['store_weixin_state'] . '&component_appid=' . $config['wx_appid'] . '#wechat_redirect');
         } else {
             if (isset($_GET['code']) && isset($_GET['state']) && $_GET['state'] == $_SESSION['store_weixin_state']) {
                 import('Http');
                 $component_access_token_arr = M('Weixin_bind')->get_access_token($now_store['store_id'], true);
                 if ($component_access_token_arr['errcode']) {
                     pigcms_tips('与微信通信失败,请重试。');
                 }
                 $result = Http::curlGet('https://api.weixin.qq.com/sns/oauth2/component/access_token?appid=' . $weixin_bind_info['authorizer_appid'] . '&code=' . $_GET['code'] . '&grant_type=authorization_code&component_appid=' . $config['wx_appid'] . '&component_access_token=' . $component_access_token_arr['component_access_token']);
                 $result = json_decode($result, true);
                 if ($result['errcode']) {
                     pigcms_tips('微信返回系统繁忙,请稍候再试。微信错误信息:' . $result['errmsg']);
                 }
                 $storeOpenid = $result['openid'];
                 if (!D('Order')->where(array('order_id' => $nowOrder['order_id']))->data(array('useStorePay' => '1', 'storeOpenid' => $storeOpenid, 'trade_no' => date('YmdHis', $_SERVER['REQUEST_TIME']) . mt_rand(100000, 999999)))->save()) {
                     pigcms_tips('订单信息保存失败,请重试。');
                 }
                 $payMethodList['weixin']['name'] = '微信安全支付';
                 $payList[0] = $payMethodList['weixin'];
                 $useStorePay = true;
             }
         }
     }
 } else {