Inheritance: extends CI_Controller
Esempio n. 1
0
 function _initialize()
 {
     parent::_initialize();
     if (!$this->_userid) {
         header("Location: " . U('User/Login/index'));
         exit;
     }
     $this->dao = M('User');
     $this->assign('bcid', 0);
     $user = $this->dao->find($this->_userid);
     if (empty($user["wxpas"])) {
         $himt = "<script type=\"text/javascript\">\$(document).ready(function(){alert(\"你还没绑定微信请扫描二维码绑定!\");});</script>";
         $this->assign("himt", $himt);
     }
     $user["username"] = $user["realname"] != "" ? $user["realname"] . "[" . $user["username"] . "]" : $user["username"];
     //////////////获得绑定二维码
     import("@.ORG.Weixin");
     $wechatObj = new Wechat();
     $user["ticket"] = $wechatObj->ewm($user["id"], 0);
     //////////////获得绑定二维码
     $this->user = $user;
     $this->assign('vo', $user);
     unset($_POST['status']);
     unset($_POST['groupid']);
     unset($_POST['amount']);
     unset($_POST['point']);
     $_GET = get_safe_replace($_GET);
     $order["count"] = M("order")->where(array('status' => 0, 'userid' => $this->_userid))->count();
     $order["all"] = M("order")->where(array('userid' => $this->_userid))->count();
     $order["ok"] = M("order")->where(array('status' => 1, 'userid' => $this->_userid))->count();
     $this->assign('order', $order);
     $this->assign('actionname', ACTION_NAME);
 }
Esempio n. 2
0
 public function index()
 {
     $thisurl = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
     $rt = explode('index.php', $thisurl);
     $arg = isset($rt[1]) ? $rt[1] : '';
     if (!empty($arg)) {
         $rt = explode('/', $arg);
         $arg = isset($rt[1]) ? $rt[1] : '';
         if (!empty($arg)) {
             $this->token = trim($arg);
         }
     }
     if (!class_exists('SimpleXMLElement')) {
         exit('SimpleXMLElement class not exist');
     }
     if (!function_exists('dom_import_simplexml')) {
         exit('dom_import_simplexml function not exist');
     }
     if (!preg_match("/^[0-9a-zA-Z]{3,42}\$/", $this->token)) {
         exit('error token');
     }
     $weixin = new Wechat($this->token);
     $this->data = $weixin->request();
     if ($this->data) {
         list($content, $type) = $this->reply($this->data);
         $weixin->response($content, $type);
     }
 }
 function index()
 {
     if (!session('openid_' . $this->token)) {
         $this->info = M('wxuser')->where(array('token' => $this->token))->find();
         vendor("Oauth2.OAuth2", LIB_PATH . '../Extend/Vendor');
         vendor("Oauth2.Provider.Wechat", LIB_PATH . '../Extend/Vendor');
         $wechat = new Wechat();
         $wechat->config(array('id' => $this->info['appid'], 'secret' => $this->info['appsecret']));
         $redirect_uri = C('site_url') . '/index.php/Wap/Login/index?token=' . $this->token . '&url=' . $this->url;
         if (!$_GET['code']) {
             // By sending no options it'll come back here
             $url = $wechat->authorize(array('redirect_uri' => $redirect_uri));
             redirect($url);
         } else {
             try {
                 // Have a go at creating an access token from the code
                 $access_token = $wechat->access($_GET['code'], array('redirect_uri' => $redirect_uri));
                 // Use this object to try and get some user details (username, full name, etc)
                 $user = $wechat->get_user_info($access_token);
                 $this->save_wechat_user($user);
                 session('openid_' . $this->token, $user->openid);
             } catch (OAuth2_Exception $e) {
                 print_r($e);
                 die;
             }
         }
     }
     if ($this->url) {
         redirect($this->url);
     }
 }
Esempio n. 4
0
 public function index()
 {
     if (!class_exists('SimpleXMLElement')) {
         exit('SimpleXMLElement class not exist');
     }
     if (!function_exists('dom_import_simplexml')) {
         exit('dom_import_simplexml function not exist');
     }
     $this->token = $this->_get('token', "htmlspecialchars");
     if (!preg_match("/^[0-9a-zA-Z]{3,42}\$/", $this->token)) {
         exit('error token');
     }
     $weixin = new Wechat($this->token);
     $data = $weixin->request();
     $this->data = $weixin->request();
     $this->fans = S('fans_' . $this->token . '_' . $this->data['FromUserName']);
     if (!$this->fans || 1) {
         $this->fans = M('Userinfo')->where(array('token' => $this->token, 'wecha_id' => $this->data['FromUserName']))->find();
         S('fans_' . $this->token . '_' . $this->data['FromUserName'], $this->fans);
     }
     $this->wxuser = S('wxuser_' . $this->token);
     if (!$this->wxuser || 1) {
         $this->wxuser = D('Wxuser')->where(array('token' => $this->token))->find();
         S('wxuser_' . $this->token, $this->wxuser);
     }
     $this->my = C('site_my');
     $this->apiServer = apiServer::getServerUrl();
     $open = M('Token_open')->where(array('token' => $this->_get('token')))->find();
     $this->fun = $open['queryname'];
     list($content, $type) = $this->reply($data);
     $weixin->response($content, $type);
 }
