Example #1
0
 public function actionIndex()
 {
     //接口校验
     if (isset($_GET['echostr'])) {
         $this->wechat->_valid();
     } else {
         WechatCheck::_responseMsg();
     }
     Yii::app()->end();
 }
Example #2
0
 /**
  * 
  * @return string
  */
 public static function getPRepay($object, Users $weixinuser)
 {
     $count = Pic::model()->count("user_id=:user_id", array(":user_id" => $weixinuser->user_id));
     if ($count < 20) {
         Yii::app()->cache->set("qys_pic_save_" . $weixinuser->user_id, $count);
         $content = "亲爱的用户,已经为你开启保存图片服务,当前已经保存了" . $count . "张,还能保存" . (20 - $count) . "张。";
     } else {
         $content = "亲爱的用户,您已经保存了20张图片,将不再给予保存。";
     }
     WechatCheck::_transmitText($object, $content);
 }
Example #3
0
 /**
  * 微信处理图片
  */
 public static function fitImage($obj, Users $user)
 {
     #判断图片是否开启
     $pic_save_status = Yii::app()->cache->get("qys_pic_save_" . $user->user_id);
     $count = Pic::model()->count("user_id=:user_id", array(":user_id" => $user->user_id));
     if ($pic_save_status == false) {
         $content = "没有开启保存图片功能,该图片不会被服务器保存.";
     } elseif ($count >= 20) {
         $content = "图片已经超过20张,不再做保存。";
     } else {
         $count = Pic::model()->count("user_id=:user_id", array(":user_id" => $user->user_id));
         #获得图片地址
         $pic = file_get_contents($obj->PicUrl);
         $picname = time() . "_" . $user->user_id . ($count + 1) . ".gif";
         $pic_path = Yii::getPathOfAlias('webroot') . '/date/uplaod/';
         $pic_show_path = '/date/uplaod/';
         file_put_contents($pic_path . $picname, $pic);
         if (file_exists($pic_path . $picname)) {
             #小图保存
             $simage = Yii::app()->image->load($pic_path . $picname);
             $simage->resize(80, 80);
             $simage->save($pic_path . "s_" . $picname);
             #中图保存
             $mimage = Yii::app()->image->load($pic_path . $picname);
             $mimage->resize(240, 240);
             $mimage->save($pic_path . "m_" . $picname);
             #大图保存
             $bimage = Yii::app()->image->load($pic_path . $picname);
             $bimage->save($pic_path . "b_" . $picname);
             $userPic = new Pic();
             $picArray = array('user_id' => $user->user_id, 'pic_type' => 0, 'pic_s_img' => $pic_show_path . "s_" . $picname, 'pic_m_img' => $pic_show_path . "m_" . $picname, 'pic_b_img' => $pic_show_path . "n_" . $picname);
             $userPic->setAttributes($picArray);
             if ($userPic->validate() && $userPic->save()) {
                 $content = "图片已经保存。";
             } else {
                 $content = "图片保存失败,请重新发送。";
             }
         } else {
             $content = "保存失败。";
         }
         unlink($pic_path . $picname);
     }
     WechatCheck::_transmitText($obj, $content);
 }
Example #4
0
 /**
  * 检查access_token是否起作用
  */
 public static function checkAccessToken()
 {
     if (self::$access_token_endtime === null || self::$access_token_endtime < time()) {
         //            重新申请access_token
         $json = file_get_contents(self::BASE_WEIXIN_URL . self::TOKEN_URL . "&appid=" . self::APPID . "&secret=" . self::APPSECRET);
         if ($json) {
             $result = json_decode($json, true);
             self::$access_token = $result['access_token'];
             self::$access_token_endtime = time() + $result['expires_in'];
         }
     }
 }
Example #5
0
 /**
  * 
  */
 public static function getRollRestul($object, $weixinuser)
 {
     #增加今天是否已经抽过奖的处理
     $pertime = $weixinuser->purview;
     $time = mktime(0, 0, 0, date("m"), date("d"), date("Y"));
     if ((int) $pertime === $time) {
         $content = "亲爱的用户,您今天已经抽过奖啦,请明天再来试试吧!";
     } else {
         $result = rand(1, 10);
         if ($result === 1) {
             $content = "恭喜您:中奖啦,您将获得本平台提供的免费商品,马上去发货。";
         } else {
             $content = "很遗憾,今天又没中奖,这是个鸟系统抽了N次不中,无聊割草!";
         }
         $result = Users::model()->updateByPk($weixinuser->user_id, array("purview" => $time));
         if (!$result) {
             $content = "命中失败,再抽一次!";
         }
     }
     WechatCheck::_transmitText($object, $content);
 }