cpmsg(lang('plugin/wechat', 'wsq_menu_name_empty'), '', 'error'); } if (!$sub_button['keyurl']) { cpmsg(lang('plugin/wechat', 'wsq_menu_keyurl_empty'), '', 'error'); } $parse = parse_url($sub_button['keyurl']); $item = array('type' => $parse['host'] ? 'view' : 'click', 'name' => convertname($sub_button['name']), $parse['host'] ? 'url' : 'key' => $sub_button['keyurl']); $sub_buttons[] = $item; } $item = array('name' => convertname($button['name']), 'sub_button' => $sub_buttons); $pubmenu['button'][] = $item; } } require_once DISCUZ_ROOT . './source/plugin/wechat/wechat.lib.class.php'; $_G['wechat']['setting'] = unserialize($_G['setting']['mobilewechat']); $wechat_client = new WeChatClient($_G['wechat']['setting']['wechat_appId'], $_G['wechat']['setting']['wechat_appsecret']); if ($wechat_client->setMenu($pubmenu)) { cpmsg(lang('plugin/wechat', 'wsq_menu_pub_succeed'), 'action=plugins&operation=config&do=' . $pluginid . '&identifier=wechat&pmod=menu_setting', 'succeed'); } else { cpmsg(lang('plugin/wechat', 'wsq_menu_pub_error', array('errno' => $wechat_client->error())), '', 'error'); } } else { cpmsg('setting_update_succeed', 'action=plugins&operation=config&do=' . $pluginid . '&identifier=wechat&pmod=menu_setting', 'succeed'); } } function convertname($str) { return urlencode(diconv($str, CHARSET, 'UTF-8')); } function buttoncmp($a, $b) {
public static function getnewname($openid) { global $_G; if (!$_G['wechat']['setting']) { $_G['wechat']['setting'] = unserialize($_G['setting']['mobilewechat']); } $wechat_client = new WeChatClient($_G['wechat']['setting']['wechat_appId'], $_G['wechat']['setting']['wechat_appsecret']); $userinfo = $wechat_client->getUserInfoById($openid); if ($userinfo) { $defaultusername = substr(WeChatEmoji::clear($userinfo['nickname']), 0, 15); loaducenter(); $user = uc_get_user($defaultusername); if (!empty($user)) { $defaultusername = cutstr($defaultusername, 7, '') . '_' . random(5); } } else { $defaultusername = '******' . random(5); } return $defaultusername; }
public static function checkIsSuc($res) { $result = true; if (is_string($res)) { $res = json_decode($res, true); } if (isset($res['errcode']) && 0 !== (int) $res['errcode']) { array_push(self::$ERROR_LOGS, $res); $result = false; self::$ERROR_NO = $res['errcode']; } return $result; }
showsetting(lang('plugin/wechat', 'wechat_disableregrule'), 'setting[wechat_disableregrule]', $setting['wechat_disableregrule'], 'radio', 0, 0, lang('plugin/wechat', 'wechat_disableregrule_comment')); showsetting(lang('plugin/wechat', 'wechat_confirmtype'), 'setting[wechat_confirmtype]', $setting['wechat_confirmtype'], 'radio', 0, 0, lang('plugin/wechat', 'wechat_confirmtype_comment')); showsetting(lang('plugin/wechat', 'wechat_user'), 'setting[wechat_user]', $setting['wechat_user'], 'text', 0, 0, lang('plugin/wechat', 'wechat_user_comment')); showsetting(lang('plugin/wechat', 'wechat_newusergroupid'), '', '', $usergroups, 0, 0, lang('plugin/wechat', 'wechat_newusergroupid_comment')); showtagfooter('tbody'); showtableheader(); showsubmit('settingsubmit'); showtablefooter(); showformfooter(); } else { if ($_GET['setting']['wechat_mtype'] == 2 && !$_GET['setting']['wechat_appId']) { cpmsg(lang('plugin/wechat', 'wechat_at_need'), '', 'error'); } if ($_GET['setting']['wechat_appId'] && $_GET['setting']['wechat_appsecret']) { require_once DISCUZ_ROOT . './source/plugin/wechat/wechat.lib.class.php'; $wechat_client = new WeChatClient($_GET['setting']['wechat_appId'], $_GET['setting']['wechat_appsecret']); if (!$wechat_client->getAccessToken(1, 1)) { cpmsg(lang('plugin/wechat', 'wechat_at_geterror'), '', 'error'); } $option = array('scene_id' => 100000, 'expire' => 30, 'ticketOnly' => 1); $ticket = $wechat_client->getQrcodeTicket($option); if (!$wechat_client->getQrcodeImgUrlByTicket($ticket)) { cpmsg(lang('plugin/wechat', 'wechat_at_qrgeterror'), '', 'error'); } } $_GET['setting']['wechat_qrtype'] = !$_GET['setting']['wechat_mtype'] ? 3 : 0; $_GET['setting']['wechat_token'] = $_GET['setting']['wechat_token'] ? $_GET['setting']['wechat_token'] : random(16); if ($_FILES['wechat_qrcode']['tmp_name']) { $upload = new discuz_upload(); if (!$upload->init($_FILES['wechat_qrcode'], 'common', random(3, 1), random(8)) || !$upload->save()) { cpmsg($upload->errormessage(), '', 'error');
/** * [Discuz!] (C)2001-2099 Comsenz Inc. * This is NOT a freeware, use is subject to license terms * * $Id: masssend_setting.inc.php 35024 2014-10-14 07:43:43Z nemohou $ */ if (!defined('IN_DISCUZ') || !defined('IN_ADMINCP')) { exit('Access Denied'); } require_once DISCUZ_ROOT . './source/plugin/wechat/wechat.lib.class.php'; require_once DISCUZ_ROOT . './source/plugin/wechat/setting.class.php'; WeChatSetting::menu(); define('PMODURL', 'action=plugins&operation&config&identifier=wechat&pmod=masssend_setting&ac='); $_G['wechat']['setting'] = unserialize($_G['setting']['mobilewechat']); $wechat_client = new WeChatClient($_G['wechat']['setting']['wechat_appId'], $_G['wechat']['setting']['wechat_appsecret']); if (!submitcheck('addsubmit') && !submitcheck('sendsubmit') && !submitcheck('delsubmit')) { $ac = !empty($_GET['ac']) ? $_GET['ac'] : ''; if (!$ac) { showtips(lang('plugin/wechat', 'mass_main_tips')); echo '<a href="' . ADMINSCRIPT . '?' . PMODURL . 'add" class="addtr">' . lang('plugin/wechat', 'mass_create') . '</a>'; $ppp = 10; $page = max(1, intval($_GET['page'])); $start = ($page - 1) * $ppp; $count = C::t('#wechat#mobile_wechat_masssend')->count(); $msg = C::t('#wechat#mobile_wechat_masssend')->range($start, $ppp, 'DESC'); $multi = multi($count, $ppp, $page, ADMINSCRIPT . '?' . PMODURL); showformheader('plugins&operation=config&identifier=wechat&pmod=masssend_setting&ac=send', 'enctype'); showtableheader(lang('plugin/wechat', 'mass_list'), ''); showsubtitle(array(lang('plugin/wechat', 'mass_text_oper'), lang('plugin/wechat', 'mass_text_send'), lang('plugin/wechat', 'mass_type'), lang('plugin/wechat', 'mass_created_at'), 'MSG_ID', lang('plugin/wechat', 'mass_finish_at'), lang('plugin/wechat', 'mass_status'), lang('plugin/wechat', 'mass_totalcount'), lang('plugin/wechat', 'mass_filtercount'), lang('plugin/wechat', 'mass_sendcount'), lang('plugin/wechat', 'mass_errorcount'))); foreach ($msg as $m) {
if ($_GET['fromapp'] == 'index') { $op = 'access'; } else { $op = $_GET['op']; } $selfurl = $_G['siteurl'] . 'plugin.php?id=wechat&mobile=2&key=' . $keyenc . ($_GET['referer'] ? '&referer=' . urlencode($_GET['referer']) : '') . ($_GET['username'] ? '&username='******'username']) : '') . '&ac='; if (!$_G['wechat']['setting']['wechat_qrtype'] && IN_WECHAT && !$openid) { if ($_G['wechat']['setting']['wechat_mtype'] != 2) { if (!empty($_G['cookie']['wechatopenid'])) { $openid = authcode($_G['cookie']['wechatopenid'], 'DECODE', $_G['config']['security']['authkey']); } if (!$openid) { showmessage('wechat:wechat_undefined'); } } else { $wechat_client = new WeChatClient($_G['wechat']['setting']['wechat_appId'], $_G['wechat']['setting']['wechat_appsecret']); $openid = !empty($_G['cookie']['wechatopenid']) ? authcode($_G['cookie']['wechatopenid'], 'DECODE', $_G['config']['security']['authkey']) : ''; if (!$openid) { if (empty($_GET['oauth'])) { $redirect_uri = $wechat_client->getOauthConnectUri($selfurl . $ac . '&oauth=yes'); dheader('location: ' . $redirect_uri); } else { $tockeninfo = $wechat_client->getAccessTokenByCode($_GET['code']); $openid = $tockeninfo['openid']; dsetcookie('wechatopenid', authcode($openid, 'ENCODE', $_G['config']['security']['authkey']), 86400); } } } } elseif ($openid) { dsetcookie('wechatopenid', authcode($openid, 'ENCODE', $_G['config']['security']['authkey']), 86400); }
<?php /* |-------------------------------------------------------------------------- | Wechat Routes |-------------------------------------------------------------------------- */ // 测试 // Route::any('api/wechat/test', array('as' => 'wechat.test', 'uses' => 'Cooper\\Wechat\\Controllers\\WechatController@test')); //测试 Facade Route::any('/weixin', function () { // //获取接收到的消息 // $message = WeChatServer::getMessage(); // return $message; // //获取消息发送者的用户id // $userId = WeChatServer::getFromUserId(); // return $userId; // //获取接收消息的公众账户appId // $appId = WeChatServer::getAppId(); // return $appId; // //创建用来发送给用户的信息 // $text = 'hellow laravel facades'; // $response = WeChatServer::getXml4Txt($text); // return $response; //测试 $userId = WeChatServer::getFromUserId(); $sendTextMsg = WeChatClient::sendTextMsg($userId, 'hello laravel'); dd($sendTextMsg); });
<?php # ###################################################################### # mp.weixin.qq.com # ###################################################################### WeChatClient::$_URL_PLATFORM_ROOT = 'https://mp.weixin.qq.com'; WeChatClient::$_URL_API_ROOT = 'https://api.weixin.qq.com'; WeChatClient::$_URL_FILE_API_ROOT = 'http://file.api.weixin.qq.com'; WeChatClient::$_USERINFO_LANG = 'zh_CN'; // @see http://mp.weixin.qq.com/wiki/index.php?title=%E5%85%A8%E5%B1%80%E8%BF%94%E5%9B%9E%E7%A0%81%E8%AF%B4%E6%98%8E WeChatClient::$ERRCODE_MAP = array('-1' => '系统繁忙', '0' => '请求成功', '40001' => '获取access_token时AppSecret错误,或者access_token无效', '40002' => '不合法的凭证类型', '40003' => '不合法的OpenID', '40004' => '不合法的媒体文件类型', '40005' => '不合法的文件类型', '40006' => '不合法的文件大小', '40007' => '不合法的媒体文件id', '40008' => '不合法的消息类型', '40009' => '不合法的图片文件大小', '40010' => '不合法的语音文件大小', '40011' => '不合法的视频文件大小', '40012' => '不合法的缩略图文件大小', '40013' => '不合法的APPID', '40014' => '不合法的access_token', '40015' => '不合法的菜单类型', '40016' => '不合法的按钮个数', '40017' => '不合法的按钮个数', '40018' => '不合法的按钮名字长度', '40019' => '不合法的按钮KEY长度', '40020' => '不合法的按钮URL长度', '40021' => '不合法的菜单版本号', '40022' => '不合法的子菜单级数', '40023' => '不合法的子菜单按钮个数', '40024' => '不合法的子菜单按钮类型', '40025' => '不合法的子菜单按钮名字长度', '40026' => '不合法的子菜单按钮KEY长度', '40027' => '不合法的子菜单按钮URL长度', '40028' => '不合法的自定义菜单使用用户', '40029' => '不合法的oauth_code', '40030' => '不合法的refresh_token', '40031' => '不合法的openid列表', '40032' => '不合法的openid列表长度', '40033' => '不合法的请求字符,不能包含\\uxxxx格式的字符', '40035' => '不合法的参数', '40038' => '不合法的请求格式', '40039' => '不合法的URL长度', '40050' => '不合法的分组id', '40051' => '分组名字不合法', '41001' => '缺少access_token参数', '41002' => '缺少appid参数', '41003' => '缺少refresh_token参数', '41004' => '缺少secret参数', '41005' => '缺少多媒体文件数据', '41006' => '缺少media_id参数', '41007' => '缺少子菜单数据', '41008' => '缺少oauth code', '41009' => '缺少openid', '42001' => 'access_token超时', '42002' => 'refresh_token超时', '42003' => 'oauth_code超时', '43001' => '需要GET请求', '43002' => '需要POST请求', '43003' => '需要HTTPS请求', '43004' => '需要接收者关注', '43005' => '需要好友关系', '44001' => '多媒体文件为空', '44002' => 'POST的数据包为空', '44003' => '图文消息内容为空', '44004' => '文本消息内容为空', '45001' => '多媒体文件大小超过限制', '45002' => '消息内容超过限制', '45003' => '标题字段超过限制', '45004' => '描述字段超过限制', '45005' => '链接字段超过限制', '45006' => '图片链接字段超过限制', '45007' => '语音播放时间超过限制', '45008' => '图文消息超过限制', '45009' => '接口调用超过限制', '45010' => '创建菜单个数超过限制', '45015' => '回复时间超过限制', '45016' => '系统分组,不允许修改', '45017' => '分组名字过长', '45018' => '分组数量超过上限', '46001' => '不存在媒体数据', '46002' => '不存在的菜单版本', '46003' => '不存在的菜单数据', '46004' => '不存在的用户', '47001' => '解析JSON/XML内容错误', '48001' => 'api功能未授权', '50001' => '用户未授权该api'); # ######################################################################
$data['action_name'] = 'QR_SCENE'; } $data = self::__json_encode($data); $res = self::post($url, $data); $res = json_decode($res, true); if (self::checkIsSuc($res)) { return $ticketOnly ? $res['ticket'] : array('ticket' => $res['ticket'], 'expire' => $res['expire_seconds']); } return null; } //*************** json_encode unicode escape fix ***************** private static function __json_encode($obj) { if (defined('JSON_UNESCAPED_UNICODE')) { // >= php 5.4 return json_encode($obj, JSON_UNESCAPED_UNICODE); } else { return preg_replace("/\\\\u([a-f0-9]{4})/e", "iconv('UCS-4LE','UTF-8',pack('V', hexdec('U\$1')))", json_encode($obj)); } } } # ###################################################################### # admin.wechat.com # ###################################################################### WeChatClient::$_URL_PLATFORM_ROOT = 'https://admin.wechat.com'; WeChatClient::$_URL_API_ROOT = 'https://api.wechat.com'; WeChatClient::$_URL_FILE_API_ROOT = 'http://file.api.weixin.qq.com'; WeChatClient::$_USERINFO_LANG = 'en'; # @see http://admin.wechat.com/wiki/index.php?title=Return_Codes WeChatClient::$ERRCODE_MAP = array('-1' => 'System busy', '0' => 'Request succeeded', '40001' => 'Verification failed', '40002' => 'Invalid certificate type', '40003' => 'Invalid Open ID', '40004' => 'Invalid media file type', '40005' => 'Invalid file type', '40006' => 'Invalid file size', '40007' => 'Invalid media file ID', '40008' => 'Invalid message type', '40009' => 'Invalid image file size', '40010' => 'Invalid audio file size', '40011' => 'Invalid video file size', '40012' => 'Invalid thumbnail file size', '40013' => 'Invalid App ID', '40014' => 'Invalid access token', '40015' => 'Invalid menu type', '40016' => 'Invalid button quantity', '40017' => 'Invalid button quantity', '40018' => 'Invalid button name length', '40019' => 'Invalid button KEY length', '40020' => 'Invalid button URL length', '40021' => 'Invalid menu version', '40022' => 'Invalid sub-menu levels', '40023' => 'Invalid sub-menu button quantity', '40024' => 'Invalid sub-menu button type', '40025' => 'Invalid sub-menu button name length', '40026' => 'Invalid sub-menu button KEY length', '40027' => 'Invalid sub-menu button URL length', '40028' => 'Invalid custom menu user', '40029' => 'Invalid oauth code', '40030' => 'Invalid refresh token', '40031' => 'Invalid openid list', '40032' => 'Invalid openid list length', '40033' => 'Invalid request characters: The character "\\uxxxx" cannot be included.', '40035' => 'Invalid parameters', '40038' => 'Invalid request format', '40039' => 'Invalid URL length', '40050' => 'Invalid group ID', '40051' => 'Invalid group name', '41001' => 'Parameter missing: access token', '41002' => 'Parameter missing: appid', '41003' => 'Parameter missing: refresh token', '41004' => 'Parameter missing: secret', '41005' => 'Multimedia file data missing', '41006' => 'Parameter missing: media id', '41007' => 'Sub-menu data missing', '41008' => 'Parameter missing: oauth code', '41009' => 'Parameter missing: openid', '42001' => 'access token timed out', '42002' => 'refresh token timed out', '42003' => 'oauth code timed out', '43001' => 'GET request required', '43002' => 'POST request required', '43003' => 'HTTPS request required', '43004' => 'The other user is not yet a follower', '43005' => 'The other user is not yet a follower', '44001' => 'Multimedia file is empty', '44002' => 'POST package is empty', '44003' => 'Rich media message is empty', '44004' => 'Text message is empty', '45001' => 'Error source: multimedia file size', '45002' => 'Message contents too long', '45003' => 'Title too long', '45004' => 'Description too long', '45005' => 'URL too long', '45006' => 'Image URL too long', '45007' => 'Audio play time over limit', '45008' => 'Rich media messages over limit', '45009' => 'Error source: interface call', '45010' => 'Message quantity over limit', '45015' => 'Response too late', '45016' => 'System group cannot be changed.', '45017' => 'System name too long', '45018' => 'Too many groups', '46001' => 'Media data missing', '46002' => 'This menu version doesn\'t exist.', '46003' => 'This menu data doesn\'t exist.', '46004' => 'This user doesn\'t exist.', '47001' => 'Error while extracting JSON/XML contents', '48001' => 'Unauthorized API function', '50001' => 'The user is not authorized for this API'); # ######################################################################
@readfile($file); } else { $qrsize = !empty($_GET['qrsize']) ? $_GET['qrsize'] : 2; $file = $dir . 'qr_index.jpg'; if (!file_exists($file) || !filesize($file)) { dmkdir($dir); require_once DISCUZ_ROOT . 'source/plugin/mobile/qrcode.class.php'; QRcode::png($url . 'index&source=pcscan', $file, QR_ECLEVEL_Q, $qrsize); } dheader('Content-Disposition: inline; filename=qrcode_index.jpg'); dheader('Content-Type: image/pjpeg'); @readfile($file); } exit; } require_once DISCUZ_ROOT . './source/plugin/wechat/wechat.lib.class.php'; $wechat_client = new WeChatClient($_G['wechat']['setting']['wechat_appId'], $_G['wechat']['setting']['wechat_appsecret']); list($ticket, $code) = explode("\t", authcode($_G['cookie']['wechat_ticket'], 'DECODE')); if ($ticket) { $file = $dir . md5($ticket) . '_' . $code . '.jpg'; if (!file_exists($file) || !filesize($file)) { dmkdir($dir); $qrcode = dfsockopen($wechat_client->getQrcodeImgUrlByTicket($ticket)); $fp = @fopen($file, 'wb'); @fwrite($fp, $qrcode); @fclose($fp); } dheader('Content-Disposition: inline; filename=qrcode.jpg'); dheader('Content-Type: image/pjpeg'); @readfile($file); }