Esempio n. 5
0
 public function index()
 {
     $this->token = $this->_get('token');
     $this->my = C('site_my');
     #        Log::record('weixinmsg',Log::DEBUG);
     #       Log::record('weixinmsg',$this->token,Log::DEBUG);
     #      Log::save();
     #     $this->siteName = C('site_name');
     $weixin = new Wechat($this->token);
     //$data = $weixin->request();
     //$this->xml = $weixin->xml;
     $this->data = $weixin->request();
     //是否是在上墙中
     if ($this->data) {
         $data = $this->data;
         $users = S($data['FromUserName'] . 'wxq');
         if ($users != false) {
             $res = $this->wxq($users);
         } else {
             $res = $this->reply($data);
         }
         list($content, $type) = $res;
         $weixin->response($content, $type);
     }
 }
 public function index()
 {
     if (!session('openid_' . $this->token)) {
         $this->info = M('wxuser')->where(array('token' => $this->token))->find();
         vendor("Oauth2.OAuth2", LIB_PATH . '../Extend/Vendor');
         vendor("Oauth2.Provider.Wechat", LIB_PATH . '../Extend/Vendor');
         $wechat = new Wechat();
         $wechat->config(array('id' => $this->info['appid'], 'secret' => $this->info['appsecret']));
         $redirect_uri = C('site_url') . '/index.php/Wap/Coupons/index?token=' . $this->token . '&coupon_id=' . $this->coupon_id;
         if (!$_GET['code']) {
             // By sending no options it'll come back here
             $url = $wechat->authorize(array('redirect_uri' => $redirect_uri));
             redirect($url);
         } else {
             try {
                 // Have a go at creating an access token from the code
                 $token = $wechat->access($_GET['code'], array('redirect_uri' => $redirect_uri));
                 // Use this object to try and get some user details (username, full name, etc)
                 $user = $wechat->get_user_info($token);
                 $this->openid = $user->openid;
                 session('openid_' . $this->token, $user->openid);
             } catch (OAuth2_Exception $e) {
                 print_r($e);
                 die;
             }
         }
     } else {
         $this->openid = session('openid_' . $this->token);
     }
     $url = C('site_url') . "/index.php?g=Wap&m=Coupon&a=index&type=1&token=" . $this->token . '&id=' . $this->coupon_id . '&wecha_id=' . $this->openid;
     header('Location:' . $url);
 }
 public function Oauth2()
 {
     if (!session('openid_' . $this->token)) {
         $this->info = M('wxuser')->where(array('token' => $this->token))->find();
         vendor("Oauth2.OAuth2", LIB_PATH . '../Extend/Vendor');
         vendor("Oauth2.Provider.Wechat", LIB_PATH . '../Extend/Vendor');
         $wechat = new Wechat();
         $wechat->config(array('id' => $this->info['appid'], 'secret' => $this->info['appsecret']));
         $redirect_uri = $_GET['method_name'];
         if (!$_GET['code']) {
             $redirect_uri = C('site_url') . '/index.php/Fxs/Fxs/Oauth2?token=' . $this->token . '&method_name=' . $_GET['method_name'];
             // By sending no options it'll come back here
             $url = $wechat->authorize(array('redirect_uri' => $redirect_uri));
             redirect($url);
         } else {
             try {
                 // Have a go at creating an access token from the code
                 $token = $wechat->access($_GET['code'], array('method_name' => $redirect_uri));
                 // Use this object to try and get some user details (username, full name, etc)
                 $user = $wechat->get_user_info($token);
                 session('openid_' . $this->token, $user->openid);
             } catch (OAuth2_Exception $e) {
                 print_r($e);
                 die;
             }
         }
     }
     if (session('openid_' . $this->token)) {
         $user = M('reguser')->where(array('token' => $this->token, 'openid' => session('openid_' . $this->token)))->find();
         if (!$user) {
             session_destroy();
         }
     }
     header('Location:' . U('Fxs/' . $_GET['method_name'], array('token' => $this->token)));
 }
 function updatefeedback()
 {
     $id = $this->_get('id', 'intval');
     header('Content-Type:text/html;charset=utf-8');
     $wetallroute = dirname(dirname(dirname(dirname(dirname(__FILE__)))));
     //dump($wetallroute);exit;
     include $wetallroute . "/wxpay/config.php";
     //dump($config);exit;
     include $wetallroute . "/wxpay/lib.php";
     $wechat = new Wechat();
     // openid 与 feedback参数都可以从数据库中得到
     $feedback = $this->_mod->where(array('id' => $id))->find();
     //dump($feedback);exit;
     //$content = 'http://api.weixin.qq.com/cgi-bin/pay/delivernotify?access_token=' . $wechat->getAccessToken($config) . '&openid=' . $feedback['openid'] . '&feedbackid=' . $feedback['feedbackid'];
     $content = 'https://api.weixin.qq.com/payfeedback/update?access_token=' . $wechat->getAccessToken($config) . '&openid=' . $feedback['openid'] . '&feedbackid=' . $feedback['feedbackid'];
     //dump($content);
     $result = $wechat->curlGet($content);
     //dump($result);exit;
     $result = json_decode($result, true);
     if ($result['errcode'] == 0) {
         //echo 'success';
         //IS_AJAX && $this->ajaxReturn(1, $result['errmsg'], '', 'edit');
         $this->_mod->where(array('id' => $id))->save(array('status' => 1));
         $this->success('通知微信成功!');
     } elseif ($result['errcode'] == -1 && $result['errmsg'] == 'system error') {
         $this->_mod->where(array('id' => $id))->save(array('status' => 1));
         $this->success('已经通知过微信,更改状态成功!');
     } else {
         //IS_AJAX && $this->ajaxReturn(0, $result['errmsg']);
         $this->error($result['errmsg']);
     }
 }
