private function _handlePostObj($postObj)
 {
     $MsgType = strtolower((string) $postObj->MsgType);
     $result = array('from' => self::$_from_id = (string) htmlspecialchars($postObj->FromUserName), 'to' => self::$_my_id = (string) htmlspecialchars($postObj->ToUserName), 'time' => (int) $postObj->CreateTime, 'type' => (string) $MsgType);
     if (property_exists($postObj, 'MsgId')) {
         $result['id'] = $postObj->MsgId;
     }
     switch ($result['type']) {
         case 'text':
             $result['content'] = (string) $postObj->Content;
             // Content 消息内容
             break;
         case 'location':
             $result['X'] = (double) $postObj->Location_X;
             // Location_X 地理位置纬度
             $result['Y'] = (double) $postObj->Location_Y;
             // Location_Y 地理位置经度
             $result['S'] = (double) $postObj->Scale;
             // Scale 地图缩放大小
             $result['I'] = (string) $postObj->Label;
             // Label 地理位置信息
             break;
         case 'image':
             $result['url'] = (string) $postObj->PicUrl;
             // PicUrl 图片链接,开发者可以用HTTP GET获取
             $result['mid'] = (string) $postObj->MediaId;
             // MediaId 图片消息媒体id,可以调用多媒体文件下载接口拉取数据。
             break;
         case 'video':
             $result['mid'] = (string) $postObj->MediaId;
             // MediaId 图片消息媒体id,可以调用多媒体文件下载接口拉取数据。
             $result['thumbmid'] = (string) $postObj->ThumbMediaId;
             // ThumbMediaId 视频消息缩略图的媒体id,可以调用多媒体文件下载接口拉取数据。
             break;
         case 'link':
             $result['title'] = (string) $postObj->Title;
             $result['desc'] = (string) $postObj->Description;
             $result['url'] = (string) $postObj->Url;
             break;
         case 'voice':
             $result['mid'] = (string) $postObj->MediaId;
             $result['format'] = (string) $postObj->Format;
             if (property_exists($postObj, Recognition)) {
                 $result['txt'] = (string) $postObj->Recognition;
             }
             break;
         case 'event':
             $result['event'] = strtolower((string) $postObj->Event);
             switch ($result['event']) {
                 case 'subscribe':
                 case 'scan':
                     if (property_exists($postObj, EventKey)) {
                         $result['key'] = str_replace('qrscene_', '', (string) $postObj->EventKey);
                         $result['ticket'] = (string) $postObj->Ticket;
                     }
                     break;
                 case 'location':
                     $result['la'] = (string) $postObj->Latitude;
                     $result['lo'] = (string) $postObj->Longitude;
                     $result['p'] = (string) $postObj->Precision;
                     break;
                 case 'click':
                     $result['key'] = (string) $postObj->EventKey;
                     break;
             }
     }
     return $result;
 }
Esempio n. 2
0
 private static function _custom($type, $keyword = '')
 {
     global $_G;
     loadcache('wechat_response');
     $response =& $_G['cache']['wechat_response'];
     $query = $type == 'text' ? $response['query']['text'][$keyword] : $response['query']['subscribe'];
     if ($query) {
         if ($query == self::$keyword) {
             return 1;
         }
         echo WeChatServer::getXml4Txt($query);
         exit;
     }
     return 0;
 }
 private static function _custom($type, $keyword = '')
 {
     global $_G;
     loadcache('wechat_response');
     $response =& $_G['cache']['wechat_response'];
     $query = $type == 'text' ? $response['query']['text'][$keyword] : $response['query']['subscribe'];
     if ($query) {
         if ($query == self::$keyword) {
             return 1;
         }
         if (preg_match("/^\\[resource=(\\d+)\\]/", $query, $r)) {
             $resource = C::t('#wechat#mobile_wechat_resource')->fetch($r[1]);
             if (!$resource['type']) {
                 $list = array(array('title' => $resource['data']['title'], 'desc' => $resource['data']['desc'], 'pic' => $resource['data']['pic'], 'url' => $resource['data']['url']));
             } else {
                 $mergeids = array_keys($resource['data']['mergeids']);
                 $sresource = C::t('#wechat#mobile_wechat_resource')->fetch_all($mergeids);
                 $list = array();
                 foreach ($resource['data']['mergeids'] as $id => $order) {
                     $list[] = array('title' => $sresource[$id]['data']['title'], 'desc' => $sresource[$id]['data']['desc'], 'pic' => $sresource[$id]['data']['pic'], 'url' => $sresource[$id]['data']['url']);
                 }
             }
             echo WeChatServer::getXml4RichMsgByArray($list);
             exit;
         } else {
             echo WeChatServer::getXml4Txt($query);
         }
         exit;
     }
     return 0;
 }
<?php

