public function ztest2($inp) { $obj = new weixin(); $obj->send_msg($inp); $b = "return seccess"; return $b; }
public function index() { $id = intval($GLOBALS['request']['id']); $email = strim($GLOBALS['request']['email']); $pwd = strim($GLOBALS['request']['pwd']); if (!dealIdIsExist($id, 1)) { $result = responseErrorInfo("deal_id参数错误"); output($result); } $user = user_check($email, $pwd); $user_id = intval($user['id']); get_mortgate(); // 不知道为什么要冻结 $deal_info = $this->getDealInfo($id, $user_id); $leader_info = getLeaderInfo($id); $deal_new_info = $this->getNewDeal_info($deal_info); // $stock_info = $this->getStockAndUnStock ( $deal_info ); // $history_info = $this->getHistoryInfo ( $deal_info ); // $plan_info = $this->getPlanInfo ( $deal_info ); $result = responseSuccessInfo("项目详情"); $result["deal_info"] = $deal_new_info; $result['leader_info'] = $leader_info; // $result ['stock_info'] = $stock_info; // $result ['history_info'] = $history_info; // $result ['plan_info'] = $plan_info; if ($user_id > 0) { $is_focus = $GLOBALS['db']->getOne("select count(*) from " . DB_PREFIX . "deal_focus_log where deal_id = " . $id . " and user_id = " . $user_id); $result['is_focus'] = $is_focus; } $result['business_url'] = get_domain() . url_mapi_html("deal#business", array("id" => $id, "user_id" => $user_id)); $result['teams_url'] = get_domain() . url_mapi_html("deal#teams", array("id" => $id, "user_id" => $user_id)); $result['history_url'] = get_domain() . url_mapi_html("deal#history", array("id" => $id, "user_id" => $user_id)); $result['plans_url'] = get_domain() . url_mapi_html("deal#plans", array("id" => $id, "user_id" => $user_id)); $url = replace_mapi(url_wap("deal#show", array("id" => $id))); $result['share_url'] = $url; if ($GLOBALS['m_config']['wx_appid'] != '' && $GLOBALS['m_config']['wx_secrit'] != '') { $weixin_1 = new weixin($GLOBALS['m_config']['wx_appid'], $GLOBALS['m_config']['wx_secrit'], $url); $wx_url = $weixin_1->scope_get_code(); $result['wx_share_url'] = $wx_url; } output($result); }
public function zfunc($zimgname, $zimgurl) { $wx = new weixin(); $access_token = $wx->get_tk(); //下载图片,转发上传到微信临时素材库 $imageData = $wx->httpGet($zimgurl); $fp = fopen(dirname(__FILE__) . "/" . $zimgname . ".jpg", 'w+'); fwrite($fp, $imageData); fclose($fp); $filepath = dirname(__FILE__) . "/" . $zimgname . ".jpg"; $filedata = array("media" => "@" . $filepath); //Linux绝对路径 $url = "https://qyapi.weixin.qq.com/cgi-bin/media/upload?access_token={$access_token}&type=image"; $res = $wx->httpPost($url, $filedata); $res = json_decode($res); $media_id = $res->media_id; $wx->send_img(array('userid' => 'plustree', 'appid' => '2', 'mediaid' => $media_id)); $b = "return seccess"; return $b; }
<?php require_once 'functions.php'; $redis = new Redis(); $redis->connect('127.0.0.1', 6379); //开始监听 app2 - app test if (isset($_GET["msg_signature"]) && isset($_GET["timestamp"]) && isset($_GET["nonce"])) { $wx = new weixin(); $xmlstr = $wx->get_msg('2'); $res_xmlstr = simplexml_load_string($xmlstr); $fromUserName = $res_xmlstr->FromUserName; $createTime = $res_xmlstr->CreateTime; $msgType = $res_xmlstr->MsgType; $agentID = $res_xmlstr->AgentID; if (!$redis->exists('timestamp')) { $redis->set('timestamp', (string) $fromUserName . (string) $createTime); } if ($redis->exists('timestamp')) { if ((string) $fromUserName . (string) $createTime != $redis->get('timestamp')) { $redis->set('timestamp', (string) $fromUserName . (string) $createTime); if ($msgType == "text" || $msgType == "image") { $content = $res_xmlstr->Content; $content = trim($content); if ($content == '1' || $content == '2') { $redis->set('type', (string) $fromUserName . (string) $content); $wx->log($redis->get('type')); } //"#1 开启上传模式"的逻辑 if (($msgType == "text" || $msgType == "image") && $redis->get('type') == (string) $fromUserName . '1') { //提示用户输入图片名称 if ($content == '1') {
public function z_create_user($userid, $name, $weixinid, $dep) { $obj = new weixin(); $res = $obj->create_user($userid, $name, $weixinid, $dep); return $res; }
function m__menu_sync() { $menu = menu_list(); $menu_post = array(); foreach ($menu as $a => $b) { $tmpa = array(); $tmpa['name'] = $b['menu_name']; if (count($b['son']) > 0) { $tmpa['sub_button'] = array(); foreach ($b['son'] as $k => $v) { $tmpb = array(); $tmpb['name'] = $v['menu_name']; $tmpb['type'] = $v['menu_type']; if ($v['menu_type'] == 'click') { $tmpb['key'] = $v['menu_key']; } else { $tmpb['url'] = $v['menu_url']; } array_push($tmpa['sub_button'], $tmpb); } } else { $tmpa['type'] = $b['menu_type']; if ($b['menu_type'] == 'click') { $tmpa['key'] = $b['menu_key']; } else { $tmpa['url'] = $b['menu_url']; } } array_push($menu_post, $tmpa); } $post_data = array('button' => $menu_post); $json = helper::json_encode_ch($post_data); //die('1'.$json); $wx = new weixin(); $ret = $wx->menu_create($json); if ($ret['errcode'] == '0') { die('{"code":"0","msg":"同步成功"}'); } else { die('{"code":"' . $ret['errcode'] . '","msg":"同步失败:' . $ret['errmsg'] . ',请重试"}' . $post_data); } }
public function mobile() { $config = M("MConfig")->order("sort asc")->findAll(); $wx_appid = ''; $wx_secrit = ''; $wx_url = ''; foreach ($config as $k => $v) { if ($v['code'] == 'wx_appid') { $wx_appid = $v['val']; continue; } if ($v['code'] == 'wx_secrit') { $wx_secrit = $v['val']; continue; } if ($v['type'] == 4) { $config[$k]['value_scope'] = explode(',', $v['value_scope']); } else { $config[$k]['value_scope'] = ''; } } if (!empty($wx_appid) && !empty($wx_secrit)) { require APP_ROOT_PATH . "system/utils/weixin.php"; $weixin = new weixin($wx_appid, $wx_secrit, get_domain() . APP_ROOT . "/wap"); $wx_url = $weixin->scope_get_code(); } $this->assign('wx_url', $wx_url); $this->assign("config", $config); $this->display(); }
Date/time : 2014-07-11 11:14:10 Purpose : 微信开发者API汇集 Description : 用户授权页面 Modify : ******************************************************************************/ include 'weixin.class.php'; //code说明 : //code作为换取access_token的票据,每次用户授权带上的code将不一样,code只能使用一次,5分钟未被使用自动过期。 $str_action = 'oauth'; $str_code = strval(trim($_REQUEST['code'])); $str_state = strval(trim($_REQUEST['state'])); $arr_request = array('code' => $str_code, 'state' => $str_state); echo '<pre>'; print_r($arr_request); echo '</pre>'; $obj_weixin = new weixin(); /** * 网页授权获取用户基本信息 */ if ($str_action == 'oauth') { /** * code说明 : * code作为换取access_token的票据,每次用户授权带上的code将不一样,code只能使用一次,5分钟未被使用自动过期。 */ /**/ $arr_data = array(); $arr_data['action'] = 'oauth_access_token'; $arr_data['code'] = $str_code; $arr_result = $obj_weixin->weixin($arr_data); //echo '-oauth2-'.'<br/>'; //echo '<pre>';
<?php require_once 'functions.php'; //开始监听 app1 - 供应商查询 if (isset($_GET["msg_signature"]) && isset($_GET["timestamp"]) && isset($_GET["nonce"])) { $wx = new weixin(); $xmlstr = $wx->get_msg('1'); $res_xmlstr = simplexml_load_string($xmlstr); $fromUserName = $res_xmlstr->FromUserName; $createTime = $res_xmlstr->CreateTime; $msgType = $res_xmlstr->MsgType; $agentID = $res_xmlstr->AgentID; if ($msgType == "event") { $event = $res_xmlstr->Event; $eventKey = $res_xmlstr->EventKey; //$msgId = $res_xmlstr->MsgId; } if ($event == "click" && !empty($eventKey)) { $con = mysql_connect("127.0.0.1", "root", "root"); mysql_select_db("wx", $con); $sql = "UPDATE customer_tbl SET language = '{$eventKey}' WHERE user_id = '{$fromUserName}'"; mysql_query($sql, $con); //update mysql_close($con); } } // $obj -> send_img("plustree", // "1U5VsijM4djNnRhyOOpuyy1XsuQaXDwxjztQ9gnnq43i-D3b_cqh9R4B4lJTMutXR" // );
mysql_select_db("wx", $con); if (isset($_SESSION['user_id'])) { $sql = "select language from customer_tbl where user_id = '" . $_SESSION['user_id'] . "'"; $result = mysql_query($sql, $con); $row = mysql_fetch_array($result); if (empty($row)) { $_SESSION['language'] = "Language_EN"; } else { $_SESSION['language'] = $row['language']; } } mysql_close($con); $code = $_GET['code']; if (!isset($_SESSION['access_token']) || !isset($_SESSION['token_time']) || !isset($_SESSION['user_id']) || !isset($_SESSION['device_id']) || !isset($_SESSION['language'])) { $sid = session_id(); $obj = new weixin(); $tk = ""; $tk = $obj->get_tk(); $agentid = "1"; $get_url = "https://qyapi.weixin.qq.com/cgi-bin/user/getuserinfo?access_token={$tk}&code={$code}&agentid={$agentid}"; $ch = curl_init($get_url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $result = curl_exec($ch); $result = json_decode($result); $result = (array) $result; $_SESSION['access_token'] = $tk; $_SESSION['token_time'] = time(); $_SESSION['user_id'] = $result["UserId"]; $_SESSION['device_id'] = $result["DeviceId"]; $_SESSION['language'] = "Language_EN"; //database
<?php require_once 'functions.php'; if (isset($_GET["msg_signature"]) && isset($_GET["timestamp"]) && isset($_GET["nonce"])) { $wx = new weixin(); $xmlstr = $wx->get_msg('13'); $res_xmlstr = simplexml_load_string($xmlstr); $fromUserName = $res_xmlstr->FromUserName; $createTime = $res_xmlstr->CreateTime; $msgType = $res_xmlstr->MsgType; $agentID = $res_xmlstr->AgentID; if ($msgType == 'text' && $fromUserName == 'plustree' && $agentID == '13') { $con = mysql_connect("127.0.0.1", "root", "root"); mysql_select_db("wx", $con); $sql = "SELECT count(1) from customer_tbl WHERE user_id = '{$fromUserName}' AND create_time= '{$createTime}'"; $sql_rsl = mysql_query($sql, $con); $row = mysql_fetch_array($sql_rsl); //转发全体 if ($row[0][0] == '0') { $content = $res_xmlstr->Content; $sql = "UPDATE customer_tbl SET create_time = '{$createTime}' WHERE user_id = '{$fromUserName}'"; mysql_query($sql, $con); // update mysql_close($con); $wx->send_msg(array('userid' => '@all', 'appid' => (string) $agentID, 'msg' => (string) $content)); } else { mysql_close($con); } } if ($msgType == 'text' && $fromUserName != 'plustree' && $agentID == '13') { $con = mysql_connect("127.0.0.1", "root", "root");
<?php require_once 'functions.php'; //开始监听 app3 - 朗姿供应链微妙平台 用户维护 if (isset($_GET["msg_signature"]) && isset($_GET["timestamp"]) && isset($_GET["nonce"])) { $wx = new weixin(); $xmlstr = $wx->get_msg('3'); $res_xmlstr = simplexml_load_string($xmlstr); $fromUserName = $res_xmlstr->FromUserName; $createTime = $res_xmlstr->CreateTime; $msgType = $res_xmlstr->MsgType; $agentID = $res_xmlstr->AgentID; if ($msgType == "event") { $event = $res_xmlstr->Event; $eventKey = $res_xmlstr->EventKey; //$msgId = $res_xmlstr->MsgId; } //接收手机发送图片 if ($msgType == "image") { $picUrl = $res_xmlstr->PicUrl; $mediaId = $res_xmlstr->MediaId; //$msgId = $res_xmlstr->MsgId; $fp = fopen('log.txt', 'w'); fwrite($fp, $picUrl); fclose($fp); } //进入应用事件响应并消息去重 if ($event == 'enter_agent' && $eventKey == '') { $con = mysql_connect("127.0.0.1", "root", "root"); mysql_select_db("wx", $con); $sql = "SELECT count(1) from customer_tbl WHERE user_id = '{$fromUserName}' AND create_time= '{$createTime}'";
function auto_login() { /* if(!isWeixin()){ header("Content-Type: text/html; charset=utf-8"); echo "抱歉,该网站只能在微信端打开,请用微信打开该网页!"; exit; } */ $user_info = session('user_info'); if ($_REQUEST['code'] && $_REQUEST['state'] == 1 && !$user_info) { require 'weixin.php'; $weixin = new weixin('wxa7e0d8fb62b7d5df', 'cab576f236da15a72eed02bc0fb7820a', 'http://www.1qjx.com/'); $wx_info = $weixin->scope_get_userinfo($_REQUEST['code']); if ($wx_info['openid']) { $wx_user_info = get_user_has('wx_openid', $wx_info['openid']); if ($wx_user_info) { //如果会员存在,直接登录 do_login_user($wx_user_info['id'], $wx_user_info['name']); } else { //会员不存在,保存会员呢账号 do_save_user($wx_info['nickname'], $wx_info['headimgurl'], $wx_info['openid']); } } } else { if (!$user_info) { require 'weixin.php'; $weixin_2 = new weixin('wxa7e0d8fb62b7d5df', 'cab576f236da15a72eed02bc0fb7820a', 'http://www.1qjx.com/'); $wx_url = $weixin_2->scope_get_code(); redirect($wx_url); } } }
$arr_articles[2]['title'] = iconv('GBK','UTF-8'.'//IGNORE','汤唯'); $arr_articles[2]['description'] = iconv('GBK','UTF-8'.'//IGNORE','汤唯拄拐杖抵港宣传新戏 获十余人护送 2 描述2'); $arr_articles[2]['url'] = 'http://news.163.com/14/0806/02/A2UBORB000014AED.html'; $arr_articles[2]['picurl'] = 'http://img4.cache.netease.com/photo/0003/2014-08-06/900x600_A2U9541P00AJ0003.jpg'; $arr_data['news']['articles'] = $arr_articles; $str_qstring = json_encode($arr_data); echo '<pre>'; print_r($str_qstring); echo '</pre>'; exit; */ $str_action = 'oauth'; $obj_weixin = new weixin(); /** * 网页授权获取用户基本信息 */ if ($str_action == 'oauth') { $arr_data = array(); $arr_data['action'] = 'oauth'; $arr_result = $obj_weixin->weixin($arr_data); //echo '<pre>'; //print_r($arr_result); //echo '</pre>'; // if (is_array($arr_result)) { // header("Location:https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxe7f55d599239f618&redirect_uri=http%3A%2F%2Fwww.91ka.com%2Fif%2Fweixin%2Fauth2.php&response_type=code&scope=snsapi_base&state=test#wechat_redirect"); // } }
<?php /*第一步 微信公众平台登陆*/ /*配置开始*/ header("content-Type: text/html; charset=utf-8"); require_once "./weixin.php"; $wxname = "*****@*****.**"; $pwd = "123456di"; $siurl = "http://bestchoice88.com/index.php/api/gqovxs1388298795"; //注意com后面不能带有斜线 上传后的地址 $sixian = new weixin(); $username = urlencode($wxname); $pwd = md5($pwd); $array = $sixian->login($username, $pwd); $cookie = $array[cookie]; $cookies = $array[cookies]; $token = $array[token]; if ($token == "") { echo "密码不正确"; } else { $nickName = $sixian->getmessage($token, $cookie, $cookies); echo $nickName["nick_name"]; $fakeid = $nickName["fakeid"]; $img = $sixian->gethead($token, $fakeid, $cookie); $filename = "{$fakeid}.jpg"; //要生成的图片名字 $jpg = $img; //得到post过来的二进制原始数据 $file = fopen("img/" . $filename, "w"); //打开文件准备写入 fwrite($file, $jpg);
/** * 微信 公众平台消息接口 SDK DEMO * @author xhxu xh_xu@qq.com/QQ:78445766 * @version 1.0.20130119 */ error_reporting(E_ALL & ~E_NOTICE); date_default_timezone_set("Asia/Shanghai"); require_once 'weixin.class.php'; define('TOKEN', 'YourToken'); //微信公众平台自定义接口处设置的 Token define('DEBUG', true); //是否调试模式 true/false (开启调试将会把收发的信息写入文件) define('LOGPATH', './'); //日志目录 $weixin = new weixin(TOKEN, DEBUG, LOGPATH); $weixin->valid(); $weixin->getMsg(); $type = $weixin->msgtype; $domain = 'http://' . $_SERVER['HTTP_HOST']; $filename = (string) end(explode('/', $_SERVER['SCRIPT_NAME'])); $strURL = $domain . str_replace($filename, '', $_SERVER['SCRIPT_NAME']); if ($type === 'text') { //用户发送文本信息 if ($weixin->msg['Content'] == 'Hello2BizUser') { //用户关注成功后,微信服务器将发送该字符串到接口. 用以标识用户关注事件 $note = '你已经成功关注该公众账号'; $reply = $weixin->makeText($note); } elseif ($weixin->msg['Content'] == '单条图文') { //如有必要可以为此条信息标星 //$weixin->setFlag = true;
public function z_invite_user($userid) { $obj = new weixin(); $res = $obj->invite_user($userid); return $res; }
<?php /****************************************************************************** Filename : api.php Author : SouthBear Email : SouthBear819@163.com Date/time : 2014-07-11 11:14:10 Purpose : 微信开发者API汇集 Description : Modify : ******************************************************************************/ include 'weixin.class.php'; $str_action = 'access_token'; //send_sevice_msg $obj_weixin = new weixin(); /** * 开发者验证 */ if ($str_action == 'check_dev') { $str_echostr = strval(trim($_REQUEST['echostr'])); //随机字符串 $str_nonce = strval(trim($_REQUEST['nonce'])); //随机数 $str_timestamp = strval(trim($_REQUEST['timestamp'])); //时间戳 $str_signature = strval(trim($_REQUEST['signature'])); //签名字串 /* $str_echostr = '3458335650061737471'; $str_nonce = '627010994'; $str_timestamp = '1405049982';
* return http response $res */ public function delete_user($userid) { $tk = $this->get_tk(); $get_url = "https://qyapi.weixin.qq.com/cgi-bin/user/delete?access_token={$tk}&userid={$userid}"; $arrReply = array("userid" => $userid); $data_string = json_encode($arrReply, JSON_UNESCAPED_UNICODE); $res = $this->httpGet($get_url, $data_string); return $res; } /** * webserver invite member to follow lancy weixin * @param: string $userid * return http response $res */ public function invite_user($userid) { $tk = $this->get_tk(); $post_url = "https://qyapi.weixin.qq.com/cgi-bin/invite/send?access_token={$tk}"; $arrReply = array("userid" => $userid); $data_string = json_encode($arrReply, JSON_UNESCAPED_UNICODE); $res = $this->httpPost($post_url, $data_string); return $res; } } $wx = new weixin(); //$wx -> create_user(array('userid'=>'zforce1111', 'name'=>'唐兆寅', 'weixinid'=>'zforce1111', 'depid'=>[1,3])); //$wx -> invite_user('zforce1111'); $wx->delete_user('test01'); $wx->delete_user('test02');
<?php define("TOKEN", "hongbao"); define("APPID", "wx8d80c4101193fcdb"); define("APPSECRET", "57ff9e369cae45f7ec9ffe28c0b43e9f"); $wxObj = new weixin(); $wxObj->responseMsg(); class weixin { public function valid() { $echoStr = $_GET["echostr"]; if ($this->checkSignature()) { echo $echoStr; exit; } } public function responseMsg() { $postStr = $GLOBALS["HTTP_RAW_POST_DATA"]; if (!empty($postStr)) { $postObj = simplexml_load_string($postStr, 'SimpleXMLElement', LIBXML_NOCDATA); $RX_TYPE = trim($postObj->MsgType); //消息类型分离 switch ($RX_TYPE) { case "event": $result = $this->receiveEvent($postObj); break; default: $this->valid(); break;
$xml .= '</item>'; } $xml .= '</Articles>'; } else { return false; } break; default: return false; break; } $xml .= '</xml>'; echo convert($xml, DT_CHARSET, 'UTF-8'); } } $wx = new weixin(); $access_token = $dc->get('weixin_access_token'); if (!$access_token) { $access_token = $wx->get_token(); $dc->set('weixin_access_token', $access_token, 7000); } $wx->access_token = $access_token; function weixin_user($openid) { global $db; return $db->get_one("SELECT * FROM {$db->pre}weixin_user WHERE openid='{$openid}'"); } function weixin_bind($openid, $username) { global $db; if (check_name($username)) {
//用户未登陆 if ($wx_info['openid']) { $wx_user_info = get_user_has('wx_openid', $wx_info['openid']); if ($wx_user_info) { //如果会员存在,直接登录 do_login_user($wx_user_info['mobile'], $wx_user_info['user_pwd']); } else { //会员不存在进入登录流程 $class = 'user_wx_register'; //app_redirect(wap_url('index','user_wx_register')); } } } else { if ($is_weixin && !$user_info && $m_config['wx_app_key'] && $m_config['wx_app_secret'] && $class != 'user_wx_register' && $class != 'register_verify_phone' && $class != 'wx_do_register') { //echo $class;exit; $weixin_2 = new weixin($m_config['wx_app_key'], $m_config['wx_app_secret'], get_domain() . $_SERVER["REQUEST_URI"]); $wx_url = $weixin_2->scope_get_code(); app_redirect($wx_url); } } //获取模板文件的名称 $tmpl_dir = $class . '_' . $act2 . '.html'; //========================= //$request_url = 'http://127.0.0.1/'.str_replace('/wap', '', APP_ROOT).'/sjmapi/index.php'; $request_url = get_domain() . str_replace('/wap', '', APP_ROOT) . '/sjmapi/index.php'; //echo $request_url;exit; //echo get_domain()."<br>;".APP_ROOT; exit; $city_id = intval($request_param['city_id']); //用户从前台直接选择某个城市 $city_name = strim($request_param['city_name']); if ($city_id == 0 && es_session::get("city_id")) {
if (!$appid) { $appid = $GLOBALS['db']->getOne("select authorizer_appid from " . DB_PREFIX . "weixin_account where type=1 and user_id=0 "); if (!$appid) { var_dump("管理员未绑定微信账号"); exit; } } $wx_url = $weixin_2->scope_get_code($appid); } else { $wx_url = $weixin_2->scope_get_code(); } //echo $wx_url;exit; app_redirect($wx_url); } else { if ($is_weixin && !$user_info && $wx_status && $class != 'ajax' && $class != 'user' && $m_config['wx_controll'] == 0) { $weixin_2 = new weixin($m_config['wx_appid'], $m_config['wx_secrit'], get_domain() . $current_url); if ($weixin_conf['platform_status']) { $appid = $_REQUEST['appid']; if (!$appid) { $appid = $GLOBALS['db']->getOne("select authorizer_appid from " . DB_PREFIX . "weixin_account where type=1 and user_id=0 "); if (!$appid) { var_dump("管理员未绑定微信账号"); exit; } } $wx_url = $weixin_2->scope_get_code($appid); } else { $wx_url = $weixin_2->scope_get_code(); } //echo $wx_url;exit; //file_put_contents('./t.txt',var_export($_REQUEST,TRUE)."==2\n",FILE_APPEND);