Esempio n. 9
0
 function send()
 {
     $u = M("user")->where(array(id => intval($_REQUEST['id'])))->find();
     import("@.ORG.Weixin");
     $wechatObj = new Wechat();
     $data = " {\r\n           \"touser\":\"" . $u['wxpas'] . "\",\r\n           \"template_id\":\"SCFdz1m9pGOO6U-LXp6qv8CUJakT3_Zk-74tjdnK0ok\",\r\n           \"url\":\"http://weixin.qq.com/download\",\r\n           \"topcolor\":\"#FF0000\",\r\n           \"data\":{\r\n                   \"first\": {\r\n                       \"value\":\"恭喜你购买成功!\",\r\n                       \"color\":\"#173177\"\r\n                   },\r\n                   \"keyword1\":{\r\n                       \"value\":\"" . $u['realname'] . "\",\r\n                       \"color\":\"#173177\"\r\n                   },\r\n                   \"keynote2\": {\r\n                       \"value\":\"" . $u['id'] . "产品名称\",\r\n                       \"color\":\"#173177\"\r\n                   },\r\n                   \"keynote3\": {\r\n                       \"value\":\"" . $u['id'] . "\",\r\n                       \"color\":\"#173177\"\r\n                   },\r\n                   \"remark\":{\r\n                       \"value\":\"此订单信息请点击这里查看!!\",\r\n                       \"color\":\"#173177\"\r\n                   }\r\n           }\r\n       }";
     echo $wechatObj->tplmsg($data);
 }
Esempio n. 10
0
 public function index()
 {
     $this->token = 'cmgeshengli';
     $weixin = new \Wechat($this->token);
     $this->data = $weixin->request();
     list($content, $type) = $this->reply($this->data);
     $weixin->response($content, $type);
 }
Esempio n. 11
0
 public function wxoauth()
 {
     $scope = 'snsapi_base';
     $code = isset($_GET['code']) ? $_GET['code'] : '';
     $token_time = isset($_SESSION['token_time']) ? $_SESSION['token_time'] : 0;
     if (!$code && isset($_SESSION['open_id']) && isset($_SESSION['user_token']) && $token_time > time() - 3600) {
         if (!$this->wxuser) {
             $this->wxuser = $_SESSION['wxuser'];
         }
         $this->open_id = $_SESSION['open_id'];
         return $this->open_id;
     } else {
         $options = array('token' => $this->options["token"], 'appid' => $this->options["appid"], 'appsecret' => $this->options["appsecret"]);
         $we_obj = new Wechat($options);
         if ($code) {
             $json = $we_obj->getOauthAccessToken();
             if (!$json) {
                 unset($_SESSION['wx_redirect']);
                 die('获取用户授权失败,请重新确认');
             }
             $_SESSION['open_id'] = $this->open_id = $json["openid"];
             $access_token = $json['access_token'];
             $_SESSION['user_token'] = $access_token;
             $_SESSION['token_time'] = time();
             $userinfo = $we_obj->getUserInfo($this->open_id);
             if ($userinfo && !empty($userinfo['nickname'])) {
                 $this->wxuser = array('open_id' => $this->open_id, 'nickname' => $userinfo['nickname'], 'sex' => intval($userinfo['sex']), 'location' => $userinfo['province'] . '-' . $userinfo['city'], 'avatar' => $userinfo['headimgurl']);
             } elseif (strstr($json['scope'], 'snsapi_userinfo') !== false) {
                 $userinfo = $we_obj->getOauthUserinfo($access_token, $this->open_id);
                 if ($userinfo && !empty($userinfo['nickname'])) {
                     $this->wxuser = array('open_id' => $this->open_id, 'nickname' => $userinfo['nickname'], 'sex' => intval($userinfo['sex']), 'location' => $userinfo['province'] . '-' . $userinfo['city'], 'avatar' => $userinfo['headimgurl']);
                 } else {
                     return $this->open_id;
                 }
             }
             if ($this->wxuser) {
                 $_SESSION['wxuser'] = $this->wxuser;
                 $_SESSION['open_id'] = $json["openid"];
                 unset($_SESSION['wx_redirect']);
                 return $this->open_id;
             }
             $scope = 'snsapi_userinfo';
         }
         if ($scope == 'snsapi_base') {
             $url = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
             $_SESSION['wx_redirect'] = $url;
         } else {
             $url = $_SESSION['wx_redirect'];
         }
         if (!$url) {
             unset($_SESSION['wx_redirect']);
             die('获取用户授权失败');
         }
         $oauth_url = $we_obj->getOauthRedirect($url, "wxbase", $scope);
         header('Location: ' . $oauth_url);
     }
 }
 public function __construct(Wechat $wechat)
 {
     $this->content = $wechat->getRev()->getRevContent();
     $this->sender = $wechat->getRev()->getRevFrom();
     $this->create_time = $wechat->getRev()->getRevCtime();
     $this->msg_id = $wechat->getRev()->getRevID();
     $this->models = new TextModel();
     $this->models->actionIndex($this->content, $this->sender, $this->msg_id);
 }