// @see http://mp.weixin.qq.com/wiki/index.php?title=%E9%AB%98%E7%BA%A7%E7%BE%A4%E5%8F%91%E6%8E%A5%E5%8F%A3#.E4.B8.8A.E4.BC.A0.E5.9B.BE.E6.96.87.E6.B6.88.E6.81.AF.E7.B4.A0.E6.9D.90
WeChatServer::$ERRCODE_MAP = array('send success' => '发送成功', 'send fail' => '发送失败', 'err(10001)' => '涉嫌广告', 'err(20001)' => '涉嫌政治', 'err(20004)' => '涉嫌社会', 'err(20002)' => '涉嫌色情', 'err(20006)' => '涉嫌违法犯罪', 'err(20008)' => '涉嫌欺诈', 'err(20013)' => '涉嫌版权', 'err(22000)' => '涉嫌互推(互相宣传)', 'err(21000)' => '涉嫌其他');
Esempio n. 5
0
<?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);
});
Esempio n. 6
0
 private function _handlePostObj($postObj)
 {
     $MsgType = strtolower((string) $postObj->MsgType);
     $result = array('from' => self::$_from_id = (string) htmlspecialchars($postObj->FromUserName), 'to' => self::$_my_id = (string) htmlspecialchars($postObj->ToUserName), 'time' => (int) $postObj->CreateTime, 'type' => (string) $MsgType);
     if (property_exists($postObj, 'MsgId')) {
         $result['id'] = $postObj->MsgId;
     }
     switch ($result['type']) {
         case 'text':
             $result['content'] = (string) $postObj->Content;
             // Content 消息内容
             break;
         case 'location':
             $result['X'] = (double) $postObj->Location_X;
             // Location_X 地理位置纬度
             $result['Y'] = (double) $postObj->Location_Y;
             // Location_Y 地理位置经度
             $result['S'] = (double) $postObj->Scale;
             // Scale 地图缩放大小
             $result['I'] = (string) $postObj->Label;
             // Label 地理位置信息
             break;
         case 'image':
             $result['url'] = (string) $postObj->PicUrl;
             // PicUrl 图片链接,开发者可以用HTTP GET获取
             $result['mid'] = (string) $postObj->MediaId;
             // MediaId 图片消息媒体id,可以调用多媒体文件下载接口拉取数据。
             break;
         case 'video':
             $result['mid'] = (string) $postObj->MediaId;
             // MediaId 图片消息媒体id,可以调用多媒体文件下载接口拉取数据。
             $result['thumbmid'] = (string) $postObj->ThumbMediaId;
             // ThumbMediaId 视频消息缩略图的媒体id,可以调用多媒体文件下载接口拉取数据。
             break;
         case 'link':
             $result['title'] = (string) $postObj->Title;
             // 消息标题
             $result['desc'] = (string) $postObj->Description;
             // 消息描述
             $result['url'] = (string) $postObj->Url;
             // 消息链接
             break;
         case 'voice':
             $result['mid'] = (string) $postObj->MediaId;
             // 语音消息媒体id,可以调用多媒体文件下载接口拉取该媒体
             $result['format'] = (string) $postObj->Format;
             // 语音格式:amr
             if (property_exists($postObj, Recognition)) {
                 $result['txt'] = (string) $postObj->Recognition;
                 // 语音识别结果,UTF8编码
             }
             break;
         case 'event':
             $result['event'] = strtolower((string) $postObj->Event);
             // 事件类型,subscribe(订阅)、unsubscribe(取消订阅)、CLICK(自定义菜单点击事???
             switch ($result['event']) {
                 // case 'unsubscribe': // 取消订阅
                 case 'subscribe':
                     // 订阅
                 // 订阅
                 case 'scan':
                     // 扫描二维码
                     if (property_exists($postObj, EventKey)) {
                         // 扫描带参数二维码事件
                         $result['key'] = str_replace('qrscene_', '', (string) $postObj->EventKey);
                         // 事件KEY值,qrscene_为前缀,后面为二维码的参数值
                         $result['ticket'] = (string) $postObj->Ticket;
                     }
                     break;
                 case 'location':
                     // 上报地理位置事件
                     $result['la'] = (string) $postObj->Latitude;
                     // 地理位置纬度
                     $result['lo'] = (string) $postObj->Longitude;
                     // 地理位置经度
                     $result['p'] = (string) $postObj->Precision;
                     // 地理位置精度
                     break;
                 case 'click':
                     // 自定义菜单事件
                     $result['key'] = (string) $postObj->EventKey;
                     // 事件KEY值,与自定义菜单接口中KEY值对???
                     break;
                 case "masssendjobfinish":
                     // 高级群发接口
                     $result['id'] = (string) $postObj->MsgID;
                     // 群发的消息ID
                     $result['status'] = (bool) 'send success' === $postObj->Status;
                     // 群发结果
                     $result['msg'] = (string) self::$ERRCODE_MAP[$postObj->Status];
                     // TotalCount >= FilterCount
                     // FilterCount = SentCount + ErrorCount
                     $result['total'] = (string) $postObj->TotalCount;
                     // group_id下粉丝数;或者openid_list中的粉丝数
                     $result['fact'] = (string) $postObj->FilterCount;
                     // 实际发送的粉丝数(部分设置黑白名单)
                     $result['hit'] = (string) $postObj->SentCount;
                     // 发送成功的粉丝数
                     $result['miss'] = (string) $postObj->ErrorCount;
                     // 发送失败的粉丝数
                     break;
             }
     }
     return $result;
 }