申请开发应用
可使用公司营业执照或个体工商户申请
微博开发者平台
https://open.weibo.com/
创建应用 提交审核
php对接(这里使用的是thinkphp5.1)
配置文件
<?php
return [
'WB_AKEY' => "XXX",
'WB_SKEY' => "XXXX",
'WB_CALLBACK_URL' => "http://XXXX",
];
api文件
https://github.com/xiaosier/libweibo
调用
//访问微博登录页面
public function wbLogin()
{
require PAY_PATH . '/wb_connect/saetv2.ex.class.php';
$wb = new \SaeTOAuthV2(config('wb.WB_AKEY'), config('wb.WB_SKEY'));
$code_url = $wb->getAuthorizeURL(config('wb.WB_CALLBACK_URL'));
header('location:' . $code_url);
}
//wb回调函数
// TOKEN
// array(5) {
// ["access_token"] => string(32) "XXXX"
// ["remind_in"] => string(9) "XXXX"
// ["expires_in"] => int(XXXX)
// ["uid"] => string(10) "XXXX"
// ["isRealName"] => string(4) "true"
// }
// $user_message
// array(62) {
// ["id"] => int(XXXX)
// ["idstr"] => string(10) "XXXX"
// ["class"] => int(1)
// ["screen_name"] => string(12) "XXXX"
// ["name"] => string(12) "XXXX"
// ["province"] => string(3) "100"
// ["city"] => string(4) "1000"
// ["location"] => string(6) "其他"
// ["description"] => string(0) ""
// ["url"] => string(0) ""
// ["profile_image_url"] => string(116) "XXXX"
// ["cover_image_phone"] => string(79) "XXXX"
// ["profile_url"] => string(12) "XXXX"
// ["domain"] => string(0) ""
// ["weihao"] => string(0) ""
// ["gender"] => string(1) "m"
// ["followers_count"] => int(248)
// ["friends_count"] => int(1409)
// ["pagefriends_count"] => int(4)
// ["statuses_count"] => int(3159)
// ["video_status_count"] => int(0)
// ["favourites_count"] => int(2)
// ["created_at"] => string(30) "Fri Aug 05 17:17:44 +0800 2016"
// ["following"] => bool(false)
// ["allow_all_act_msg"] => bool(false)
// ["geo_enabled"] => bool(true)
// ["verified"] => bool(false)
// ["verified_type"] => int(-1)
// ["remark"] => string(0) ""
// ["insecurity"] => array(1) {
// ["sexual_content"] => bool(false)
// }
// ["status"] => array(45) {
// ["visible"] => array(2) {
// ["type"] => int(0)
// ["list_id"] => int(0)
// }
// ["created_at"] => string(30) "Sun Feb 02 23:28:05 +0800 2020"
// ["id"] => int(4467662828288407)
// ["idstr"] => string(16) "XXXX"
// ["mid"] => string(16) "XXXX"
// ["can_edit"] => bool(false)
// ["show_additional_indication"] => int(0)
// ["text"] => string(12) "转发微博"
// ["source_allowclick"] => int(0)
// ["source_type"] => int(2)
// ["source"] => string(62) "<a href="http://weibo.com/" rel="nofollow">iPhone客户端</a>"
// ["favorited"] => bool(false)
// ["truncated"] => bool(false)
// ["in_reply_to_status_id"] => string(0) ""
// ["in_reply_to_user_id"] => string(0) ""
// ["in_reply_to_screen_name"] => string(0) ""
// ["pic_urls"] => array(0) {
// }
// ["geo"] => NULL
// ["is_paid"] => bool(false)
// ["mblog_vip_type"] => int(0)
// ["annotations"] => array(1) {
// [0] => array(1) {
// ["mapi_request"] => bool(true)
// }
// }
// ["reposts_count"] => int(0)
// ["comments_count"] => int(0)
// ["attitudes_count"] => int(0)
// ["pending_approval_count"] => int(0)
// ["isLongText"] => bool(false)
// ["reward_exhibition_type"] => int(0)
// ["hide_flag"] => int(0)
// ["mlevel"] => int(0)
// ["biz_feature"] => int(0)
// ["hasActionTypeCard"] => int(0)
// ["darwin_tags"] => array(0) {
// }
// ["hot_weibo_tags"] => array(0) {
// }
// ["text_tag_tips"] => array(0) {
// }
// ["mblogtype"] => int(0)
// ["rid"] => string(1) "0"
// ["userType"] => int(0)
// ["more_info_type"] => int(0)
// ["positive_recom_flag"] => int(0)
// ["content_auth"] => int(0)
// ["gif_ids"] => string(0) ""
// ["is_show_bulletin"] => int(2)
// ["comment_manage_info"] => array(2) {
// ["comment_permission_type"] => int(-1)
// ["approval_comment_type"] => int(0)
// }
// ["repost_type"] => int(2)
// ["pic_num"] => int(0)
// }
// ["ptype"] => int(0)
// ["allow_all_comment"] => bool(true)
// ["avatar_large"] => string(117) "XXXX"
// ["avatar_hd"] => string(117) "XXXX"
// ["verified_reason"] => string(0) ""
// ["verified_trade"] => string(0) ""
// ["verified_reason_url"] => string(0) ""
// ["verified_source"] => string(0) ""
// ["verified_source_url"] => string(0) ""
// ["follow_me"] => bool(false)
// ["like"] => bool(false)
// ["like_me"] => bool(false)
// ["online_status"] => int(0)
// ["bi_followers_count"] => int(2)
// ["lang"] => string(5) "zh-cn"
// ["star"] => int(0)
// ["mbtype"] => int(0)
// ["mbrank"] => int(0)
// ["block_word"] => int(0)
// ["block_app"] => int(0)
// ["credit_score"] => int(80)
// ["user_ability"] => int(3146752)
// ["cardid"] => string(9) "star_1073"
// ["avatargj_id"] => string(10) "XXXX"
// ["urank"] => int(4)
// ["story_read_state"] => int(-1)
// ["vclub_member"] => int(0)
// ["is_teenager"] => int(0)
// ["is_guardian"] => int(0)
// ["is_teenager_list"] => int(0)
// ["special_follow"] => bool(false)
// }
public function wbCallback()
{
if (isset($_REQUEST['code'])) {
$keys = array();
$keys['code'] = $_REQUEST['code'];
$keys['redirect_uri'] = config('wb.WB_CALLBACK_URL');
require PAY_PATH . '/wb_connect/saetv2.ex.class.php';
$wb = new \SaeTOAuthV2(config('wb.WB_AKEY'), config('wb.WB_SKEY'));
$token = $wb->getAccessToken('code', $keys);
$c = new \SaeTClientV2(config('wb.WB_AKEY'), config('wb.WB_SKEY'), $token['access_token']);
$uid_get = $c->get_uid();
$uid = $uid_get['uid'];
$user_message = $c->show_user_by_id($uid);
dump($user_message);
}
}