Esempio n. 13
0
 public function index()
 {
     $this->token = $this->_get('token');
     $weixin = new Wechat($this->token);
     $data = $weixin->request();
     $this->data = $weixin->request();
     $this->my = C('site_my');
     list($content, $type) = $this->reply($data);
     $weixin->response($content, $type);
 }
Esempio n. 14
0
function send_wechat_msg_pe($staff_openid, $template_id, $url_ticket_id, $first_data, $remark_data, $keyword1_data, $keyword2_data, $keyword3_data = null)
{
    $notice_data = ["touser" => $staff_openid, "template_id" => $template_id, "url" => "https://wechat.gds-services.com/static/html/query_req_detail.html?tid=" . $url_ticket_id, "topcolor" => "#000", "data" => ["first" => ["value" => $first_data, "color" => "#000"], "remark" => ["value" => $remark_data, "color" => "#000"], "keyword1" => ["value" => $keyword1_data, "color" => "#000"], "keyword2" => ["value" => $keyword2_data, "color" => "#000"]]];
    if (!empty($keyword3_data) && $keyword3_data != null) {
        $notice_data->data->keyword3 = ["value" => $keyword3_data, "color" => "#000"];
    }
    $options = ['token' => 'nizhidaoma', 'encodingaeskey' => 'IXR7m0K8Q7KOIC4z9s1CRHNQBqrJfFGTUT86CECPaXM', 'appid' => 'wx6bc0c53a3a1c150d', 'appsecret' => '3888ccc01ec4e5d6e0e673308e92e627', 'debug' => true, 'logcallback' => '_log'];
    include dirname(__FILE__) . "/../qy-sdk/wechat.class.php";
    $weObj = new Wechat($options);
    return $weObj->sendTemplateMessage($notice_data);
}
Esempio n. 15
0
 public function index()
 {
     $wechat = new Wechat($this->config);
     $data = $wechat->request();
     list($content, $type) = $this->reply($data);
     if (!empty($content)) {
         $wechat->response($content, $type);
     } else {
         exit;
     }
 }
Esempio n. 16
0
 public function index()
 {
     import("@.ORG.Weixin");
     $config = $this->Config;
     $wxconfig = F("wxconfig");
     $user = M("user");
     $data = array();
     $wechatObj = new Wechat();
     if ($wxconfig["wstatu"] != "") {
         $data = $wechatObj->responseMsg($idx);
         //接收到的
         $me = $data['me'];
         $guest = $data['user'];
         //////////////////////*用户打入库-开始*///////////////
         $this->adduser($guest);
         if ($data['key'] == "ewm") {
             $ewm = $wechatObj->ewm(2, 1);
             $wechatObj->sendtext($guest, $me, $ewm);
         }
         $wechatObj->sendtext($guest, $me, $guest);
         exit;
         ///////////////////////////////事件开始/////////////////////////
         if ($data['type'] == "event") {
             //关注
             if ($data['event'] == "subscribe" || $data['event'] == "SCAN") {
                 if ($data['key'] == 1) {
                     $user = M("user")->where("wxid='" . sysmd5($guest) . "'")->setfield('vip', 1);
                     $map1['url'] = "http://mall.bydauto.com.cn/echo/index/store";
                     $map1['title'] = "vip会议标题['待定..']";
                     $map1['description'] = "描述的文字['待定..'],点击进去的链接待定,下面的图片大小700x400";
                     $map1['thumb'] = "http://byd.gzqizhen.com/Public/byd/byd.jpg";
                     $wechatObj->sendimg($guest, $me, $map1);
                     exit;
                 }
                 if ($data['key'] == 2) {
                     $vip = M("user")->where("wxid='" . sysmd5($guest) . "'")->getfield('vip');
                     if (!$vip) {
                         $user = M("user")->where("wxid='" . sysmd5($guest) . "'")->setfield('vip', 2);
                     }
                     $map2['url'] = "http://mall.bydauto.com.cn/echo/index/store";
                     $map2['title'] = "新能源['待定..']";
                     $map2['description'] = "描述的文字['待定..']下面的图片大小700x400";
                     $map2['thumb'] = "http://byd.gzqizhen.com/Public/byd/byd.jpg";
                     $wechatObj->sendimg($guest, $me, $map2);
                     // $wechatObj->sendtext($guest,$me,"新能源");
                     exit;
                 }
             }
         }
         ///////////////////////////////事件结束/////////////////////////
         $wechatObj->sendimg($guest, $me, $wxconfig);
     } else {
         M("config")->where("varname='wstatu'")->setField('value', "清理此位置可以重新设置微信接入!");
         $wechatObj->valid($wxconfig["token"]);
         savecache("Config");
     }
 }
