function cron_run($id) { global $_W; $cron = pdo_get('core_cron', array('uniacid' => $_W['uniacid'], 'id' => $id)); if (empty($cron)) { return false; } $extra = array(); $extra['Host'] = $_SERVER['HTTP_HOST']; load()->func('communication'); $urlset = parse_url($_W['siteurl']); $urlset = pathinfo($urlset['path']); $response = ihttp_request('http://127.0.0.1/' . $urlset['dirname'] . '/' . url('cron/entry', array('id' => $cron['cloudid'])), array(), $extra); $response = json_decode($response['content'], true); if (is_error($response['message'])) { return $response['message']; } else { cron_setnexttime($cron); $cron_new = pdo_get('core_cron', array('uniacid' => $_W['uniacid'], 'id' => $id)); if (empty($cron_new)) { return true; } if ($cron_new['status'] != $cron['status'] || $cron_new['lastruntime'] != $cron['lastruntime'] || $cron_new['nextruntime'] != $cron['nextruntime']) { load()->model('cloud'); $cron_new['id'] = $cron_new['cloudid']; $status = cloud_cron_update($cron_new); if (is_error($status)) { return $status; } } } return true; }
private function responseText($obj) { global $_W; $timeout = 4; load()->func('communication'); ihttp_request($_W['siteroot'] . 'app/index.php?i=' . $_W['uniacid'] . '&c=entry&m=ewei_shop&do=plugin&p=poster&method=build', array("openid" => $obj->message['from'], "content" => urlencode($obj->message['content'])), null, $timeout); return $this->responseEmpty(); }
private function getSimsimiReply($sendtext='') { $url = 'http://api.we7.cc/v1/simsimi.php?msg='.urlencode($sendtext); $response = ihttp_request($url); if (!empty($response['content'])) { return json_decode($response['content'], true); } else { return array(); } }
private function post() { global $_W, $engine; if (!in_array($this->message['msgtype'], array('text', 'image'))) { return false; } $member = $this->getMember(); $wall = pdo_fetch("SELECT * FROM " . tablename('wxwall_reply') . " WHERE rid = :rid LIMIT 1", array(':rid' => $member['rid'])); if (!empty($wall['timeout']) && $wall['timeout'] > 0 && TIMESTAMP - $member['lastupdate'] >= $wall['timeout']) { $this->endContext(); return $this->respText('由于您长时间未操作,请重新进入微信墙!'); } $this->refreshContext(); if (empty($wall['quit_command']) && $this->message['content'] == '退出' || !empty($wall['quit_command']) && $this->message['content'] == $wall['quit_command']) { $this->endContext(); return $this->respText($wall['quit_tips']); } if (empty($member['nickname']) || empty($member['avatar'])) { return $this->respText('发表话题前请完善您的基本信息,<a target="_blank" href="' . $this->createMobileUrl('register') . '">点击完善</a>。'); } $data = array('rid' => $member['rid'], 'from_user' => $_W['member']['uid'], 'type' => $this->message['type'], 'createtime' => TIMESTAMP); if (empty($wall['isshow']) && empty($member['isblacklist'])) { $data['isshow'] = 1; } else { $data['isshow'] = 0; } if ($this->message['type'] == 'text') { $data['content'] = $this->message['content']; } if ($this->message['type'] == 'image') { load()->func('communication'); $image = ihttp_request($this->message['picurl']); $partPath = IA_ROOT . '/' . $_W['config']['upload']['attachdir'] . '/'; do { $filename = "images/{$_W['uniacid']}/" . date('Y/m/') . random(30) . '.jpg'; } while (file_exists($partPath . $filename)); file_write($filename, $image['content']); $data['content'] = $filename; } if ($this->message['type'] == 'link') { $data['content'] = iserializer(array('title' => $this->message['title'], 'description' => $this->message['description'], 'link' => $this->message['link'])); } pdo_insert('wxwall_message', $data); if (!empty($member['isblacklist'])) { $content .= '你已被列入黑名单,发送的消息需要管理员审核!'; } elseif (!empty($wall['isshow'])) { $content = '发送消息成功,请等待管理员审核'; } elseif (!empty($wall['send_tips'])) { $content = $wall['send_tips']; } else { $content = '发送消息成功。'; } return $this->respText($content); }
public function get_access_token() { load()->func('communication'); $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=" . $this->appid . "&secret=" . $this->appsn; $content2 = ihttp_request($url); //$result =$this->get_curl($url); //print_r($url); $info = json_decode($content2['content'], true); $access_token = $info['access_token']; return $access_token; }
function xiaojo($msg, $openid) { $yourdb = 'ourstudio'; //小九帐号 $yourpw = 'ourstudio514'; //小九密码 $msg = urlencode($msg); $openid = urlencode($openid); $yourdb = urlencode($yourdb); $url = 'http://www.xiaojo.com/api5.php?chat=' . $msg . '&db=' . $yourdb . '&pw=' . $yourpw . '&from=' . $openid; $response = ihttp_request($url); $reply = urldecode($response['content']); return $reply; }
function getList($express, $expresssn) { $url = "http://wap.kuaidi100.com/wap_result.jsp?rand=" . time() . "&id={$express}&fromWeb=null&postid={$expresssn}"; load()->func('communication'); $resp = ihttp_request($url); $content = $resp['content']; if (empty($content)) { return array(); } preg_match_all('/\\<p\\>·(.*)\\<\\/p\\>/U', $content, $arr); if (!isset($arr[1])) { return false; } return $arr[1]; }
private function post() { global $_W; if (!in_array($this->message['msgtype'], array('text', 'image'))) { return '微信墙只能发表文字和图片'; } $member = $this->getMember(); $sql = 'SELECT * FROM ' . tablename('wxwall_reply') . ' WHERE `rid` = :rid'; $wall = pdo_fetch($sql, array(':rid' => $this->rule)); if (intval($wall['timeout']) > 0 && $wall['timeout'] + $member['lastupdate'] < TIMESTAMP) { $this->endContext(); return '由于您长时间未操作,请重新进入微信墙!'; } $this->refreshContext(); if (empty($wall['quit_command']) && $this->message['content'] == '退出' || !empty($wall['quit_command']) && $this->message['content'] == $wall['quit_command']) { $this->endContext(); return empty($wall['quit_tips']) ? '您已成功退出微信墙' : $wall['quit_tips']; } $data = array('rid' => $this->rule, 'from_user' => $_W['openid'], 'type' => $this->message['type'], 'createtime' => TIMESTAMP); if (empty($wall['isshow']) && empty($member['isblacklist'])) { $data['isshow'] = 1; } // 文字类型信息 if ($this->message['type'] == 'text') { $data['content'] = $this->message['content']; } // 图片类型信息 if ($this->message['type'] == 'image') { load()->func('file'); load()->func('communication'); $image = ihttp_request($this->message['picurl']); $filename = 'images/' . $_W['uniacid'] . '/' . date('Y/m/') . md5(TIMESTAMP + CLIENT_IP + random(12)) . '.jpg'; file_write($filename, $image['content']); $data['content'] = $filename; } pdo_insert('wxwall_message', $data); if (!empty($member['isblacklist'])) { $content = '你已被列入黑名单,发送的消息需要管理员审核!'; } elseif (!empty($wall['isshow'])) { $content = '发送消息成功,请等待管理员审核'; } elseif (!empty($wall['send_tips'])) { $content = $wall['send_tips']; } else { $content = '发送消息成功。'; } return $content; }
private function autoFinishOrders() { global $_W; $file = IA_ROOT . "/addons/ewei_shop/data/receive"; $lasttime = strtotime(@file_get_contents($file)); $interval = intval(@file_get_contents(IA_ROOT . "/addons/ewei_shop/data/receive_time")); if (empty($interval)) { $interval = 60; } $interval *= 60; $current = time(); if ($lasttime + $interval <= $current) { file_put_contents($file, date('Y-m-d H:i:s', $current)); load()->func('communication'); ihttp_request($_W['siteroot'] . "addons/ewei_shop/core/mobile/order/receive.php", null, null, 1); } }
private function post() { global $_W, $engine; if (!in_array($this->message['msgtype'], array('text', 'image'))) { return false; } $member = $this->getMember(); $wall = pdo_fetch("SELECT * FROM " . tablename('wxwall_reply') . " WHERE rid = '{$member['rid']}' LIMIT 1"); if (!empty($wall['timeout']) && $wall['timeout'] > 0 && TIMESTAMP - $member['lastupdate'] >= $wall['timeout']) { $this->endContext(); return $this->respText('由于您长时间未操作,请重新进入微信墙!'); } $this->refreshContext(); if (empty($wall['quit_command']) && $this->message['content'] == '退出' || !empty($wall['quit_command']) && $this->message['content'] == $wall['quit_command']) { $this->endContext(); return $this->respText($wall['quit_tips']); } if (empty($member['nickname'])) { return $this->respText('发表话题前请<a target="_blank" href="' . $this->createMobileUrl('register') . '">登记</a>您的信息。'); } $data = array('rid' => $member['rid'], 'from_user' => $this->message['from'], 'type' => $this->message['type'], 'createtime' => TIMESTAMP); if (empty($wall['isshow']) && empty($member['isblacklist'])) { $data['isshow'] = 1; } else { $data['isshow'] = 0; } if ($this->message['type'] == 'text') { $data['content'] = $this->message['content']; } if ($this->message['type'] == 'image') { $image = ihttp_request($this->message['picurl']); $filename = 'wxwall/' . $member['rid'] . '/' . random(30) . '.jpg'; file_write($filename, $image['content']); $data['content'] = $filename; } if ($this->message['type'] == 'link') { $data['content'] = iserializer(array('title' => $this->message['title'], 'description' => $this->message['description'], 'link' => $this->message['link'])); } pdo_insert('wxwall_message', $data); pdo_update('wxwall_members', array('lastupdate' => TIMESTAMP), array('from_user' => $this->message['from'])); $content = $wall['send_tips']; if (!empty($member['isblacklist'])) { $content .= '你已被列入黑名单,发送的消息需要管理员审核!'; } return $this->respText($content); }
private function getJsApiTicket() { $ticket = cache_read("js_api_ticket"); if (empty($ticket) || $ticket["time"] <= time()) { $token = $this->getWxAccessToken(); if (!empty($token)) { $url = "https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token={$token}&type=jsapi"; $js_token = ihttp_request($url); if (!empty($js_token)) { $content = @json_decode($js_token['content'], true); $ticket = array("ticket" => $content["ticket"], "time" => TIMESTAMP + $content["expires_in"]); cache_write("js_api_ticket", $ticket); } } } return $ticket["ticket"]; }
public function respond() { $content = $this->message['content']; global $_W; if (!strcmp($this->message['type'], 'image')) { $count = pdo_fetchcolumn("select count(*) from " . tablename("ice_picWallMain") . " where openid = :openid and uniacid = :uniacid", array(":openid" => $_W['openid'], ":uniacid" => $_W['uniacid'])); if ($count > 0) { $url = $this->buildSiteUrl($this->createMobileUrl('Index', array())); $url2 = $this->buildSiteUrl($this->createMobileUrl('getInfo', array())); $message = sprintf("您已经上传过照片到照片墙,无需重复上传。<a href='%s'>查看照片墙</a>。", $url, $url2); return $this->respText($message); } $message = $this->message; $showID = $this->getShowID(); load()->func('communication'); $image = ihttp_request($this->message['picurl']); $partPath = IA_ROOT . '/' . $_W['config']['upload']['attachdir'] . '/'; do { $filename = "images/{$_W['uniacid']}/" . date('Y/m/') . random(30) . '.jpg'; } while (file_exists($partPath . $filename)); file_write($filename, $image['content']); $data['content'] = $filename; $data = array('uniacid' => $_W['uniacid'], 'openid' => $_W['openid'], 'tousername' => $message['to'], 'showID' => $showID, 'imgurl' => $filename, 'time' => $message['time']); $data['tousername'] = $message['to']; $url = $this->buildSiteUrl($this->createMobileUrl('Index', array())); $url2 = $this->buildSiteUrl($this->createMobileUrl('getInfo', array())); $ds = pdo_insert('ice_picWallMain', $data); $message = sprintf("照片上传成功,请点击<a href='%s'>照片墙</a>,并留下<a href='%s'>您的信息</a>,方便与您取得联系。", $url, $url2); if ($ds) { return $this->respText($message); } else { return $this->respText('照片上传失败'); } } elseif (!strcmp($this->message['type'], 'text')) { return $this->respText('照片墙更多活动请了解'); } else { return $this->respText('照片上传失败'); } }
/** * 异步处理腾讯墙信息 */ public function doWebIncomingTxWall() { global $_W, $_GPC; $id = intval($_GPC['id']); $result = array('status' => 0); $lastmsgtime = intval($_GPC['lastmsgtime']); $lastuser = ''; $wall = pdo_fetchcolumn("SELECT syncwall FROM " . tablename('wxwall_reply') . " WHERE rid = :rid LIMIT 1", array(':rid' => $id)); if (empty($wall)) { message($result, '', 'ajax'); } $wall = iunserializer($wall); if (empty($wall['tx']['status'])) { message($result, '', 'ajax'); } load()->func('communication'); $response = ihttp_request('http://wall.v.t.qq.com/index.php?c=wall&a=topic&ak=801424380&t=' . $wall['tx']['subject'] . '&fk=&fn=&rnd=' . TIMESTAMP); if (empty($response['content'])) { $result['status'] = -1; message($result, '', 'ajax'); } $last = pdo_fetch("SELECT createtime, from_user FROM " . tablename('wxwall_message') . " WHERE createtime >= :createtime AND type = 'txwall' AND rid = :rid ORDER BY createtime DESC LIMIT 1", array(':createtime' => $lastmsgtime, ':rid' => $id)); if (!empty($last)) { $lastmsgtime = $last['createtime']; $lastuser = $last['from_user']; } $list = json_decode($response['content'], true); if (!empty($list['data']['info'])) { $insert = array(); foreach ($list['data']['info'] as $row) { if ($row['timestamp'] < $lastmsgtime || $lastmsgtime == $row['timestamp'] && !empty($lastuser) && $lastuser == $row['name']) { break; } $content = array('nickname' => $row['nick'], 'avatar' => !empty($row['head']) ? $row['head'] . '/120' : '', 'content' => $row['text']); $insert[] = array('rid' => $id, 'content' => iserializer($content), 'from_user' => $row['name'], 'type' => 'txwall', 'isshow' => 1, 'createtime' => $row['timestamp']); } unset($row); if (!empty($insert)) { $insert = array_reverse($insert); foreach ($insert as $row) { pdo_insert('wxwall_message', $row); } } $lastmsgtime = $row['timestamp']; $result = array('status' => 1, 'lastmsgtime' => $lastmsgtime); message($result, '', 'ajax'); } else { message($result, '', 'ajax'); } }
if ($do == 'promotion') { if (empty($_W['setting']['site']['key']) || empty($_W['setting']['site']['token'])) { message("你的程序需要在微动力云服务平台注册你的站点资料, 来接入云平台服务后才能使用推广功能.", url('cloud/profile'), 'error'); } $auth['forward'] = 'promotion'; $iframe = __to($auth); $title = '我要推广'; } if ($do == 'buyversion') { load()->func('communication'); $auth['forward'] = 'buyversion'; $auth['name'] = $_GPC['m']; $auth['is_upgrade'] = 1; $auth['version'] = $_GPC['version']; $url = __to($auth); $response = ihttp_request($url); if (is_error($response)) { message($response['message'], '', 'error'); } $response = json_decode($response['content'], true); switch ($response['message']['errno']) { case '-1': case '-2': message('模块不存在或是未有更新的版本。', url('extension/module'), 'error'); break; case '-3': message('您的交易币不足以支付此次升级费用。', url('extension/module'), 'error'); break; case '2': message('您已经购买过此升级版本,系统将直接跳转至升级界面。', url('cloud/process', array('m' => $auth['name'], 'is_upgrade' => 1, 'is_buy' => 1)), 'success'); break;
private function changeWechatSend($id, $status, $msg = '') { global $_W; $paylog = pdo_fetch("SELECT plid, openid, tag FROM " . tablename('paylog') . " WHERE tid = '{$id}' AND status = 1 AND type = 'wechat'"); if (!empty($paylog['openid'])) { $paylog['tag'] = iunserializer($paylog['tag']); $send = array('appid' => $_W['account']['payment']['wechat']['appid'], 'openid' => $paylog['openid'], 'transid' => $paylog['tag']['transaction_id'], 'out_trade_no' => $paylog['plid'], 'deliver_timestamp' => TIMESTAMP, 'deliver_status' => $status, 'deliver_msg' => $msg); $sign = $send; $sign['appkey'] = $_W['account']['payment']['wechat']['signkey']; ksort($sign); foreach ($sign as $key => $v) { $key = strtolower($key); $string .= "{$key}={$v}&"; } $send['app_signature'] = sha1(rtrim($string, '&')); $send['sign_method'] = 'sha1'; $token = account_weixin_token($_W['account']); $sendapi = 'https://api.weixin.qq.com/pay/delivernotify?access_token=' . $token; $response = ihttp_request($sendapi, json_encode($send)); $response = json_decode($response['content'], true); if (empty($response)) { message('发货失败,请检查您的公众号权限或是公众号AppId和公众号AppSecret!'); } if (!empty($response['errcode'])) { message($response['errmsg']); } } }
public function sendTplNotice($touser, $template_id, $postdata, $url = '', $topcolor = '#FF683F') { if (empty($this->account['secret']) || empty($this->account['key']) || $this->account['level'] != 4) { return error(-1, '你的公众号没有发送模板消息的权限'); } if (empty($touser)) { return error(-1, '参数错误,粉丝openid不能为空'); } if (empty($template_id)) { return error(-1, '参数错误,模板标示不能为空'); } if (empty($postdata) || !is_array($postdata)) { return error(-1, '参数错误,请根据模板规则完善消息内容'); } $token = $this->fetch_token(); if (is_error($token)) { return $token; } $data = array(); $data['touser'] = $touser; $data['template_id'] = trim($template_id); $data['url'] = trim($url); $data['topcolor'] = trim($topcolor); $data['data'] = $postdata; $data = json_encode($data); $post_url = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token={$token}"; $response = ihttp_request($post_url, $data); if (is_error($response)) { return error(-1, "访问公众平台接口失败, 错误: {$response['message']}"); } $result = @json_decode($response['content'], true); if (empty($result)) { return error(-1, "接口调用失败, 元数据: {$response['meta']}"); } elseif (!empty($result['errcode'])) { return error(-1, "访问微信接口错误, 错误代码: {$result['errcode']}, 错误信息: {$result['errmsg']},信息详情:{$this->error_code($result['errcode'])}"); } return true; }
function get_store_theme() { load()->func('communication'); $response = ihttp_request(APP_STORE_API, array('controller' => 'store', 'action' => 'api', 'do' => 'theme')); $response = json_decode($response['content'], true); $themes = '<tr><td colspan="' . count($response['message']) . '">'; $themes .= '<div class="form-group">'; foreach ($response['message'] as $key => $theme) { $theme['detail_link'] = APP_STORE_URL . trim($theme['detail_link'], '.'); $themes .= '<div class="col-sm-2" style="padding-left: 7px;margin-right: 25px;">'; $themes .= '<a href="' . $theme['detail_link'] . '" title="查看详情" target="_blank" /><img src="' . $theme['logo'] . '" /></a>'; $themes .= '<p></p><p class="text-right">'; $themes .= '<a href="' . $theme['detail_link'] . '" title="查看详情" target="_blank">' . $theme['title'] . '</a></p>'; $themes .= '</div>'; } $themes .= '</div>'; return $themes; }
$pars['page_url'] = $page['url']; $pars['comment'] = $page['comment']; $image = $this->mediaUpload($page['image']); if (is_error($image)) { return $image; } $pars['icon_url'] = $image; $pars['page_id'] = intval($id); $resp = ihttp_post($url, json_encode($pars)); if (is_error($resp)) { return $resp; } $ret = @json_decode($resp['content'], true); if (is_array($ret) && !empty($ret['data'])) { $r = $ret['data']['page_id']; return $r; } return error(-1, $resp['content']); } public function deletePage($id) { $token = $this->getAccessToken();
function wechat_build($params, $wechat) { global $_W; load()->func('communication'); if (empty($wechat['version']) && !empty($wechat['signkey'])) { $wechat['version'] = 1; } $wOpt = array(); if ($wechat['version'] == 1) { $wOpt['appId'] = $wechat['appid']; $wOpt['timeStamp'] = TIMESTAMP; $wOpt['nonceStr'] = random(8); $package = array(); $package['bank_type'] = 'WX'; $package['body'] = $params['title']; $package['attach'] = $_W['uniacid']; $package['partner'] = $wechat['partner']; $package['out_trade_no'] = $params['tid']; $package['total_fee'] = $params['fee'] * 100; $package['fee_type'] = '1'; $package['notify_url'] = $_W['siteroot'] . 'payment/wechat/notify.php'; $package['spbill_create_ip'] = CLIENT_IP; $package['time_start'] = date('YmdHis', TIMESTAMP); $package['time_expire'] = date('YmdHis', TIMESTAMP + 600); $package['input_charset'] = 'UTF-8'; ksort($package); $string1 = ''; foreach ($package as $key => $v) { $string1 .= "{$key}={$v}&"; } $string1 .= "key={$wechat['key']}"; $sign = strtoupper(md5($string1)); $string2 = ''; foreach ($package as $key => $v) { $v = urlencode($v); $string2 .= "{$key}={$v}&"; } $string2 .= "sign={$sign}"; $wOpt['package'] = $string2; $string = ''; $keys = array('appId', 'timeStamp', 'nonceStr', 'package', 'appKey'); sort($keys); foreach ($keys as $key) { $v = $wOpt[$key]; if ($key == 'appKey') { $v = $wechat['signkey']; } $key = strtolower($key); $string .= "{$key}={$v}&"; } $string = rtrim($string, '&'); $wOpt['signType'] = 'SHA1'; $wOpt['paySign'] = sha1($string); return $wOpt; } else { $package = array(); $package['appid'] = $wechat['appid']; $package['mch_id'] = $wechat['mchid']; $package['nonce_str'] = random(8); $package['body'] = $params['title']; $package['attach'] = $_W['uniacid']; $package['out_trade_no'] = $params['tid']; $package['total_fee'] = $params['fee'] * 100; $package['spbill_create_ip'] = CLIENT_IP; $package['time_start'] = date('YmdHis', TIMESTAMP); $package['time_expire'] = date('YmdHis', TIMESTAMP + 600); $package['notify_url'] = $_W['siteroot'] . 'payment/wechat/notify.php'; $package['trade_type'] = 'JSAPI'; $package['openid'] = $_W['fans']['from_user']; ksort($package, SORT_STRING); $string1 = ''; foreach ($package as $key => $v) { $string1 .= "{$key}={$v}&"; } $string1 .= "key={$wechat['signkey']}"; $package['sign'] = strtoupper(md5($string1)); $dat = array2xml($package); $response = ihttp_request('https://api.mch.weixin.qq.com/pay/unifiedorder', $dat); if (is_error($response)) { return $response; } $xml = @simplexml_load_string($response['content'], 'SimpleXMLElement', LIBXML_NOCDATA); if (strval($xml->return_code) == 'FAIL') { return error(-1, strval($xml->return_msg)); } if (strval($xml->result_code) == 'FAIL') { return error(-1, strval($xml->err_code) . ': ' . strval($xml->err_code_des)); } $prepayid = $xml->prepay_id; $wOpt['appId'] = $wechat['appid']; $wOpt['timeStamp'] = TIMESTAMP; $wOpt['nonceStr'] = random(8); $wOpt['package'] = 'prepay_id=' . $prepayid; $wOpt['signType'] = 'MD5'; ksort($wOpt, SORT_STRING); foreach ($wOpt as $key => $v) { $string .= "{$key}={$v}&"; } $string .= "key={$wechat['signkey']}"; $wOpt['paySign'] = strtoupper(md5($string)); return $wOpt; } }
function account_yixin_basic($username) { global $wechat; $auth = cache_load('yxauth:' . $username . ':'); $response = ihttp_request(YIXIN_ROOT . '/set', '', array('CURLOPT_COOKIE' => $auth['cookie'])); if (is_error($response)) { return array(); } $info = array(); preg_match('/icon\\:\\"(.*?)\\"/', $response['content'], $match); $image = ihttp_request($match[1]); file_write('headimg_' . $wechat['weid'] . '.jpg', $image['content']); preg_match('/qrCodeMix\\:\\"(.*?)\\"/', $response['content'], $match); $image = ihttp_request($match[1]); file_write('qrcode_' . $wechat['weid'] . '.jpg', $image['content']); preg_match('/signature\\:\\"(.*?)\\"/', $response['content'], $match); $info['signature'] = $match[1]; preg_match('/帐号名称<\\/div>(.*?)<\\/div>/', $response['content'], $match); $info['username'] = strip_tags($match[1]); return $info; }
$dos = array('display', 'change', 'qr', 'chat'); $do = !empty($_GPC['do']) && in_array($do, $dos) ? $do : 'display'; load()->model('account'); if ($do == 'display') { template('platform/url2qr'); } if ($do == 'change') { if ($_W['ispost']) { load()->func('communication'); $longurl = trim($_GPC['longurl']); $token = WeAccount::token(WeAccount::TYPE_WEIXIN); $url = "https://api.weixin.qq.com/cgi-bin/shorturl?access_token={$token}"; $send = array(); $send['action'] = 'long2short'; $send['long_url'] = $longurl; $response = ihttp_request($url, json_encode($send)); if (is_error($response)) { $result = error(-1, "访问公众平台接口失败, 错误: {$response['message']}"); } $result = @json_decode($response['content'], true); if (empty($result)) { $result = error(-1, "接口调用失败, 元数据: {$response['meta']}"); } elseif (!empty($result['errcode'])) { $result = error(-1, "访问微信接口错误, 错误代码: {$result['errcode']}, 错误信息: {$result['errmsg']}"); } if (is_error($result)) { exit(json_encode(array('errcode' => -1, 'errmsg' => $result['message']))); } exit(json_encode($result)); } else { exit('err');
public function delMaterial($media_id) { global $_GPC; $media_id = trim($media_id); if (empty($media_id)) { return error(-1, '素材media_id错误'); } $token = $this->getAccessToken(); if (is_error($token)) { return $token; } $url = 'https://api.weixin.qq.com/cgi-bin/material/del_material?access_token=' . $token; $data = array('media_id' => trim($media_id)); $response = ihttp_request($url, json_encode($data)); if (is_error($response)) { return error(-1, "访问公众平台接口失败, 错误: {$response['message']}"); } $result = @json_decode($response['content'], true); if (empty($result)) { } elseif (!empty($result['errcode'])) { return error(-1, "访问公众平台接口失败, 错误: {$result['errmsg']},错误详情:{$this->error_code($result['errcode'])}"); } return $result; }
public function respond() { global $_W; load()->func('communication'); $msgtype = $this->message['msgtype']; if ($msgtype == 'image') { $url = $this->module['config']['picurl']; $token = $this->module['config']['pictoken']; if ($this->module['config']['pic'] == 1 && !empty($url) && !empty($token)) { $url = $this->setsign($url, $token); $body = "<xml>" . PHP_EOL . "<ToUserName><![CDATA[{$this->message['to']}]]></ToUserName>" . PHP_EOL . "<FromUserName><![CDATA[{$this->message['from']}]]></FromUserName>" . PHP_EOL . "<CreateTime>{$this->message['time']}</CreateTime>" . PHP_EOL . "<MsgType><![CDATA[image]]></MsgType>" . PHP_EOL . "<PicUrl><![CDATA[{$this->message['picurl']}]]></PicUrl>" . PHP_EOL . "<MsgId>" . TIMESTAMP . "</MsgId>" . PHP_EOL . "</xml>"; } else { return $this->respText('图片消息接口配置错误,进在特殊消息处理模块进行正确的配置'); } } elseif ($msgtype == 'voice') { $url = $this->module['config']['voiceurl']; $token = $this->module['config']['voicetoken']; if ($this->module['config']['voice'] == 1 && !empty($url) && !empty($token)) { $url = $this->setsign($url, $token); $body = "<xml>" . PHP_EOL . "<ToUserName><![CDATA[{$this->message['to']}]]></ToUserName>" . PHP_EOL . "<FromUserName><![CDATA[{$this->message['from']}]]></FromUserName>" . PHP_EOL . "<CreateTime>{$this->message['time']}</CreateTime>" . PHP_EOL . "<MsgType><![CDATA[voice]]></MsgType>" . PHP_EOL . "<MediaId><![CDATA[{$this->message['mediaid']}]]></MediaId>" . PHP_EOL . "<Format><![CDATA[{$this->message['format']}]]></Format>" . PHP_EOL . "<MsgId>" . TIMESTAMP . "</MsgId>" . PHP_EOL . "</xml>"; } else { return $this->respText('语音消息接口配置错误,进在特殊消息处理模块进行正确的配置'); } } elseif ($msgtype == 'video') { $url = $this->module['config']['videourl']; $token = $this->module['config']['videotoken']; if ($this->module['config']['video'] == 1 && !empty($url) && !empty($token)) { $url = $this->setsign($url, $token); $body = "<xml>" . PHP_EOL . "<ToUserName><![CDATA[{$this->message['to']}]]></ToUserName>" . PHP_EOL . "<FromUserName><![CDATA[{$this->message['from']}]]></FromUserName>" . PHP_EOL . "<CreateTime>{$this->message['time']}</CreateTime>" . PHP_EOL . "<MsgType><![CDATA[video]]></MsgType>" . PHP_EOL . "<MediaId><![CDATA[{$this->message['mediaid']}]]></MediaId>" . PHP_EOL . "<ThumbMediaId><![CDATA[{$this->message['thumbmediaid']}]]></ThumbMediaId>" . PHP_EOL . "<MsgId>" . TIMESTAMP . "</MsgId>" . PHP_EOL . "</xml>"; } else { return $this->respText('视频消息接口配置错误,进在特殊消息处理模块进行正确的配置'); } } elseif ($msgtype == 'location') { $url = $this->module['config']['locationurl']; $token = $this->module['config']['locationtoken']; if ($this->module['config']['location'] == 1 && !empty($url) && !empty($token)) { $url = $this->setsign($url, $token); $body = "<xml>" . PHP_EOL . "<ToUserName><![CDATA[{$this->message['to']}]]></ToUserName>" . PHP_EOL . "<FromUserName><![CDATA[{$this->message['from']}]]></FromUserName>" . PHP_EOL . "<CreateTime>{$this->message['time']}</CreateTime>" . PHP_EOL . "<MsgType><![CDATA[location]]></MsgType>" . PHP_EOL . "<Location_X><![CDATA[{$this->message['location_x']}]]></Location_X>" . PHP_EOL . "<Location_Y><![CDATA[{$this->message['location_y']}]]></Location_Y>" . PHP_EOL . "<Scale><![CDATA[{$this->message['scale']}]]></Scale>" . PHP_EOL . "<Label><![CDATA[{$this->message['label']}]]></Label>" . PHP_EOL . "<MsgId>" . TIMESTAMP . "</MsgId>" . PHP_EOL . "</xml>"; } else { return $this->respText('位置消息接口配置错误,进在特殊消息处理模块进行正确的配置'); } } elseif ($msgtype == 'link') { $url = $this->module['config']['linkurl']; $token = $this->module['config']['linktoken']; if ($this->module['config']['link'] == 1 && !empty($url) && !empty($token)) { $url = $this->setsign($url, $token); $body = "<xml>" . PHP_EOL . "<ToUserName><![CDATA[{$this->message['to']}]]></ToUserName>" . PHP_EOL . "<FromUserName><![CDATA[{$this->message['from']}]]></FromUserName>" . PHP_EOL . "<CreateTime>{$this->message['time']}</CreateTime>" . PHP_EOL . "<MsgType><![CDATA[link]]></MsgType>" . PHP_EOL . "<Title><![CDATA[{$this->message['title']}]]></Title>" . PHP_EOL . "<Description><![CDATA[{$this->message['description']}]]></Description>" . PHP_EOL . "<Url><![CDATA[{$this->message['url']}]]></Url>" . PHP_EOL . "<MsgId>" . TIMESTAMP . "</MsgId>" . PHP_EOL . "</xml>"; } else { return $this->respText('链接消息接口配置错误,进在特殊消息处理模块进行正确的配置'); } } elseif ($msgtype == 'event' && $this->message['event'] == 'LOCATION') { $url = $this->module['config']['traceurl']; $token = $this->module['config']['tracetoken']; if ($this->module['config']['trace'] == 1 && !empty($url) && !empty($token)) { $url = $this->setsign($url, $token); $body = "<xml>" . PHP_EOL . "<ToUserName><![CDATA[{$this->message['to']}]]></ToUserName>" . PHP_EOL . "<FromUserName><![CDATA[{$this->message['from']}]]></FromUserName>" . PHP_EOL . "<CreateTime>{$this->message['time']}</CreateTime>" . PHP_EOL . "<MsgType><![CDATA[event]]></MsgType>" . PHP_EOL . "<Event><![CDATA[LOCATION]]></Event>" . PHP_EOL . "<Latitude><![CDATA[{$this->message['latitude']}]]></Latitude>" . PHP_EOL . "<Longitude><![CDATA[{$this->message['longitude']}]]></Longitude>" . PHP_EOL . "<Precision><![CDATA[{$this->message['precision']}]]></Precision>" . PHP_EOL . "<MsgId>" . TIMESTAMP . "</MsgId>" . PHP_EOL . "</xml>"; } else { return $this->respText('上传位置消息接口配置错误,进在特殊消息处理模块进行正确的配置'); } } $response = ihttp_request($url, $body, array('CURLOPT_HTTPHEADER' => array('Content-Type: text/xml; charset=utf-8'))); $result = array(); if (!is_error($response)) { $temp = @json_decode($response['content'], true); if (is_array($temp)) { $result = $this->buildResponse($temp); } else { if (!empty($response['content'])) { $obj = @simplexml_load_string(trim($response['content']), 'SimpleXMLElement', LIBXML_NOCDATA); if ($obj instanceof SimpleXMLElement) { $type = strtolower(strval($obj->MsgType)); if ($type == 'text') { $result = $this->respText(strval($obj->Content)); } if ($type == 'image') { $imid = strval($obj->Image->MediaId); $result = $this->respImage($imid); } if ($type == 'voice') { $imid = strval($obj->Voice->MediaId); $result = $this->respVoice($imid); } if ($type == 'video') { $video = array(); $video['video'] = strval($obj->Video->MediaId); $video['thumb'] = strval($obj->Video->ThumbMediaId); $result = $this->respVideo($video); } if ($type == 'music') { $music = array(); $music['title'] = strval($obj->Music->Title); $music['description'] = strval($obj->Music->Description); $music['musicurl'] = strval($obj->Music->MusicUrl); $music['hqmusicurl'] = strval($obj->Music->HQMusicUrl); $result = $this->respMusic($music); } if ($type == 'news') { $news = array(); foreach ($obj->Articles->item as $item) { $news[] = array('title' => strval($item->Title), 'description' => strval($item->Description), 'picurl' => strval($item->PicUrl), 'url' => strval($item->Url)); } $result = $this->respNews($news); } } } } if (@stristr($result, '{begin-context}') !== false) { $this->beginContext(0); $result = str_ireplace('{begin-context}', '', $result); } if (@stristr($result, '{end-context}') !== false) { $this->endContext(); $result = str_ireplace('{end-context}', '', $result); } return $result; } else { return array(); } }
} $path = IA_ROOT . '/' . $_W['config']['upload']['attachdir'] . '/'; $srcfile = $path . $file['path']; if (!empty($_GPC['mediatype'])) { load()->model('account'); $token = WeAccount::token(WeAccount::TYPE_WEIXIN); if (is_error($token)) { $result['message'] = $token['message']; frameCallback($_GPC['callback'], json_encode($result)); exit; } $media = array('type' => $_GPC['mediatype'], 'media' => $srcfile); $sendapi = "http://file.api.weixin.qq.com/cgi-bin/media/upload?access_token={$token}&type={$media['type']}"; $newData = array('media' => '@' . $media['media']); load()->func('communication'); $response = ihttp_request($sendapi, $newData); $response = json_decode($response['content'], true); if (!empty($response['type'])) { $ret = $response; } else { $ret = error($response['errcode'], $response['errmsg']); } if (is_error($ret)) { $result['error'] = $ret['errno']; $result['message'] = $ret['errno'] . ': ' . $ret['message']; frameCallback($_GPC['callback'], json_encode($result)); exit; } elseif (!empty($ret['type'])) { $result['error'] = 0; $result['media_id'] = $ret['media_id']; $result['type'] = $ret['type'];
function account_weixin_remark($fakeid, $remark, $groupid = 0) { //备注 if (account_weixin_login()) { global $_W; $username = $_W['account']['username']; if (empty($_W['cache']['wxauth'][$username])) { cache_load('wxauth:' . $username . ':'); } $auth = $_W['cache']['wxauth'][$username]; $url = WEIXIN_ROOT . '/cgi-bin/modifycontacts'; $post = array('remark' => $remark, 'tofakeuin' => $fakeid, 'token' => $auth['token'], 'lang' => 'zh_CN', 'action' => 'setremark', 't' => 'ajax-response'); $response = ihttp_request($url, $post, array('CURLOPT_COOKIE' => $auth['cookie'], 'CURLOPT_REFERER' => WEIXIN_ROOT . '/cgi-bin/contactmanage?t=user/index&pagesize=10&pageidx=0&type=0&groupid=' . $groupid . '&token=' . $auth['token'] . '&lang=zh_CN')); $result = json_decode($response['content'], 1); return $result; } return false; }
function ihttp_post($url, $data) { $headers = array('Content-Type' => 'application/x-www-form-urlencoded'); return ihttp_request($url, $data, $headers); }
function module_app_entries($name, $types = array(), $args = null) { $ts = array('rule', 'cover', 'menu', 'home', 'profile', 'shortcut', 'function'); if (empty($types)) { $types = $ts; } else { $types = array_intersect($types, $ts); } $fields = implode("','", $types); $sql = 'SELECT * FROM ' . tablename('modules_bindings') . " WHERE `module`=:module AND `entry` IN ('{$fields}') ORDER BY eid ASC"; $pars = array(); $pars[':module'] = $name; $bindings = pdo_fetchall($sql, $pars); $entries = array(); foreach ($bindings as $bind) { if (!empty($bind['call'])) { $extra = array(); $extra['Host'] = $_SERVER['HTTP_HOST']; load()->func('communication'); $urlset = parse_url($_W['siteurl']); $urlset = pathinfo($urlset['path']); $response = ihttp_request('http://127.0.0.1/' . $urlset['dirname'] . '/' . url('utility/bindcall', array('modulename' => $bind['module'], 'callname' => $bind['call'], 'args' => $args, 'uniacid' => $_W['uniacid'])), array('W' => base64_encode(iserializer($_W)))); if (is_error($response)) { continue; } $response = json_decode($response['content'], true); $ret = $response['message']; if (is_array($ret)) { foreach ($ret as $et) { $et['url'] .= '&__title=' . urlencode($et['title']); $entries[$bind['entry']][] = array('title' => $et['title'], 'url' => $et['url'], 'from' => 'call'); } } } else { if ($bind['entry'] == 'cover') { $url = murl("entry", array('eid' => $bind['eid'])); } if ($bind['entry'] == 'home') { $url = murl("entry", array('eid' => $bind['eid'])); } if ($bind['entry'] == 'profile') { $url = murl("entry", array('eid' => $bind['eid'])); } if ($bind['entry'] == 'shortcut') { $url = murl("entry", array('eid' => $bind['eid'])); } $entries[$bind['entry']][] = array('title' => $bind['title'], 'url' => $url, 'from' => 'define'); } } return $entries; }
public function sendMessage($data, $notice = false) { global $_W; $reply = pdo_fetch('select * from ' . tablename('xwz_queue_reply') . ' where uniacid=:uniacid and rid=:rid limit 1', array(':uniacid' => $_W['uniacid'], ':rid' => $data['rid'])); $type = pdo_fetch('select * from ' . tablename('xwz_queue_type') . ' where uniacid=:uniacid and rid=:rid and id=:id limit 1', array(':uniacid' => $_W['uniacid'], ':rid' => $data['rid'], ':id' => $data['typeid'])); $number = pdo_fetchcolumn('select count(*) from ' . tablename('xwz_queue_data') . ' where uniacid=:uniacid and rid=:rid and typeid=:typeid and openid<>:openid and status=0 and id<:id ', array(':uniacid' => $_W['uniacid'], ':rid' => $reply['rid'], ':typeid' => $data['typeid'], ':openid' => $data['openid'], ':id' => $data['id'])); //发送通知 $sendtype = 0; // 0不发送 1 模板消息 2 客服消息 //如果是认证服务号模板消息,如果认证号订阅号,客服消息 load()->model('account'); $account = account_fetch($_W['uniacid']); if ($account['level'] == 4) { //认证服务号 $template_id = $reply['templateid']; if (!empty($template_id)) { $sendtype = 1; } else { $sendtype = 2; } } else { if ($account['level'] == 3) { //认证订阅号 $sendtype = 2; } } $url = $_W['siteroot'] . 'app/index.php?i=' . $_W['uniacid'] . '&c=entry&m=xwz_queue&do=index&rid=' . $data['rid']; if ($sendtype == 1) { $data = json_encode(array('keyword1' => array('value' => $type['tag'] . $data['number']), 'keyword2' => array('value' => $type['title']), 'keyword3' => array('value' => $number . '位'), 'keyword4' => array('value' => $reply['heading']), 'keyword5' => array('value' => date('Y-m-d H:i', $data['createtime'])))); load()->classs('weixin.account'); $accObj = WeixinAccount::create($_W['uniacid']); $access_token = $accObj->fetch_token(); if (!empty($access_token)) { load()->func('communication'); $postarr = '{"touser":"******","template_id":"' . $template_id . '","url":"' . $url . '","data":' . $data . '}'; $res = ihttp_post('https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=' . $access_token, $postarr); } } else { if ($sendtype == 2) { $content = $notice ? "排号进度通知" : "取号成功通知\n\n"; $content .= "号码:" . $type['tag'] . $data['number'] . "\n"; $content .= "类型:" . $type['title'] . "\n"; $content .= "前面还有:" . $number . "位\n"; $content .= "商家:" . $reply['heading'] . "\n"; $content .= "取号时间:" . date('Y-m-d H:i', $data['createtime']) . "\n\n"; $content .= "<a href='{$url}'>点击查看详情</a>"; $data = array("touser" => $data['openid'], "msgtype" => "text", "text" => array('content' => urlencode($content))); load()->classs('weixin.account'); $accObj = WeixinAccount::create($_W['uniacid']); $access_token = $accObj->fetch_token(); if (!empty($access_token)) { $url = "https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token={$access_token}"; load()->func('communication'); $res = ihttp_request($url, urldecode(json_encode($data))); } } } }
function cloud_request($url, $post = '', $extra = array(), $timeout = 60) { load()->func('communication'); load()->model('setting'); $setting = setting_load('cloudip'); if (!empty($setting['cloudip'])) { $extra['ip'] = $setting['cloudip']; } return ihttp_request($url, $post, $extra, $timeout); }
$result['error'] = 0; $result['message'] = '素材不存在'; die(json_encode($result)); } load()->model('account'); $acc = WeAccount::create($acid); $token = $acc->fetch_token(); if (is_error($token)) { $result['error'] = 0; $result['message'] = $token['message']; die(json_encode($result)); } $sendapi = $apis[$data['model']]['del'] . "?access_token={$token}"; $post = array('media_id' => $data['media_id']); load()->func('communication'); $resp = ihttp_request($sendapi, json_encode($post)); if (is_error($resp)) { $result['error'] = 0; $result['message'] = $resp['message']; die(json_encode($result)); } $content = @json_decode($resp['content'], true); if (empty($content)) { $result['error'] = 0; $result['message'] = "接口调用失败, 元数据: {$response['meta']}"; die(json_encode($result)); } if (!empty($content['errcode'])) { $result['error'] = 0; $result['message'] = "访问微信接口错误, 错误代码: {$content['errcode']}, 错误信息: {$content['errmsg']},错误详情:{$acc->error_code($content['errcode'])}"; die(json_encode($result));