Пример #1
0
 public function addon_get_js_ticket()
 {
     $configs = globaSetting(array("jsapi_ticket", "jsapi_ticket_exptime"));
     $jsapi_ticket = $configs['jsapi_ticket'];
     $jsapi_ticket_exptime = intval($configs['jsapi_ticket_exptime']);
     if (empty($jsapi_ticket) || empty($jsapi_ticket_exptime) || $jsapi_ticket_exptime < time()) {
         $accessToken = get_weixin_token();
         $url = "https://api.weixin.qq.com/cgi-bin/ticket/getticket?type=jsapi&access_token={$accessToken}";
         $content = http_get($url);
         $res = @json_decode($content, true);
         $ticket = $res['ticket'];
         if (!empty($ticket)) {
             $cfg = array('jsapi_ticket' => $ticket, 'jsapi_ticket_exptime' => time() + intval($res['expires_in']));
             refreshSetting($cfg);
             return $ticket;
         }
         return '';
     } else {
         return $jsapi_ticket;
     }
 }
Пример #2
0
 public function menuQuery()
 {
     $token = get_weixin_token();
     $url = "https://api.weixin.qq.com/cgi-bin/menu/get?access_token={$token}";
     $content = http_get($url);
     if (empty($content)) {
         return message("接口调用失败,请重试!微信公众平台返回错误信息: {$content}");
     }
     $dat = $content;
     $result = @json_decode($dat, true);
     if (is_array($result) && !empty($result['menu'])) {
         return $result;
     } else {
         if ($result['errcode'] != '46003') {
             get_weixin_token(true);
             if (is_array($result)) {
                 return message("微信公众平台返回接口错误。错误信息: {$result['errmsg']} 错误描述: " . $this->error_code($result['errcode']));
             } else {
                 return message('微信公众平台未知错误');
             }
         }
     }
 }
Пример #3
0
 public function sendcustomIMG($from_user, $msg)
 {
     $access_token = get_weixin_token();
     $url = "https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token={$access_token}";
     $post = '{"touser":"******","msgtype":"image","image":{"media_id":"' . $msg . '"}}';
     http_post($url, $post);
 }
Пример #4
0
 function xoauth($appid, $secret)
 {
     global $_GP;
     //用户不授权返回提示说明
     if ($_GP['code'] == "authdeny") {
         exit;
     }
     //高级接口取未关注用户Openid
     if (isset($_GP['code'])) {
         if (empty($appid) || empty($secret)) {
             message('微信公众号没有配置公众号AppId和公众号AppSecret!');
         }
         $state = $_GP['state'];
         //0未获取用户资料 1获取用户资料
         //查询活动时间
         $code = $_GP['code'];
         $oauth2_code = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=" . $appid . "&secret=" . $secret . "&code=" . $code . "&grant_type=authorization_code";
         $content = http_get($oauth2_code);
         $token = @json_decode($content, true);
         if (empty($token) || !is_array($token) || empty($token['access_token']) || empty($token['openid'])) {
             message('获取微信公众号授权失败,公众平台返回原始数据为:' . $content['meta']);
             exit;
         }
         $from_user = $token['openid'];
         $access_token = get_weixin_token();
         $oauth2_url = "https://api.weixin.qq.com/cgi-bin/user/info?access_token=" . $access_token . "&openid=" . $from_user . "&lang=zh_CN";
         $content = http_get($oauth2_url);
         $info = @json_decode($content, true);
         if ($info['subscribe'] == 1) {
             $follow = 1;
         } else {
             $follow = 0;
         }
         $fans = mysqld_select("SELECT * FROM " . table('weixin_wxfans') . " WHERE weixin_openid=:weixin_openid ", array(':weixin_openid' => $from_user));
         $gender = $info["gender"];
         $nickname = $info["nickname"];
         if (empty($fans) || empty($fans['weixin_openid']) || empty($fans["nickname"])) {
             if ($follow == 0 && $state == 0) {
                 get_weixin_openid(1);
                 return;
             }
             if ($follow == 0 && $state == 1) {
                 $access_token = $token['access_token'];
                 $oauth2_url = "https://api.weixin.qq.com/sns/userinfo?access_token=" . $access_token . "&openid=" . $from_user . "&lang=zh_CN";
                 $content = http_get($oauth2_url);
                 $info = @json_decode($content, true);
             }
             if (empty($info) || !is_array($info) || empty($info['openid'])) {
                 message('获取微信公众号授权失败[无法取得info], 请稍后重试');
                 exit;
             }
             $gender = $info['sex'];
             $nickname = $info["nickname"];
         }
         if (empty($fans['weixin_openid'])) {
             $row = array('nickname' => $nickname, 'follow' => $follow, 'gender' => intval($gender), 'weixin_openid' => $from_user, 'avatar' => '', 'createtime' => TIMESTAMP);
             mysqld_insert('weixin_wxfans', $row);
             if (!empty($info["headimgurl"])) {
                 mysqld_update('weixin_wxfans', array('avatar' => $info["headimgurl"]), array('weixin_openid' => $from_user));
             }
         } else {
             $row = array('follow' => $follow, 'gender' => intval($gender), 'avatar' => '');
             if (!empty($nickname)) {
                 $row['nickname'] = $nickname;
             }
             mysqld_update('weixin_wxfans', $row, array('weixin_openid' => $from_user));
             if (!empty($info["headimgurl"])) {
                 mysqld_update('weixin_wxfans', array('avatar' => $info["headimgurl"]), array('weixin_openid' => $from_user));
             }
         }
         if (!empty($fans['openid']) && !empty($nickname)) {
             $member = mysqld_select("SELECT realname FROM " . table('member') . " WHERE openid=:openid ", array(':openid' => $fans['openid']));
             if (empty($member['realname'])) {
                 mysqld_update('member', array('realname' => $nickname), array('openid' => $fans['openid']));
             }
         }
         return $from_user;
     } else {
         message('微信端网页授权域名设置出错!');
         exit;
     }
 }
