Пример #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;
 }
Пример #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);
    }
Пример #3
0
 public function call()
 {
     t\Webown::debug_log("财付通执行call");
     //启动一个CURL会话
     $ch = curl_init();
     // 设置curl允许执行的最长秒数
     curl_setopt($ch, CURLOPT_TIMEOUT, $this->timeOut);
     // 获取的信息以文件流的形式返回,而不是直接输出。
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
     // 从证书中检查SSL加密算法是否存在
     curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 1);
     $arr = explode("?", $this->reqContent);
     if (count($arr) >= 2 && $this->method == "post") {
         //发送一个常规的POST请求,类型为:application/x-www-form-urlencoded,就像表单提交的一样。
         curl_setopt($ch, CURLOPT_POST, 1);
         curl_setopt($ch, CURLOPT_URL, $arr[0]);
         //要传送的所有数据
         curl_setopt($ch, CURLOPT_POSTFIELDS, $arr[1]);
     } else {
         curl_setopt($ch, CURLOPT_URL, $this->reqContent);
     }
     //设置证书信息
     if ($this->certFile != "") {
         curl_setopt($ch, CURLOPT_SSLCERT, $this->certFile);
         curl_setopt($ch, CURLOPT_SSLCERTPASSWD, $this->certPasswd);
         curl_setopt($ch, CURLOPT_SSLCERTTYPE, $this->certType);
     }
     //设置CA
     if ($this->caFile != "") {
         // 对认证证书来源的检查,0表示阻止对证书的合法性的检查。1需要设置CURLOPT_CAINFO
         curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);
         curl_setopt($ch, CURLOPT_CAINFO, $this->caFile);
     } else {
         // 对认证证书来源的检查,0表示阻止对证书的合法性的检查。1需要设置CURLOPT_CAINFO
         curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
     }
     // 执行操作
     $res = curl_exec($ch);
     $this->responseCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
     if ($res == NULL) {
         t\Webown::debug_log("res ===== null");
         $this->errInfo = "call http err :" . curl_errno($ch) . " - " . curl_error($ch);
         curl_close($ch);
         return false;
     } else {
         if ($this->responseCode != "200") {
             t\Webown::debug_log("responseCode !===== 200");
             $this->errInfo = "call http err httpcode=" . $this->responseCode;
             curl_close($ch);
             return false;
         }
     }
     curl_close($ch);
     $this->resContent = $res;
     return true;
 }
Пример #4
0
function recordLog($data, $fileName)
{
    return \Common\Lib\Pclass\Webown::record_log(print_r($data, true), $fileName);
}