Esempio n. 17
0
function showTip($smarty, $tip, $db, $title)
{
    $options = array('token' => WX_TOKEN, 'appid' => WX_APPID, 'encodingaeskey' => '6pnP7qHyqJ1kFXMjuO4Z3QrpOa9WfapsgkPOtXoZKC2', 'appsecret' => WX_SECRET, 'logcallback' => logdebug);
    $we = new Wechat($options);
    $auth = $we->checkAuth();
    $js_ticket = $we->getJsTicket();
    $smarty->assign('tip', $tip);
    $smarty->assign('title', $title);
    $url = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
    $smarty->assign('js_sign', $we->getJsSign($url));
    $smarty->display('templates/tip.html');
    $db->disconnect();
    die;
}
Esempio n. 18
0
 public function index()
 {
     import('Vendor.Wechat.Wechat');
     $option = array('token' => 'weixin', 'appid' => 'wx444c22311a33b40d', 'secret' => 'f39ae15e9d86c293edbff26a9c47af6e');
     $wechatObj = new \Wechat($option);
     $wechatObj->valid();
     //解析来向XML
     $msg = $wechatObj->getRev();
     $message['fromUsername'] = $msg->getRevFrom();
     $message['toUsername'] = $msg->getRevTo();
     $message['type'] = $msg->getRevType();
     $message['createtime'] = $msg->getRevCtime();
     $message['keyword'] = $msg->getRevContent();
     $message['event'] = $msg->getRevEvent();
     //保存新用户相关信息
     $status = D('Member');
     $status->InsertNewer($message['fromUsername']);
     //主要部分,暂时仅使用TEXT,EVENT两种
     switch ($message['type']) {
         case $wechatObj::MSGTYPE_TEXT:
             $text = A('Text');
             $ret = $text->textSkip($message);
             if ('text' == $ret['type']) {
                 $wechatObj->text($ret['content'])->reply();
             } else {
                 if ('news' == $ret['type']) {
                     $wechatObj->news($ret['content'])->reply();
                 }
             }
             break;
         case $wechatObj::MSGTYPE_EVENT:
             $event = A('Event');
             $ret = $event->eventSkip($message);
             if ('text' == $ret['type']) {
                 $wechatObj->text($ret['content'])->reply();
             } else {
                 if ('news' == $ret['type']) {
                     $wechatObj->news($ret['content'])->reply();
                 }
             }
             break;
         default:
             $wechatObj->text('更多功能正在研发中,敬请期待')->reply();
     }
     //获取菜单
     $menu = $wechatObj->getMenu();
     //创建菜单
     $newmenu = array('小瓜神力' => array(array('type' => 'click', 'name' => '新生专题', 'key' => 'V1001_01_01'), array('type' => 'click', 'name' => '校车时刻', 'key' => 'V1001_01_02'), array('type' => 'click', 'name' => '交通导航', 'key' => 'V1001_01_03'), array('type' => 'click', 'name' => '考试成绩', 'key' => 'V1001_01_04'), array('type' => 'click', 'name' => '图书信息', 'key' => 'V1001_01_05')), '军训专题' => array(array('type' => 'click', 'name' => '通知公告', 'key' => 'V1001_02_01'), array('type' => 'click', 'name' => '军训快报', 'key' => 'V1001_02_02'), array('type' => 'click', 'name' => '军营风采', 'key' => 'V1001_02_03'), array('type' => 'view', 'name' => '军歌嘹亮', 'url' => 'http://mp.weixin.qq.com/s?__biz=MjM5OTIxMTM2Mg==&mid=209183345&idx=1&sn=96c4cf9ad618e5e051167456210d9fe8&scene=5&srcid=OJ8qMfaW9nS5T0jFFjQj#rd'), array('type' => 'click', 'name' => '微军训', 'key' => 'V1001_02_05')), '小瓜威武' => array(array('type' => 'click', 'name' => '小瓜在线', 'key' => 'V1001_03_01'), array('type' => 'click', 'name' => '跑操查询', 'key' => 'V1001_03_02'), array('type' => 'view', 'name' => '瓜棚论坛', 'url' => 'http://npuxiaogua.mgschool.cn/wx/apps/liuyan/'), array('type' => 'view', 'name' => '失物招领', 'url' => 'http://npuxiaogua.mgschool.cn/wx/npuxg_blog/wxq/index.php'), array('type' => 'click', 'name' => '表白墙', 'key' => 'V1001_03_05')));
     $result = $wechatObj->createMenu($newmenu);
 }
