Esempio n. 1
0
 /**
  * 获取access_token
  */
 public static function get_token()
 {
     $cond['username'] = self::$_username;
     if (!self::$_username) {
         \Common\Lib\Pclass\Webown::debug_log("Cann't found app setting record for username="******"app settings are not full-completed for username="******"https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=" . $mp['appid'] . "&secret=" . $mp['appsecret'];
         $curl = new Curl();
         $tmpInfo = $curl->get($url);
         $arr = json_decode($tmpInfo, true);
         $access_token = $arr['access_token'];
         $data['ctime'] = time();
         $data['access_token'] = $access_token;
         M('WeixinMp')->where($cond)->save($data);
     }
     return $access_token;
 }
Esempio n. 2
0
    /**
     * 推送图文消息
     */
    public function push_news($openid, $articles)
    {
        $token = WxConfig::get_token();
        foreach ($articles as $k => $v) {
            if ($k > 0) {
                $arr .= ',';
            }
            $arr .= '{
					 "title":"' . $v['title'] . '",
					 "description":"' . $v['description'] . '",
					 "url":"' . $v['description'] . '",
					 "picurl":"' . $v['picurl'] . '"
				 }';
        }
        $data = '{
				    "touser":"******",
				    "msgtype":"news",
				    "news":{
				        "articles": [' . $arr . ']
				    }
				}';
        $url = "https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token=" . $token;
        Webown::debug_log('$$articles=======' . $data);
        $curl = new Curl();
        $tmpInfo = $curl->post($url, $data);
        Webown::debug_log('$$tmpInfo=======' . $tmpInfo);
    }
Esempio n. 3
0
 /**
  * 获取发送短信的令牌
  * @param Boolean  $flag  是否请求新令牌:true-请求(不管本地Redis是否保存令牌)  false-不请求(首先从本地Redis中取,没有的话再向服务器请求)
  * @return String 令牌
  */
 private static function getAccessToken($flag)
 {
     if (!$flag) {
         // 首先从本地Redis中取
         $accesstoken = MyRedis::get('sms.accesstoken');
         if ($accesstoken) {
             return $accesstoken;
         }
     }
     $url = "https://oauth.api.189.cn/emp/oauth2/v3/access_token";
     $postData['grant_type'] = 'client_credentials';
     $postData['app_id'] = YsSmSService::APPID;
     $postData['app_secret'] = YsSmSService::APPSECRET;
     foreach ($postData as $key => $value) {
         $post[] = $key . '=' . $value;
     }
     $curl = new t\Curl();
     $resultJson = $curl->post($url, implode('&', $post));
     $resObj = json_decode($resultJson);
     $expiers = intval($resObj->expires_in);
     $accesstoken = $resObj->access_token;
     if ($expiers > 0) {
         MyRedis::set('sms.accesstoken', $accesstoken, $expiers);
     }
     return $accesstoken;
 }
Esempio n. 4
0
 /**
  * 查询票的状态
  * @param string $ticket_sn 票的序列号  可传单个或者多个   多个用英文逗号隔开   
  */
 public function ticket_use_timeAct($ticket_sn)
 {
     $type = 'get';
     if ($type == 'get') {
         $token = $this->getToken(md5('ticketusetime'));
         $url = $this->apiurl . '/sys/ticket/ticket_use_time?token=' . $token . '&ticketNos=' . $ticket_sn;
         $curl = new t\Curl();
         $return = $curl->get($url);
         $return = json_decode($return, true);
     } else {
         $param = array('ticketNos' => $ticket_sn);
         $token = $this->getToken(md5('ticketusetime'));
         $data[] = $param;
         $url = $this->apiurl . '/sys/ticket/ticket_use_time?token=' . $token;
         $curlData = json_encode($data);
         $curl = new t\Curl();
         $return = $curl->post($url, $curlData, 1);
     }
     return $return;
 }
Esempio n. 5
0
 protected function resetSolrCourseData($debug = false)
 {
     $envFlag = defined('__ENV_FLAG__') ? __ENV_FLAG__ : 'PRODUCTION_SERVER';
     // 环境标志
     if ($envFlag == 'DEV_SERVER') {
         // 开发环境
         $url = 'http://192.168.0.9:8983/solr/course_video/dataimport?command=full-import&wt=json';
     } elseif ($envFlag == 'PRODUCTION_SERVER') {
         // 生产环境
         $url = 'http://192.168.0.34:8983/solr/course_video/dataimport?command=full-import&wt=json';
     } else {
         // 测试环境
         $url = 'http://192.168.0.42:8983/solr/course_video/dataimport?command=full-import&wt=json';
     }
     $curl = new p\Curl();
     $result = $curl->get($url);
     if ($debug) {
         $this->_log('[更新Solr课程信息]:' . $result);
     }
 }