Example #1
0
function get_base_information($openid)
{
    $accessToken = get_access_token();
    $url = sprintf('https://api.weixin.qq.com/cgi-bin/user/info?access_token=%s&openid=%s&lang=zh_CN', $accessToken, $openid);
    $res = http_get_data($url);
    return $res;
}
 /**
  * 组装配置信息
  * @param $url
  * return json
  */
 public function InitConfig($url)
 {
     $info = get_token_appinfo();
     //appId $appid = 'wxaa3ddf43e19630ee';    //$secret = '2946a5c98f49087208212f9bcba69379';
     $appid = $info['appid'];
     $secret = $info['secret'];
     //生成签名的时间戳  //生成签名的随机串
     $nonceStr = $timestamp = 12345678901;
     $access_token = get_access_token();
     if (empty($access_token)) {
         $auth = file_get_contents("https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=" . $appid . "&secret=" . $secret);
         $token = json_decode($auth);
         $t = get_object_vars($token);
         //转换成数组
         $access_token = $t['access_token'];
         //输出access_token
     }
     $jsapi_contents = file_get_contents("https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token=" . $access_token . "&type=jsapi");
     $jsapi = json_decode($jsapi_contents);
     $j = get_object_vars($jsapi);
     $jsapi_ticket = $j['ticket'];
     //get JSAPI
     $and = "jsapi_ticket=" . $jsapi_ticket . "&noncestr=" . $nonceStr . "&timestamp=" . $timestamp . "&url=" . $url . "";
     $signature = sha1($and);
     $arr['appId'] = $appid;
     $arr['timestamp'] = $timestamp;
     $arr['nonceStr'] = $nonceStr;
     $arr['signature'] = $signature;
     echo json_encode($arr);
     //输出json数据
 }
Example #3
0
function get_video_upload_info()
{
    //get youtube access token
    $access_token = get_access_token();
    $sql = "SELECT p.profilePlaceId, p.nicename, l.businessName, l.subscribe,u.state,v.link,cam.brand, cam.tag1, cam.tag2 FROM businessProfile AS p\n\t\tLEFT JOIN businessList AS l ON l.id = p.profilePlaceId\n\t\tLEFT JOIN businessUserGroup AS u ON u.gId = l.userGroupId\n\t\tLEFT JOIN businessvanitylink AS v ON v.placeId = l.id\n\t\tLEFT JOIN campaigndetails AS cam ON cam.posterId = l.id\n\t\tLEFT JOIN businessCustom AS c ON c.customPlaceId = p.profilePlaceId\n\t\tWHERE p.profilePlaceId =  {$_SESSION['placeIdVid']}\n\t\tLIMIT 1";
    $result1 = mysql_query($sql) or die(mysql_error());
    $row = mysql_fetch_object($result1);
    $title = $_REQUEST['videotitle'];
    if ($title == '') {
        $title = $row->businessName . ' Video';
    }
    //create a video obj with temp info
    $video_title = $title;
    $video_desc = $row->businessName . ' -- ' . strtolower($row->tag1) . ' ' . strtolower($row->tag2) . ' by ' . $row->brand . ' ' . 'http://camrally.com/' . $row->nicename . '.html';
    $video_keywords = $row->businessName . ', ' . 'Camrally, Campaign';
    //setup request body as xml
    $xml_str = implode('', array('<?xml version="1.0"?>', '<entry xmlns="http://www.w3.org/2005/Atom" xmlns:media="http://search.yahoo.com/mrss/" xmlns:yt="http://gdata.youtube.com/schemas/2007">', '<media:group>', '<media:title type="plain">' . $video_title . '</media:title>', '<media:description type="plain">' . $video_desc . '</media:description>', '<media:category scheme="http://gdata.youtube.com/schemas/2007/categories.cat">Animals</media:category>', '<media:keywords>' . $video_keywords . '</media:keywords>', '<yt:accessControl action="list" permission="denied"/>', '</media:group>', '</entry>'));
    //use curl to call youtube api
    $ch = curl_init('http://gdata.youtube.com/action/GetUploadToken');
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_HTTPHEADER, array('Authorization: Bearer ' . $access_token, 'GData-Version: 2', 'X-GData-Key: key=AI39si4ZlJR_8DWIfv_VchkxZn4R3NJ0NzVli9zFkoc35FCP83ps_exV2Qe8v5zSkbxRDw3_TPbuOpWeuN_bhaAl3UzOfk-CJA', 'Content-Type: application/atom+xml; charset=UTF-8'));
    curl_setopt($ch, CURLOPT_POSTFIELDS, $xml_str);
    //send request
    $xml_response = curl_exec($ch);
    //close connection
    curl_close($ch);
    $result = simplexml_load_string($xml_response);
    if ($result->getName() === 'errors') {
        return array('post_url' => 'broke', 'upload_token' => 'not_a_real_token');
    }
    return array('post_url' => (string) $result->url, 'upload_token' => (string) $result->token);
}
 function _thumb_media_id($cover_id)
 {
     $cover = get_cover($cover_id);
     $driver = C('PICTURE_UPLOAD_DRIVER');
     if ($driver != 'Local' && !file_exists(SITE_PATH . $cover['path'])) {
         // 先把图片下载到本地
         $pathinfo = pathinfo(SITE_PATH . $cover['path']);
         mkdirs($pathinfo['dirname']);
         $content = wp_file_get_contents($cover['url']);
         $res = file_put_contents(SITE_PATH . $cover['path'], $content);
         if ($res) {
             return '';
         }
     }
     $path = $cover['path'];
     if (!$path) {
         return '';
     }
     $param['type'] = 'thumb';
     $param['media'] = '@' . realpath(SITE_PATH . $path);
     $url = 'https://api.weixin.qq.com/cgi-bin/material/add_material?access_token=' . get_access_token();
     $res = post_data($url, $param, true);
     if (isset($res['errcode']) && $res['errcode'] != 0) {
         return '';
     }
     $map['cover_id'] = $cover_id;
     $map['manager_id'] = $this->mid;
     $this->where($map)->setField('thumb_media_id', $res['media_id']);
     return $res['media_id'];
 }
