本文整理汇总了PHP中get_access_token函数的典型用法代码示例。如果您正苦于以下问题:PHP get_access_token函数的具体用法?PHP get_access_token怎么用?PHP get_access_token使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_access_token函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: get_base_information
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;
}
示例2: InitConfig
/**
* 组装配置信息
* @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 . "×tamp=" . $timestamp . "&url=" . $url . "";
$signature = sha1($and);
$arr['appId'] = $appid;
$arr['timestamp'] = $timestamp;
$arr['nonceStr'] = $nonceStr;
$arr['signature'] = $signature;
echo json_encode($arr);
//输出json数据
}
示例3: get_video_upload_info
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);
}
示例4: _thumb_media_id
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'];
}
示例5: checkUser
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
示例6: replyCode
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();
}
示例7: move_group
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;
}
示例8: getAndUploadWxImage
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);
}
示例9: __CONSTRUCT
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 ();
//}
}
示例10: run
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;
}
}
示例11: get_acc_tokens
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";
}
}
示例12: getaccess_token
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();
}
示例13: sendtempmsg
public function sendtempmsg($openid, $template_id, $url, $data, $topcolor = '#FF0000')
{
$xml = '{"touser":"' . $openid . '","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;
}
示例14: test
function test()
{
$param['touser'] = "o3ZYauOnS_g-qQ9bYISisG2MLfvE";
$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);
}
示例15: db_get_token_ticket
/**
* 依赖于数据库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);
}