protected function messageEvent($postObj)
 {
     $event = $postObj->Event;
     switch ($event) {
         case 'subscribe':
             $user = User::model()->findByAttributes(array('udid' => $postObj->FromUserName));
             if (!$user) {
                 $user = new User();
                 $user->udid = $postObj->FromUserName;
                 $user->create_at = $this->getTime();
             } else {
                 $user->status = 1;
                 $user->times++;
             }
             $user->save();
             WX::updateInfo($postObj->FromUserName);
             $this->returnText('love,love', $postObj);
             break;
         case 'unsubscribe':
             $user = User::model()->findByAttributes(array('udid' => $postObj->FromUserName));
             if ($user) {
                 $user->status = 0;
                 $user->update_at = $this->getTime();
                 $user->save();
             }
             $this->returnText('dont,love,love', $postObj);
             break;
         case 'LOCATION':
             $user = User::model()->findByAttributes(array('udid' => $postObj->FromUserName));
             if ($user) {
                 $user->x = floatval($postObj->Latitude);
                 $user->y = floatval($postObj->Longitude);
                 $user->locate = floatval($postObj->Precision);
                 $user->update_at = $this->getTime();
                 $user->save();
             }
             $this->returnText('get x,y', $postObj);
             break;
         case 'CLICK':
             $keyvalue = $postObj->EventKey;
             if ($keyvalue == 'TEM_COMMUNITY') {
                 //创建临时的网点
                 CommunityController::createOrUpdate($postObj->FromUserName);
             }
             $this->returnText('创建临时网点成功', $postObj);
             break;
     }
 }
 /**
  * 把微信的图片上传到又拍云服务器上
  * @param string $medil
  * @return string
  */
 public function updateWxImage($medil)
 {
     if (substr($medil, 0, 4) == 'http') {
         return $medil;
     }
     $accesstoken = WX::actionAccessToken();
     $imgurl = "https://api.weixin.qq.com/cgi-bin/media/get?access_token={$accesstoken}&media_id={$medil}";
     $upyun = new UpYun(UPYUN_BUCKET, UPYUN_USER, UPYUN_PASSWORD);
     $fh = file_get_contents($imgurl);
     if (empty($fh)) {
         return "";
     }
     $md5 = md5($this->openid);
     $path = "/" . substr($md5, 0, 4) . '/' . $md5 . '/' . $medil . '.jpg';
     $rsp = $upyun->writeFile($path, $fh, True);
     // 上传图片,自动创建目录
     return UPYUN_CDN . $path;
 }
 private function getUmbrellaUrl($umbrellaid)
 {
     $url = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=%s&redirect_uri=%s&response_type=code&scope=snsapi_userinfo&state=wxbutton#wechat_redirect";
     $umbrella = urlencode('http://umbrella.centurywar.cn/umbrella/info/id/' . $umbrellaid);
     $tem = sprintf($url, APP_ID, $umbrella);
     $ret = WX::getShortUrl($tem);
     if (empty($ret)) {
         return $tem;
     }
     return $ret;
 }
示例#4
0
 public static function getShortUrl($url)
 {
     $accesstoken = WX::actionAccessToken();
     $urlpost = "https://api.weixin.qq.com/cgi-bin/shorturl?access_token={$accesstoken}";
     $params = array('action' => 'long2short', 'long_url' => $url);
     $response = Yii::app()->curl->post($urlpost, $params, 'json');
     Yii::log($url, 'trace', 'GET short url');
     $response = json_decode($response, true);
     Yii::log(CVarDumper::dumpAsString($response), 'error', 'GET short url');
     if ($response['errcode'] == 0) {
         return $response['short_url'];
     } else {
         if ($response['errcode'] == 41001) {
             // 				WX::actionAccessToken(true);
         }
         return "";
     }
 }
示例#5
0
<?php

header('Access-Control-Allow-Origin:*');
require_once 'lib/SnsNetwork.php';
require_once 'lib/SnsSigCheck.php';
require_once 'include/log.php';
require_once 'include/app_info.php';
require_once 'include/wx.php';
$appid = $_REQUEST['appid'];
$cmd = $_REQUEST['cmd'];
if (!$appid) {
    die('请指定AppID');
}
if (!AppInfo::query($appid)) {
    die('AppID尚未配置');
}
$data = null;
switch ($cmd) {
    case 'sign':
        // 获取分享的签名信息
        $data = WX::get_sign($appid, $_REQUEST['url']);
        break;
    default:
        die("未知指令");
}
echo json_encode($data);
示例#6
0
文件: mpwx.php 项目: hugolong/weixiao
<?php

include_once '../common.php';
include_once S_ROOT . './module/wx.php';
//define your token
define("TOKEN", $_SC['api_token']);
$wx = new WX();
$wx->run();