Esempio n. 19
0
 /**
  * 初始化,判断此次请求是否为验证请求,并以数组形式保存
  *
  * @param string $token 验证信息
  * @param boolean $debug 调试模式,默认为关闭
  */
 public function __construct($token, $fromtype, $debug = FALSE)
 {
     if (!empty($_GET["version"])) {
         $ver = new version();
         $ver->verSions();
     }
     if (!$this->validateSignature($token)) {
         exit('签名验证失败');
     }
     if ($this->isValid()) {
         // 网址接入验证
         exit($_GET['echostr']);
     }
     if (!isset($GLOBALS['HTTP_RAW_POST_DATA'])) {
         exit('缺少数据');
     }
     set_error_handler(array(&$this, 'errorHandler'));
     // 设置错误处理函数,将错误通过文本消息回复显示
     //file_put_contents('s.txt',$GLOBALS['HTTP_RAW_POST_DATA']);
     $xml = (array) simplexml_load_string($GLOBALS['HTTP_RAW_POST_DATA'], 'SimpleXMLElement', LIBXML_NOCDATA);
     //file_put_contents('s.txt',$xml);
     $this->request = array_change_key_case($xml, CASE_LOWER);
     // 将数组键名转换为小写,提高健壮性,减少因大小写不同而出现的问题
     Wechat::$fromtype = $fromtype;
     $this->debug = $debug;
 }
Esempio n. 20
0
 public function notify(Request $request)
 {
     \Log::debug('payment_notify', ['request' => $request]);
     $input = XML::parse($request->getContent());
     if ($input['return_code'] == 'SUCCESS') {
         $order = Order::where('wx_out_trade_no', $input['out_trade_no'])->firstOrFail();
         $address_id = $order->address_id;
         # 当前订单收货地址id
         if ($order->isPaid()) {
             return 'FAIL';
         }
         $order->update(['wx_transaction_id' => $input['transaction_id'], 'cash_payment' => floatval($input['total_fee']) / 100.0]);
         $order->paid();
         /*  发送消息提醒 */
         $default_address = Address::where(['id' => $address_id])->first();
         $phone = $default_address->phone;
         $msg = '尊敬的顾客您好!您的订单已经收到,易康商城将尽快为您安排发货,如有任何问题可以拨打客服电话400-1199-802进行咨询,感谢您的惠顾!';
         \MessageSender::sendMessage($phone, $msg);
         //            if ($phone = env('ORDER_ADMIN_PHONE')) {
         //                \Log::error($phone);
         //                \MessageSender::sendMessage($phone, $order->toOrderMessageString());
         //            }
         $result = \Wechat::paymentNotify();
         return $result;
     }
     return 'FAIL';
 }
Esempio n. 21
0
 public function index() {
     $this->token = $this->_get('token', "htmlspecialchars");
     if (!preg_match("/^[0-9a-zA-Z]{3,42}$/", $this->token)) {
         exit('error token');
     }
     $weixin = new Wechat($this->token);
     $data = $weixin->request();
     $this->data = $weixin->request();
     $this->my = C('site_my');
     $open = M('Token_open')->where(array(
         'token' => $this->_get('token')
     ))->find();
     $this->fun = $open['queryname'];
     list($content, $type) = $this->reply($data);
     $weixin->response($content, $type);
 }
Esempio n. 22
0
 /**
  * 接收微信服务器消息的入口函数
  */
 public function index()
 {
     try {
         $wechat = new Wechat(TOKEN, APPID, EncodingAESKey);
         /* 加载微信SDK */
         $data = $wechat->request();
         /* 获取请求信息 */
         if ($data && is_array($data)) {
             file_put_contents('./data.json', json_encode($data));
             //记录微信推送过来的数据
             $this->response($wechat, $data);
             //对消息做出响应
         }
     } catch (\Exception $e) {
         file_put_contents('./error.json', json_encode($e->getMessage()));
     }
 }