Example #5
0
 function checkUser()
 {
     /**
      * QQ互联登录,授权成功后会回调此地址
      * 必须要用授权的request token换取access token
      * 访问QQ互联的任何资源都需要access token
      * 目前access token是长期有效的,除非用户解除与第三方绑定
      * 如果第三方发现access token失效,请引导用户重新登录QQ互联,授权,获取access token
      */
     //授权成功后,会返回用户的openid
     //检查返回的openid是否是合法id
     if (!is_valid_openid($_REQUEST["openid"], $_REQUEST["timestamp"], $_REQUEST["oauth_signature"], $this->skey)) {
         return false;
     }
     //tips
     //这里已经获取到了openid,可以处理第三方账户与openid的绑定逻辑
     //但是我们建议第三方等到获取accesstoken之后在做绑定逻辑
     //用授权的request token换取access token
     $access_str = get_access_token($this->akey, $this->skey, $_REQUEST["oauth_token"], $_REQUEST['oauth_token_secret'], $_REQUEST["oauth_vericode"]);
     //echo "access_str:$access_str\n";
     $result = array();
     parse_str($access_str, $result);
     //error
     if (isset($result["error_code"])) {
         return false;
     }
     //获取access token成功后也会返回用户的openid
     //我们强烈建议第三方使用此openid
     //检查返回的openid是否是合法id
 public function replyCode()
 {
     $openId = (string) $this->postObj->FromUserName;
     $customerInfo = get_customer_info($openId);
     $customerId = $customerInfo['id'];
     $url = 'https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token=%s';
     $accessToken = get_access_token();
     $url = sprintf($url, $accessToken);
     $data['expire_seconds'] = 1800;
     $data['action_name'] = $this->actionName;
     $data['action_info'] = array('scene' => array('scene_id' => (int) $customerId));
     $data = json_encode($data);
     //                $replyMessage = A('ReplyMessage');
     //            $replyMessage->setText('传入的JSON数据为' . $data);
     //            $replyMessage->replyTextMessage();
     //            return;
     $res = http_post_json($url, $data);
     $res = json_decode($res);
     $ticket = $res->ticket;
     $ticket = urlencode($ticket);
     $replyMessage = A('ReplyMessage');
     $picUrl = "https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket=" . $ticket;
     $url = $picUrl;
     $title = '您的专属二维码';
     $description = '其它用户通过扫描该二维码关注我们,将自动成为您的朋友。';
     $news[] = array('title' => $title, 'description' => $description, 'picurl' => $picUrl, 'url' => $url);
     $replyMessage->setNews($news);
     $replyMessage->replyNewsMessage();
 }
 function move_group($id, $group_id)
 {
     is_array($id) || ($id = explode(',', $id));
     $data['uid'] = $map['uid'] = array('in', $id);
     // $data ['group_id'] = $group_id; //TODO 前端微信用户只能有一个微信组
     $res = M('auth_group_access')->where($data)->delete();
     $data['group_id'] = $group_id;
     foreach ($id as $uid) {
         $data['uid'] = $uid;
         $res = M('auth_group_access')->add($data);
         // 更新用户缓存
         D('Common/User')->getUserInfo($uid, true);
     }
     $group = $this->find($group_id);
     // 同步到微信端
     if (C('USER_GROUP') && !empty($group['wechat_group_id'])) {
         $url = 'https://api.weixin.qq.com/cgi-bin/groups/members/update?access_token=' . get_access_token();
         $map['token'] = get_token();
         $follow = M('public_follow')->where($map)->field('openid, uid')->select();
         foreach ($follow as $v) {
             if (empty($v['openid'])) {
                 continue;
             }
             $param['openid'] = $v['openid'];
             $param['to_groupid'] = $group['wechat_group_id'];
             $param = JSON($param);
             $res = post_data($url, $param);
         }
     }
     return $group;
 }
 public function getAndUploadWxImage($mediaId)
 {
     $access_token = get_access_token();
     //下载图片
     $url = "http://file.api.weixin.qq.com/cgi-bin/media/get?access_token={$access_token}&media_id={$mediaId}";
     $fileInfo = $this->downloadWeixinFile($url);
     return $this->saveWeixinFile($fileInfo);
 }
Example #9
0
	public function __CONSTRUCT() {
		$this->token = TOKEN;
		$this->appID = APP_ID;
		$this->appSecret = APP_SECRET;
		$this->accessToken = get_access_token();
		//$this->accessToken = RUNTIME_PATH . TOKEN . '_access_token';
		//if (! file_exists ( $this->accessToken )) {
		//	$this->AccessTokenGet ();
		//}
	}
Example #10
0
 public function run()
 {
     $moreRequestMessage = getMoreRequestMessage();
     $this->fromusername = $moreRequestMessage["fromusername"];
     $this->tousername = $moreRequestMessage["tousername"];
     $this->msgtype = $moreRequestMessage["msgtype"];
     //是否开启菜单
     if (!!$this->config->item("ismenu")) {
         $access_token = get_access_token();
         createmenu($access_token);
     }
     //判断消息类型
     switch ($this->msgtype) {
         case 'event':
             //判断事件类型
             $this->event = $moreRequestMessage["event"];
             $this->handleEventMessage($this->event);
             break;
         case 'text':
             $keyMessage = getKeyRequestTextMessage();
             $content = $keyMessage['content'];
             $this->responseTextMessage($content);
             break;
         case 'image':
             $keyMessage = getKeyRequestImageMessage();
             $picurl = $keyMessage['picurl'];
             $mediaid = $keyMessage['mediaid'];
             $this->responseImageMessage($picurl, $mediaid);
             break;
         case 'location':
             $keyMessage = getKeyRequestLocationMessage();
             $location_x = $keyMessage['location_x'];
             $location_y = $keyMessage['location_y'];
             $scale = $keyMessage['scale'];
             $label = $keyMessage['label'];
             $this->responseLocationMessage($location_x, $location_y, $scale, $label);
             break;
         case 'link':
             $keyMessage = getKeyRequestLinkMessage();
             $title = $keyMessage['title'];
             $description = $keyMessage['description'];
             $url = $keyMessage['url'];
             $this->responseLinkMessage($title, $description, $url);
             break;
         case 'voice':
             $keyMessage = getKeyRequestVoiceMessage();
             $mediaid = $keyMessage['mediaid'];
             $format = $keyMessage['format'];
             $this->responseVoiceMessage($mediaid, $format);
             break;
         default:
             $this->responseUnknownMessage();
             break;
     }
 }
Example #11
0
function get_acc_tokens($request_token, $request_token_secret)
{
    $retarr = get_access_token(OAUTH_CONSUMER_KEY, OAUTH_CONSUMER_SECRET, $request_token, $request_token_secret, false, true, true);
    if (!empty($retarr)) {
        list($info, $headers, $body, $body_parsed) = $retarr;
        if ($info['http_code'] == 200 && !empty($body)) {
            return $retarr[3];
        }
    } else {
        echo "Empty array" . "\n";
    }
}
Example #12
0
 function getaccess_token()
 {
     //$where = array('token' => get_token());
     //$this->thisWxUser = M('member_public')->where($where)->find();
     //$url_get = (('https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=' . $this->thisWxUser['appid']) . '&secret=') . $this->thisWxUser['secret'];
     //$json = json_decode($this->curlGet($url_get));
     //if (!$json->errmsg) {
     //} else {
     //	$this->error((('获取access_token发生错误:错误代码' . $json->errcode) . ',微信返回错误信息:') . $json->errmsg);
     //}
     //return $json->access_token;
     return get_access_token();
 }
Example #13
0
 public function sendtempmsg($openid, $template_id, $url, $data, $topcolor = '#FF0000')
 {
     $xml = '{"touser":"******","template_id":"' . $template_id . '","url":"' . $url . '","topcolor":"' . $topcolor . '","data":' . $data . '}';
     $res = $this->curlPost('https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=' . get_access_token(), $xml);
     $res = json_decode($res, true);
     // 记录日志
     if ($res['errcode'] == 0) {
         addWeixinLog($xml, 'post');
     }
     $senddata = array('openid' => $openid, 'template_id' => $template_id, 'MsgID' => $res['msgid'], 'message' => $data, 'sendstatus' => $res['errcode'] == 0 ? 0 : 1, 'token' => get_token(), 'ctime' => time());
     M('tmplmsg')->add($senddata);
     return $res;
 }
 function test()
 {
     $param['touser'] = "******";
     $param['msgtype'] = "text";
     $param['text']['content'] = "Hello World!";
     $param['customservice']['kf_account'] = "zbyy@nyfslg";
     $param_json = json_encode($param);
     dump($param_json);
     $token = get_token();
     $access_token = get_access_token($token);
     $url = "https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token=" . $access_token;
     $return = http_post($url, $param_json);
     dump($return);
 }
Example #15
0
/**
 * 依赖于数据库2小时缓存获取token,ticket
 * @param $appid
 * @param $secret
 * @return array    包含token,ticket的数组
 */
function db_get_token_ticket($appid, $secret)
{
    $token = "                                                                                                                                                                                                                                                                ";
    $ticket = "                                                                                                                                                                                                                                                                ";
    $params = array(array($appid, SQLSRV_PARAM_IN), array($token, SQLSRV_PARAM_OUT), array($ticket, SQLSRV_PARAM_OUT));
    sp_execute("{call weixin_get_token(?,?,?)}", $params);
    if (strlen($token) == 0 || strlen($ticket) == 0) {
        $token = get_access_token($appid, $secret);
        $ticket = get_jsapi_ticket($token);
        $params = array(array($appid, SQLSRV_PARAM_IN), array($token, SQLSRV_PARAM_IN), array($ticket, SQLSRV_PARAM_IN));
        sp_execute("{call weixin_set_token(?,?,?)}", $params);
    }
    return array("token" => $token, "ticket" => $ticket);
}
 public function indexAction()
 {
     //取出openId数据组
     $accessToken = get_access_token();
     $url = 'https://api.weixin.qq.com/cgi-bin/user/get?access_token=' . $accessToken;
     $jsonData = http_get_data($url);
     $data = json_decode($jsonData);
     $openids = $data->data->openid;
     //取出openid对应的其它信息
     $userInfo = array();
     foreach ($openids as $key => $value) {
         $userInfo[] = get_weichat_user_info($value, $accessToken);
     }
     $customer = D('Customer');
     $customer->addUserInfo($userInfo);
     $this->success('列表获取完成', U('Index/index'), 2);
 }
Example #17
0
 public function update_wxmenu()
 {
     $hset = $this->check_wechat();
     $data = [];
     for ($i = 1; $i <= 3; $i++) {
         $data[$i] = json_decode($this->ad_cache->get_wx_menu($hset, $i), true);
     }
     $menu = generate_menu_from_redis($data);
     $access_token = get_access_token(APPID, APPSECRET);
     $info = json_decode(post_tab($access_token, json_encode($menu, JSON_UNESCAPED_UNICODE)), true);
     if ($info["errcode"] == "0") {
         $res = "更新自定义菜单成功";
     } else {
         $res = "更新自定义菜单失败\n错误代码:" . $info["errcode"] . "\n错误信息:" . $info["errmsg"];
     }
     echo $res;
 }
Example #18
0
 private function getJsApiTicket_temp($token = '')
 {
     empty($token) && ($token = get_token());
     $key = 'jsapi_ticket_' . $token;
     $res = S($key);
     if ($res !== false) {
         return $res;
     }
     $access_token = get_access_token();
     $url = 'https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token=' . $access_token . '&type=jsapi';
     $tempArr = json_decode(file_get_contents($url), true);
     if (@array_key_exists('ticket', $tempArr)) {
         S($key, $tempArr['ticket'], 7200);
         return $tempArr['ticket'];
     } else {
         return 0;
     }
 }
Example #19
0
 function send_ewm()
 {
     //-----获取access_token
     $access_token = get_access_token();
     //----生成二维码
     $ewmid = I('ewmid');
     $postUrl = 'https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token=' . $access_token;
     $postJson = '{"action_name": "QR_LIMIT_SCENE", "action_info": {"scene": {"scene_id": ' . $ewmid . '}}}';
     $return = json_decode(http_post($postUrl, $postJson), true);
     if ($return['errcode'] == 0) {
         $ticket = $return['ticket'];
         $qr_code = 'https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket=' . UrlEncode($ticket);
         $this->qr_code_save($qr_code, $ewmid);
         $this->success('生成二维码成功');
     } else {
         $this->error('生成二维码失败,错误的返回码是:' . $res['errcode'] . ', 错误的提示是:' . $res['errmsg']);
     }
 }
Example #20
0
function get_access_token($appid, $secret, $retry = 0)
{
    $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid={$appid}&secret={$secret}";
    $json = file_get_contents($url);
    $rs = json_decode($json, TRUE);
    if (!empty($rs) && empty($rs['errcode'])) {
        return $rs;
    }
    if ($rs['errcode'] == -1) {
        if ($retry < 5) {
            sleep(10);
            return get_access_token($appid, $secret, $retry + 1);
        }
        //outlog("ERROR: Refresh access token failed with retry $retry times. $rs[errcode]($rs[errmsg])");
    } else {
        //outlog("ERROR: $rs[errmsg]. (CODE=$rs[errcode])");
    }
    return 0;
}
 public function del_menu()
 {
     //dump($menuid);die();
     $access_token = get_access_token();
     $url_post = 'https://api.weixin.qq.com/cgi-bin/menu/delete?access_token=' . $access_token;
     //$header [] = "content-type: application/x-www-form-urlencoded; charset=UTF-8";
     $res = D('CustomMenu')->curlGet($url_post);
     $res = json_decode($res, true);
     if ($res['errcode'] == 0) {
         $result = D('CustomMenuType')->set_menu_local(1, $id = null);
         if ($result) {
             $this->success('全部菜单删除成功,数据更新成功!');
         } else {
             $this->error('全部菜单删除成功,数据更新失败!');
         }
     } else {
         $this->error(error_msg($res));
     }
 }
 public function getAddressPackage()
 {
     $appId = $this->appId;
     //appID
     $scope = 'jsapi_address';
     //说明获取编辑地址权限
     $signType = 'SHA1';
     //加密方式为sha1
     $timeStamp = time();
     //时间戳
     $nonceStr = $this->_createNonceStr();
     //以下开始进行签名
     $url = get_current_url();
     $accessToken = get_access_token();
     $string = 'accesstoken=' . $accessToken . '&appid=' . $appId . '&noncestr=' . $nonceStr . '&timestamp=' . $timeStamp . '&url=' . $url;
     $addrSign = SHA1($string);
     $addressPage = array('appId' => $appId, 'scope' => $scope, 'signType' => $signType, 'addrSign' => $addrSign, 'timeStamp' => $timeStamp, 'nonceStr' => $nonceStr);
     return $addressPage;
 }
Example #23
0
 function user_detail($user_id)
 {
     $upload_url = UPLOAD_URL;
     $access_token = get_access_token($user_id);
     $this->pdb->update("bom_users", array("access_token" => $access_token), "user_id='{$user_id}'");
     $user_prefix_and_table = get_user_prefix_and_table($user_id);
     $user_detail_prefix = $user_prefix_and_table['user_detail_prefix'];
     $user_detail_table = $user_prefix_and_table['user_detail_table'];
     $brandimage = $user_detail_prefix . "_brand_logo";
     $companyimage = $user_detail_prefix . "_company_photo";
     $displayname = $user_detail_prefix . "_display_name";
     $companyname = $user_detail_prefix . "_company_name";
     $country = $user_detail_prefix . "_country";
     $state = $user_detail_prefix . "_state";
     $city = $user_detail_prefix . "_city";
     $mobile = $user_detail_prefix . "_contact_number";
     $query = "SELECT  U.user_id userid, U.user_type usertype, U.login_email emailid, U.is_otp_verified, U.is_notification, U.access_token, U.status,\n                          CONCAT('{$upload_url}','/',{$brandimage}) brandimage, \n                          CONCAT('{$upload_url}','/',{$companyimage}) companyimage,\n                          {$displayname} displayname, {$companyname} companyname,\n                          {$country} country, {$state} state, {$city} city,\n                          {$mobile} mobile \n                          FROM bom_users U \n                          JOIN  {$user_detail_table}  ON U.user_id = {$user_detail_table}.user_id\n                          WHERE U.user_id ='{$user_id}'";
     $result = $this->pdb->query($query);
     return $result[0];
 }
Example #24
0
function send_notify($val)
{
    global $limit, $notify_user, $notify_tmpl, $tmpl_url;
    if ($val > $limit) {
        return;
    }
    $has_send_today = file_get_contents('/shell/sendtag.log');
    if ($has_send_today + 24 * 3600 > time()) {
        return;
    }
    $notify_tmpl['data']['first']['value'] = '土壤湿度不足' . $val . '%,请及时浇水。';
    $access_token = get_access_token();
    $tmpl_url = $tmpl_url . $access_token;
    foreach ($notify_user as $k => $user_id) {
        $notify_tmpl['touser'] = $user_id;
        $msg = json_encode($notify_tmpl);
        //file_put_contents('/tmp/msg.log', $tmpl_url."\n".$msg."\n", FILE_APPEND);
        post_method($tmpl_url, $msg);
    }
    file_put_contents('/shell/sendtag.log', time());
}
 public function tongbuyonghuhao()
 {
     //同步用户号
     $token = get_token();
     $access_token = get_access_token($token);
     $url = 'https://api.weixin.qq.com/cgi-bin/user/get?access_token=' . $access_token . '';
     $users = json_decode(wp_file_get_contents($url), true);
     if (!$users['total']) {
         $this->error("更新失败");
     }
     $data = $users['data'];
     $openidArray = $data['openid'];
     foreach ($openidArray as $key => $openid) {
         $userInfo = getWeixinUserInfo($openid, $token);
         $map['openid'] = $userInfo['openid'];
         $data['nickname'] = $userInfo['nickname'];
         $data['sex'] = $userInfo['sex'];
         $data['city'] = $userInfo['city'];
         $data['country'] = $userInfo['country'];
         $data['province'] = $userInfo['province'];
         $data['language'] = $userInfo['language'];
         $data['headimgurl'] = $userInfo['headimgurl'];
         $data['subscribe_time'] = $userInfo['subscribe_time'];
         $data['status'] = $userInfo['subscribe'];
         $data['token'] = $token;
         $result_id = M('Follow')->where($map)->getField('id');
         if ($result_id) {
             //更新
             $data['id'] = $result_id;
             M('Follow')->save($data);
             unset($data);
         } else {
             //新增
             D('Common/Follow')->init_follow($userInfo['openid']);
         }
     }
     $this->success("同步完成!");
 }
Example #26
0
 public function __construct()
 {
     parent::__construct();
     $this->load->config('wechatconfig');
     $this->load->database();
     $this->load->library('session');
     $this->load->helper('url');
     $this->load->helper('common');
     $this->load->helper('menu');
     //保存accesstoken到session
     $this->accesstoken = get_access_token();
     $access = array('accesstoken' => $this->accesstoken);
     $this->session->set_userdata($access);
     //自定义错误消息回复
     if (!!$this->config->item('debug')) {
         set_error_handler("errorHandler");
     }
     ignore_user_abort(true);
     //set_time_limit(0);//SAE不支持
     date_default_timezone_set('PRC');
     //'Asia/Shanghai'
     //页面编码
     header("Content-type: text/html; charset=utf-8");
 }
Example #27
0
function get_jsapi_ticket($redis, $access_token)
{
    $ticket = $redis->get('wechat_jsapi_ticket');
    $ticket = json_decode($ticket);
    $expires = $redis->get('wechat_jsapi_expires');
    if (isset($ticket->ticket)) {
        return $ticket->ticket;
    } else {
        $appid = 'wx131b06b8cdbe4111';
        $appsecret = 'd895a6f60e5cd1abaa93f513d57d34bc';
        $url = 'https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token=' . $access_token . '&type=jsapi';
        $data = file_get_contents($url);
        $json = json_decode($data);
        if ($json->errcode) {
            $redis->set('wechat_access_token', '');
            $access_token = get_access_token($redis);
            $url = 'https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token=' . $access_token . '&type=jsapi';
            $data = file_get_contents($url);
        }
        $redis->set('wechat_jsapi_ticket', $data, 3600);
        $json = json_decode($data);
        return $json->ticket;
    }
}
    function checkUser()
    {
        /**
		 * QQ互联登录,授权成功后会回调此地址
		 * 必须要用授权的request token换取access token
		 * 访问QQ互联的任何资源都需要access token
		 * 目前access token是长期有效的,除非用户解除与第三方绑定
		 * 如果第三方发现access token失效,请引导用户重新登录QQ互联,授权,获取access token
		 */
        //授权成功后,会返回用户的openid
        //检查返回的openid是否是合法id
        if (!is_valid_openid($_REQUEST["openid"], $_REQUEST["timestamp"], $_REQUEST["oauth_signature"])) {
            return false;
        }
        //tips
        //这里已经获取到了openid,可以处理第三方账户与openid的绑定逻辑
        //但是我们建议第三方等到获取accesstoken之后在做绑定逻辑
        //用授权的request token换取access token
        $access_str = get_access_token(QZONE_KEY, QZONE_SECRET, $_REQUEST["oauth_token"], $_SESSION['qzone']["keys"]["oauth_token_secret"], $_REQUEST["oauth_vericode"]);
        //echo "access_str:$access_str\n";
        $result = array();
        parse_str($access_str, $result);
        //error
        if (isset($result["error_code"])) {
            return false;
        }
        //获取access token成功后也会返回用户的openid
        //我们强烈建议第三方使用此openid
        //检查返回的openid是否是合法id
        if (!is_valid_openid($result["openid"], $result["timestamp"], $result["oauth_signature"])) {
            return false;
        }
        //将access token,openid保存!!
        //XXX 作为demo,临时存放在session中,网站应该用自己安全的存储系统来存储这些信息
        $_SESSION['qzone']['access_token']['oauth_token'] = $result["oauth_token"];
        $_SESSION['qzone']['access_token']['oauth_token_secret'] = $result["oauth_token_secret"];
Example #29
0
<?php

/*
 * 74cms WAP
 * ============================================================================
 * 版权所有: 骑士网络,并保留所有权利。
 * 网站地址: http://www.74cms.com;
 * ----------------------------------------------------------------------------
 * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和
 * 使用;不允许对程序代码以任何形式任何目的的再发布。
 * ============================================================================
*/
define('IN_QISHI', true);
define('REQUEST_MOBILE', true);
require_once QISHI_ROOT_PATH . 'include/jssdk.php';
$jssdk = new JSSDK($_CFG['weixin_appid'], $_CFG['weixin_appsecret'], get_access_token());
$signPackage = $jssdk->GetSignPackage();
$smarty->assign("signPackage", $signPackage);
 function send_menu()
 {
     $data = $this->get_data();
     foreach ($data as $k => $d) {
         if ($d['pid'] != 0) {
             continue;
         }
         $tree['button'][$d['id']] = $this->_deal_data($d);
         unset($data[$k]);
     }
     foreach ($data as $k => $d) {
         $tree['button'][$d['pid']]['sub_button'][] = $this->_deal_data($d);
         unset($data[$k]);
     }
     $tree2 = array();
     $tree2['button'] = array();
     foreach ($tree['button'] as $k => $d) {
         $tree2['button'][] = $d;
     }
     $tree = $this->json_encode_cn($tree2);
     //$map ['token'] = get_token ();
     //$info = M ( 'member_public' )->where ( $map )->find ();
     //$url_get = 'https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=' . $info ['appid'] . '&secret=' . $info ['secret'];
     //$ch1 = curl_init ();
     //$timeout = 5;
     //curl_setopt ( $ch1, CURLOPT_URL, $url_get );
     //curl_setopt ( $ch1, CURLOPT_RETURNTRANSFER, 1 );
     //curl_setopt ( $ch1, CURLOPT_CONNECTTIMEOUT, $timeout );
     //curl_setopt ( $ch1, CURLOPT_SSL_VERIFYPEER, FALSE );
     //curl_setopt ( $ch1, CURLOPT_SSL_VERIFYHOST, false );
     //$accesstxt = curl_exec ( $ch1 );
     //curl_close ( $ch1 );
     //$access = json_decode ( $accesstxt, true );
     //if (empty ( $access ['access_token'] )) {
     //	$this->error ( '获取access_token失败,请确认AppId和Secret配置是否正确,然后再重试。' );
     //}
     $access['access_token'] = get_access_token();
     file_get_contents('https://api.weixin.qq.com/cgi-bin/menu/delete?access_token=' . $access['access_token']);
     $url = 'https://api.weixin.qq.com/cgi-bin/menu/create?access_token=' . $access['access_token'];
     $header[] = "content-type: application/x-www-form-urlencoded; charset=UTF-8";
     $ch = curl_init();
     curl_setopt($ch, CURLOPT_URL, $url);
     curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
     curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
     curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
     curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
     curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (compatible; MSIE 5.01; Windows NT 5.0)');
     curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
     curl_setopt($ch, CURLOPT_AUTOREFERER, 1);
     curl_setopt($ch, CURLOPT_POSTFIELDS, $tree);
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
     $res = curl_exec($ch);
     curl_close($ch);
     $res = json_decode($res, true);
     if ($res['errcode'] == 0) {
         $this->success('发送菜单成功');
     } else {
         $this->success('发送菜单失败,错误的返回码是:' . $res['errcode'] . ', 错误的提示是:' . $res['errmsg']);
     }
 }