public function setCloud($apiinfo) { global $_W; global $_K; $header[] = "Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0"; $header[] = "Content-Type: text/xml; charset=utf-8"; // 定义content-type为xml $ch = curl_init(); // 初始化curl //判断提交方式 //POST远程 if ($apiinfo['webuntil_type'] == 'post') { if ($apiinfo['webuntil_backtype'] == 'string') { $post_data = http_build_query($apiinfo['webuntil_param']); } else { $post_data = $GLOBALS['HTTP_RAW_POST_DATA']; //判断是否过滤关键词 仅对文本请求 匹配规则为开头匹配 if ($_W['msgtype'] == 'text' && $apiinfo['webuntil_sigtype'] == 'yes') { $content = trim(str_replace($_K['keyword_content'], '', $_W['content'])); $post_data = str_replace('<Content><![CDATA[' . $_W['content'] . ']]></Content>', '<Content><![CDATA[' . $content . ']]></Content>', $post_data); } } $url = $apiinfo['webuntil_url']; curl_setopt($ch, CURLOPT_POST, 1); // 设置为POST方式 curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data); // POST数据 } else { //GET 请求 $getinfo = $apiinfo['webuntil_param']; $getinfo['keyword'] = $_W['msgtype'] == 'text' && $apiinfo['webuntil_sigtype'] == 'yes' ? trim(str_replace($_K['keyword_content'], '', $_W['content'])) : $_W['content']; //参数 $get_data = http_build_query($getinfo); $blindurl = false === strpos($apiinfo['webuntil_url'], '?') ? '?' . $get_data : $get_data; $url = $apiinfo['webuntil_url'] . $blindurl; curl_setopt($ch, CURLOPT_POST, 0); // 设置为POST方式 } curl_setopt($ch, CURLOPT_URL, $apiinfo['webuntil_url']); // 设置链接 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // 设置是否返回信息 curl_setopt($ch, CURLOPT_HTTPHEADER, $header); // 设置HTTP头 $response = curl_exec($ch); // 接收返回信息 // if($apiinfo['webuntil_tag']==0){ // echo $response;die; // } if (curl_errno($ch)) { // 出错则显示错误信息 wx_error(curl_error($ch)); } curl_close($ch); $response = str_replace("<Content><![CDATA[]]></Content>", '', $response); //回复处理 判断是否是XML $string = simplexml_load_string($response, 'SimpleXMLElement', LIBXML_NOCDATA); if (!empty($string)) { // //XML转成完整数组 $data = json_decode(json_encode($string, JSON_FORCE_OBJECT), TRUE); foreach ($data as $key => $value) { $packet[strtolower($key)] = $value; } $type = $packet['msgtype']; unset($packet['fromusername'], $packet['tousername'], $packet['createtime'], $packet['msgtype']); //支持多图文的TAG switch (strtolower($type)) { case 'news': $xmlarray = $packet['articles']['item']; $nums = $packet['articlecount']; if ($nums == 1) { if (!is_string($xmlarray['PicUrl'])) { $xmlarray['PicUrl'] = ''; } $rearray[0] = $xmlarray; $info = $apiinfo['webuntil_tag'] == 1 ? Factory('Dantw')->load($rearray)->select() : Factory('Dantw')->load($rearray)->deltag('*')->select(); $infotype = 'Dantw'; } else { $info = $apiinfo['webuntil_tag'] == 1 ? Factory('Duotw')->load($xmlarray)->select() : Factory('Duotw')->load($xmlarray)->deltag('*')->select(); $infotype = 'Duotw'; } break; case 'text': $xmlarray['Content'] = $packet['content']; $info = $apiinfo['webuntil_tag'] == 1 ? Factory('Text')->load($xmlarray)->select() : Factory('Text')->load($xmlarray)->deltag('*')->select(); $infotype = 'Text'; break; default: $info = $xml; $infotype = ''; break; } $xmlinfo = array('type' => $infotype, 'info' => $info); } else { $newresponse = self::is_json($response); if (is_array($newresponse)) { $type = ucfirst($newresponse['msgtype']); unset($newresponse['msgtype']); //$info = Factory($type)->load($newresponse)->select(); $info = $apiinfo['webuntil_tag'] == 1 ? Factory($type)->load($newresponse)->select() : Factory($type)->load($newresponse)->deltag('*')->select(); $xmlinfo = array('type' => $type, 'info' => $info); } else { //$info = Factory('Text')->load($response)->select(); $info = $apiinfo['webuntil_tag'] == 1 ? Factory('Text')->load($response)->select() : Factory('Text')->load($response)->deltag('*')->select(); $xmlinfo = array('type' => 'text', 'info' => $info); } } //设置缓存 if ($apiinfo['webuntil_cache'] > 0) { excute_cache($apiinfo['id'], $xmlinfo, $apiinfo['webuntil_cache'], $is_echo = false); } return $xmlinfo; }
/** * 显示输出 * @param 处理参数 * @access public */ public function display($type, $xmlinfo) { $xmlinfo = empty($this->xmlinfo) ? $xmlinfo : $this->xmlinfo; $type = empty($this->type) ? $type : $this->type; session('ReplyType', $type); //TODO 激活前行为 暂不启用 // excute_behavior($this->behaviorhead); //回复内容缓存 判断是否含有头部 $xmlinfo = $this->completeInfo($type, $this->denytag, $xmlinfo); $xml = false !== stripos($xmlinfo, 'ToUserName') || false !== stripos($xmlinfo, 'MsgType') ? $xmlinfo : $this->completeHead($type, $xmlinfo) . $xmlinfo . self::XMLEND; // $xmlhead = self::completeHead($type,$xmlinfo); // $xml = $xmlhead.$xmlinfo.self::XMLEND; hook('weixin_end', &$xml); echo $xml; //个人菜单 锁定 if ($this->clickmodel > 0) { excute_lock('click', $this->clickmodel); } global $_K; //个人关键词 锁定 if (1 == $this->down) { excute_lock('keyword', $_K['id']); } //个人模式 锁定 if (!empty($this->lockmodel)) { excute_lock('model', $this->lockmodel); } //设置关键词缓存 if ($this->cache > 0) { excute_cache($_K['id'], $xml, $this->cache, $is_echo = false); } self::amangolog(); hook('weixin_end'); die; }