Пример #5
0
 function single($sid)
 {
     //single 出单操作
     if (isset($sid)) {
         $tid;
         $username = $_SESSION['username'];
         $store = $_SESSION['store'];
         $finish = 0;
         $dates = date("Y-m-d H:i:s", time());
         //$num 存储的是排号的号数,采用session存储和写入
         $num = isset($_SESSION['num']) ? $_SESSION['num'] + 1 : 1;
         //检测是否存在session,若存在,将变量的值设为该session+1,否则初始化为1
         if ($num >= 1000) {
             $num = 1;
         }
         $_SESSION['num'] = $num;
         $sql = "INSERT INTO `ticket` (`tid`,`num`,`username`,`store`,`finish`,`dates`) VALUES('{$tid}','{$num}','{$username}','{$store}','{$finish}','{$dates}')";
         $query = mysql_query($sql);
         //----------------获取最新传入的tid------------------
         $select_tid = "SELECT * FROM `ticket`  WHERE store = '{$store}'  ORDER BY `tid` DESC";
         $qu = mysql_query($select_tid);
         $rs = mysql_fetch_array($qu);
         $tid = !empty($rs['tid']) ? $rs['tid'] : $rs['tid'] + 1;
         //如果tid不为空,就用tid,如果为空,则+1.防止tid为0.
         //            $_SESSION['tid'] = $tid;
         //----------------获取最新传入的tid------------------
         //生成网址二维码
         $appId = trim('wx4a5705a0d58ff752');
         $appSecret = trim('a3d6e50f86a17fb5f9d0f5265d711d99');
         $access_token = get_weixin_token($appId, $appSecret);
         //                print_r($access_token);exit;
         $qr_Scene = '{"expire_seconds": 604800, "action_name": "QR_SCENE", "action_info": {"scene": {"scene_id":' . $tid . '}}}';
         //            print_r($qr_Scene);
         $qrcode_url = "https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token={$access_token}";
         $result = postWeixinData($qrcode_url, $qr_Scene);
         $jsoninfo = json_decode($result, true);
         //    var_dump($jsoninfo);
         $ticket = $jsoninfo['url'];
         //订单id
         $dingdanID = array();
         while (count($dingdanID) < 5) {
             $dingdanID[] = rand(1, 5);
             $dingdanID = array_unique($dingdanID);
         }
         //打印机api
         $url = 'line.php?id=' . $sid . '&store=' . $store;
         //跳转到原来页面
         $post = 'http://42.121.124.104:60002';
         //POST指向的API链接
         $dingdan = '<1B40><1B40><1B40><1D2111><1B6101>美西西皇茶<0D0A>
                     <1B6100><1D2110><1D2101>你的单号是' . $num . '<0D0A>
                     <1B2A>' . $ticket . '<1B2A>';
         //二维码内容
         $dayinjisn = $_SESSION['dayinjisn'];
         $dingdanID = implode("", $dingdanID);
         $pages = 1;
         $replyURL = 'http://42.121.124.104:60002';
         $data = array('dingdanID' => 'dingdanID=' . $dingdanID, 'dayinjisn' => 'dayinjisn=' . $dayinjisn, 'dingdan' => 'dingdan=' . $dingdan, 'pages' => 'pages=' . $pages, 'replyURL' => 'replyURL=' . $replyURL);
         //回复确认URL
         $post_data = implode('&', $data);
         $result = $this->postData($post, $post_data);
         echo $result;
         //
         //            //如果执行成功
         if ($query) {
             echo "<script language='javascript'>\n                        alert('出单成功');\n                        location.href='{$url}';\n                        </script> ";
         } else {
             echo "<script language='javascript'>\n                        alert('出单失败');\n                        location.href='{$url}';\n                        </script> ";
         }
     }
 }
