微信第三方平台开发(获取授权链接)

<?php
$type = $_REQUEST['type'];	//1:网页授权   2:移动端链接授权
$auth_type = $_REQUEST['auth_type'];	//1:公账号授权   2:小程序授权
$appId = '';		//appid
$component_access_token_name = Server::getProject() . '_' . 'component_access_token';
$component_access_token = Redis::get($component_access_token_name);
$url = "https://api.weixin.qq.com/cgi-bin/component/api_create_preauthcode?component_access_token=$component_access_token";
$param['component_appid'] = $appId;
$json_param = json_encode($param);
$rest = HttpRequest::http_post($url, $json_param);
$rest = json_decode($rest,true);
$pre_auth_code = $rest['pre_auth_code'];
if (isset($pre_auth_code)){
    if($auth_type == 1){
        $redirect_uri = "";	//授权成功的回调地址(跳转到此页面)
    }elseif($auth_type == 2){
        $redirect_uri = "";
    }
    if($type == 1){//授权注册页面扫码授权
        $re_url = "https://mp.weixin.qq.com/cgi-bin/componentloginpage?component_appid=$appId&pre_auth_code=$pre_auth_code&redirect_uri=$redirect_uri&auth_type=$auth_type";
    }elseif ($type == 2){//点击移动端链接快速授权
        $re_url = "https://mp.weixin.qq.com/safe/bindcomponent?action=bindcomponent&auth_type=3&no_scan=1&component_appid=$appId&pre_auth_code=$pre_auth_code&redirect_uri=$redirect_uri&auth_type=$auth_type#wechat_redirect";
    }
    $data['url'] = $re_url;
    $data['expires_in'] = $rest['expires_in'];
    HttpResponse::exitJSON(0, "获取授权地址成功~!",$data);
}else{
    HttpResponse::exitJSON(1, "获取预授权码失败~!");
}
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值