Esempio n. 23
0
 public function vote_replay()
 {
     $from = $this->from;
     //投票函数
     $reply = array(new NewsResponseItem('点击进入投票', '点击本模块进入投票!', Web_ROOT . '/vote/images/voteshow.jpg', Web_ROOT . "/vote/index.php?wecha_id={$from}"));
     Wechat::$noendtail = 0;
     return $reply;
 }
 public function __construct($options)
 {
     $this->cachedir = isset($options['cachedir']) ? dirname($options['cachedir'] . '/.cache') . '/' : 'cache/';
     $this->logfile = isset($options['logfile']) ? $options['logfile'] : '';
     if ($this->cachedir) {
         $this->checkDir($this->cachedir);
     }
     parent::__construct($options);
 }
Esempio n. 25
0
 public function index()
 {
     $this->siteUrl = C('site_url');
     if (!class_exists('SimpleXMLElement')) {
         exit('SimpleXMLElement class not exist');
     }
     if (!function_exists('dom_import_simplexml')) {
         exit('dom_import_simplexml function not exist');
     }
     $this->token = $this->_get('token', "htmlspecialchars");
     if ($this->token == 'pigcms' || $this->token == 'qcloud') {
         $qcloudUser = M('Qcloud_user')->where(array('openid' => $this->_get('openId')))->find();
         $this->token = $qcloudUser['token'];
     }
     if (!preg_match("/^[0-9a-zA-Z]{3,42}\$/", $this->token)) {
         exit('error token');
     }
     $weixin = new Wechat($this->token, $this->wxuser);
     $this->wxuser = S('wxuser_' . $this->token);
     if (!$this->wxuser || 1) {
         $this->wxuser = D('Wxuser')->where(array('token' => $this->token))->find();
         if (C('agent_version') && intval($this->wxuser['agentid'])) {
             $thisAgent = M('Agent')->where(array('id' => $this->wxuser['agentid']))->find();
             $this->siteUrl = $thisAgent['siteurl'];
         }
         S('wxuser_' . $this->token, $this->wxuser);
     }
     $this->user = M('Users')->where(array('id' => $this->wxuser['uid']))->find();
     $weixin = new Wechat($this->token, $this->wxuser);
     $data = $weixin->request();
     $this->data = $weixin->request();
     $this->fans = S('fans_' . $this->token . '_' . $this->data['FromUserName']);
     if (!$this->fans || 1) {
         $this->fans = M('Userinfo')->where(array('token' => $this->token, 'wecha_id' => $this->data['FromUserName']))->find();
         S('fans_' . $this->token . '_' . $this->data['FromUserName'], $this->fans);
     }
     //自定义机器人名字
     $this->my = C('site_my');
     $this->apiServer = apiServer::getServerUrl();
     $open = M('Token_open')->where(array('token' => $this->_get('token')))->find();
     $this->fun = $open['queryname'];
     list($content, $type) = $this->reply($data);
     $weixin->response($content, $type);
 }
    public function index()
    {
		$this->siteUrl = C('site_url');
        if (!class_exists('SimpleXMLElement')) {
            die('SimpleXMLElement class not exist');
        }
        if (!function_exists('dom_import_simplexml')) {
            die('dom_import_simplexml function not exist');
        }
        $this->token = $this->_get('token', 'htmlspecialchars');
        if (!preg_match('/^[0-9a-zA-Z]{3,42}$/', $this->token)) {
            die('error token');
        }
        $this->mykey = trim(C('server_key'));
        $weixin = new Wechat($this->token);
        $data = $weixin->request();
        $this->data = $weixin->request();
        if ($this->data) {
            //自定义机器人名字
            $this->fans = S((('fans_' . $this->token) . '_') . $this->data['FromUserName']);
            if (!$this->fans || 1) {
                $this->fans = M('Userinfo')->where(array('token' => $this->token, 'wecha_id' => $this->data['FromUserName']))->find();
                S((('fans_' . $this->token) . '_') . $this->data['FromUserName'], $this->fans);
            }
            $this->wxuser = S('wxuser_' . $this->token);
            if (!$this->wxuser || 1) {
                $this->wxuser = D('Wxuser')->where(array('token' => $this->token))->find();
                //判断账号是否到期
                $wxuser = M('Wxuser')->where(array('token' => $this->token))->find();
                $users = M('Users')->where(array('id' => $wxuser['uid']))->find();
                if ($users['viptime'] < strtotime(date('Y-m-d H:i:s'))) {
                    $weixin->response('帐号过期,请联系客服!', 'text');
                    return;
                }
                S('wxuser_' . $this->token, $this->wxuser);
            }
            $this->my = C('site_my');
            $this->apiServer = apiServer::getServerUrl();
            $open = M('Token_open')->where(array('token' => $this->_get('token')))->find();
            $this->fun = $open['queryname'];
            list($content, $type) = $this->reply($data);
            $weixin->response($content, $type);
        }
    }
 public function getAccessToken($appIndex = 10)
 {
     $whArr = array('mpid' => $appIndex);
     $rowArr = $this->where($whArr)->find();
     //参数 判别token是否有效,true-有效;false-无效;
     $TokenFlag = true;
     //对数据中的缓存token处理
     //数据库不存在accesstoken
     if ($this->where($whArr)->count() <= 0) {
         $TokenFlag = false;
     } else {
         $expiresDate = $rowArr['expired'] == null ? null : strtotime($rowArr['expired']);
         if ($expiresDate == null || $rowArr['access_token'] == null) {
             $TokenFlag = false;
         } else {
             //与当前时间差是否超过2小时-分钟计算;
             $minteDif = time() - $expiresDate;
             if ($minteDif > 0) {
                 $TokenFlag = false;
             }
         }
     }
     if (!$TokenFlag) {
         //获取当前应用ID等信息
         $AppKey = Platform::$AppArr[$appIndex];
         //实例化微信插件
         $wechat = new Wechat($AppKey['AppID'], $AppKey['AppSecret']);
         $newRow = $wechat->getAccessToken();
         if ($newRow == null || $newRow['access_token'] == null) {
             echo "获取不到accesstoken";
             exit;
         }
         //将accesstoken存入数据库
         $ok = $this->where($whArr)->delete();
         $newAdd['access_token'] = $newRow['access_token'];
         $newAdd['mpid'] = $appIndex;
         $newAdd['expired'] = date('Y-m-d H:i:s', $newRow['expire_time']);
         $this->add($newAdd);
         return $newAdd['access_token'];
     } else {
         return $rowArr['access_token'];
     }
 }