Пример #6
0
 //        print_r($res);
 $update = "UPDATE `ticket` SET `finish`='1' WHERE `tid`='{$tid}'   LIMIT 1 ";
 $query1 = mysql_query($update);
 //        print_r($query1);exit;
 //遍历一遍,对比
 $finish = new user();
 $url = 'single.php?id=' . $sid . '&store=' . $store;
 //       $finish = $finish->sucess($url,$query1);
 //--------获取token
 $appId = trim('wx4a5705a0d58ff752');
 $appSecret = trim('a3d6e50f86a17fb5f9d0f5265d711d99');
 //        $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid={$appId}&secret={$appSecret}";
 //        $return = file_get_contents($url);
 //        $return = json_decode($return);
 //        $access_token = $return -> access_token;
 $access_token = get_weixin_token($appId, $appSecret);
 //        print_r($access_token);exit;
 $tplId = 'mO_PQdRgUhJCiQqhe4sCJ4W2qWRPw7uELX0F6xsJqHQ';
 //模板ID
 $ticket_sql = "SELECT * FROM `ticket` WHERE `tid` = {$tid} AND `finish` = '1' LIMIT 1";
 $ticket_query = mysql_query($ticket_sql);
 $ticket = mysql_fetch_array($ticket_query);
 $ticket['num'] = str_pad($ticket['num'], 5, '0', STR_PAD_LEFT);
 $post = array();
 $post['first'] = array('value' => "您的茶已经新鲜做好,enjoy!\r\n", 'color' => '#000');
 $post['keyword1'] = array('value' => $ticket['num'], 'color' => '#000');
 $post['keyword2'] = array('value' => "皇茶见!", 'color' => '#000');
 $post['remark'] = array('value' => "感谢您的耐心等待", 'color' => '#000');
 $url = '';
 //可选参数,填上用户可以点击模板消息访问该链接;
 //发送模板消息:
Пример #7
0
 function xoauth()
 {
     global $_GP;
     //用户不授权返回提示说明
     if ($_GP['code'] == "authdeny") {
         echo "authdeny";
         exit;
     }
     $state = $_GP['state'];
     if ($state == 1) {
         $token = weixin_code_access_token(1, "snsapi_userinfo");
     } else {
         $token = weixin_code_access_token(0, "snsapi_base");
     }
     if (!empty($token)) {
         $from_user = $token['openid'];
         $access_token = get_weixin_token();
         $oauth2_url = "https://api.weixin.qq.com/cgi-bin/user/info?access_token=" . $access_token . "&openid=" . $from_user . "&lang=zh_CN";
         $content = http_get($oauth2_url);
         $info = @json_decode($content, true);
         if ($info['subscribe'] == 1) {
             $follow = 1;
         } else {
             $follow = 0;
         }
         $fans = mysqld_select("SELECT * FROM " . table('weixin_wxfans') . " WHERE weixin_openid=:weixin_openid ", array(':weixin_openid' => $from_user));
         $gender = $info["gender"];
         $nickname = $info["nickname"];
         if (empty($fans) || empty($fans['weixin_openid']) || empty($fans["nickname"])) {
             if ($follow == 0 && $state == 0) {
                 weixin_code_access_token(1, "snsapi_userinfo", true);
                 return;
             }
             if ($follow == 0 && $state == 1) {
                 $access_token = $token['access_token'];
                 $oauth2_url = "https://api.weixin.qq.com/sns/userinfo?access_token=" . $access_token . "&openid=" . $from_user . "&lang=zh_CN";
                 $content = http_get($oauth2_url);
                 $info = @json_decode($content, true);
             }
             if (empty($info) || !is_array($info) || empty($info['openid'])) {
                 weixin_code_access_token(1, "snsapi_userinfo", true);
                 return;
             }
             $gender = $info['sex'];
             $nickname = $info["nickname"];
         }
         if (empty($fans['weixin_openid'])) {
             $row = array('nickname' => $nickname, 'follow' => $follow, 'gender' => intval($gender), 'weixin_openid' => $from_user, 'avatar' => '', 'createtime' => TIMESTAMP);
             mysqld_insert('weixin_wxfans', $row);
             if (!empty($info["headimgurl"])) {
                 mysqld_update('weixin_wxfans', array('avatar' => $info["headimgurl"]), array('weixin_openid' => $from_user));
             }
         } else {
             $row = array('follow' => $follow, 'gender' => intval($gender), 'avatar' => '');
             if (!empty($nickname)) {
                 $row['nickname'] = $nickname;
             }
             mysqld_update('weixin_wxfans', $row, array('weixin_openid' => $from_user));
             if (!empty($info["headimgurl"])) {
                 mysqld_update('weixin_wxfans', array('avatar' => $info["headimgurl"]), array('weixin_openid' => $from_user));
             }
         }
         if (!empty($fans['openid']) && !empty($nickname)) {
             $member = mysqld_select("SELECT realname FROM " . table('member') . " WHERE openid=:openid ", array(':openid' => $fans['openid']));
             if (empty($member['realname'])) {
                 mysqld_update('member', array('realname' => $nickname), array('openid' => $fans['openid']));
             }
         }
         return $from_user;
     }
     return '';
 }