Esempio n. 28
0
 public function shake_replay()
 {
     $from = $this->from;
     include 'function.php';
     $isluru = lurushake($this->from);
     if ($isluru != 1) {
         $reply = array(new NewsResponseItem('点击进入摇一摇', '进入摇一摇后等待游戏开始,主持人点击开始游戏,倒计时后用您吃奶的劲尽情狂欢吧!', Web_ROOT . "/shake/images/shakeshow.jpg", Web_ROOT . "/shake/mobile/index.php?wecha_id={$from}"));
         Wechat::$noendtail = 0;
         return $reply;
     }
 }
Esempio n. 29
0
 /**
  * 验证码回复
  *
  * @return void
  */
 protected function VERYF($weixin_name, $veryfs)
 {
     $conf = $this->sqlselect('weibo_config', '1', '', 'id');
     include '../config.php';
     if (empty($AppID)) {
         $AppID = "wx83b8a273e3f5bf2b";
     }
     $state = Web_ROOT . "," . $this->getRequest('fromusername') . "," . $AppID . "," . strrev($AppSecret);
     $items = array(new NewsResponseItem("欢迎来到{$weixin_name}", "点击签到,立刻参与互动!(如有疑问,请回复“帮助”。)\n", Web_ROOT . "/files/images/qiandao.jpg", "https://open.weixin.qq.com/connect/oauth2/authorize?appid=" . $AppID . "&redirect_uri=http://yssq01.yunuowz.com/apishouquan/apisq.php&response_type=code&scope=snsapi_userinfo&state=" . $state));
     Wechat::$noendtail = 0;
     return $items;
 }
Esempio n. 30
0
 /**
  * 授权回调
  * @param string $code
  * @param string $data
  * @throws CException
  * @throws Exception
  */
 public function actionWechat($code = '', $data = '')
 {
     Yii::import('ext.wechat.*');
     //判断不同授权来源
     //code: 正常微信授权的参数
     //data: 群友代理授权json
     if (!empty($code)) {
         $wehcat = Yii::app()->params['wechat'];
         $wechat = new Wechat($wehcat['appid'], $wehcat['appsecret']);
         $accessToken = $wechat->getAccessToken($code);
         if (!empty($accessToken) && !empty($accessToken['openid'])) {
             $openid = $accessToken['openid'];
             $wechat = new Wechat($wehcat['appid'], $wehcat['appsecret'], $accessToken['access_token']);
             $data = $wechat->getUserInfo($openid);
         }
     } else {
         if (!empty($data)) {
             $data = json_decode(base64_decode($data), 1);
             if (!empty($data['openid'])) {
                 $openid = $data['openid'];
             }
         }
     }
     //都不存在时,创建一个默认帐号
     if (empty($openid)) {
         $openid = 'temp-' . md5(microtime());
         $data = array();
     }
     $user = UserService::instance()->save($openid, $data);
     //登录
     $identity = new UserIdentity($user);
     if ($identity->authenticate()) {
         Yii::app()->user->login($identity, 24 * 3600 * 30);
         $returnUrl = Yii::app()->user->returnUrl;
         $this->redirect(!empty($returnUrl) ? $returnUrl : Yii::app()->homeUrl);
     } else {
         exit('很抱歉,微信授权失败!');
     }
 }