<?php
/* 键绑定程序 */
//制作:爱微
//演示:aiwei1818.com
//日期:2014.7.14
$errbiao = array(
"-1" => "系统错误",
"-2" => "帐号或密码错误",
"-3" => "密码错误",
"-4" => "不存在该帐户",
"-5" => "访问受限",
"-6" => "需要输入验证码",
"-7" => "此帐号已绑定私人微信号,不可用于公众平台登录",
"-8" => "邮箱已存在",
"-32" => "验证码输入错误",
"-200" => "因频繁提交虚假资料,该帐号被拒绝登录",
"-94" => "请使用邮箱登陆",
"10" => "该公众会议号已经过期,无法再登录使用"
);
$uid = Request::get(1);
if (!uid) {
die();
}
$u = new Model('user');
$u->find($uid);
$p = new Model('pubs');
if ($u->id == Session::get('mainuid') || Session::get('mainuid') == $u->pid) {
$p->find(array(
'uid' => $uid
));
} else {
die();
}
//删除
if ('del' == Request::get(2)) {
if ($u->id == Session::get('mainuid')) {
//自己
$p->isval = '0';
$p->save();
Response::write('ok');
} else {
$u->pid = 0;
$u->save();
Response::write('ok');
}
}
$badun = '';
if ($p->try_post()) {
if (!empty($p->wun) && !empty($p->wpwd)) {
$t['username'] = urlencode($p->wun);
$t['pwd'] = md5($p->wpwd);
$t['p'] = 'json';
$link = "https://mp.weixin.qq.com/cgi-bin/login?lang=zh_CN";
$post = "username={$t['username']}&pwd={$t['pwd']}&imgcode=&f={$t['p']}";
$refer = "https://mp.weixin.qq.com/cgi-bin/loginpage?t=wxm2-login&lang=zh_CN";
$ch = curl_init();
$cookie_file = tempnam('./temp', 'mpweixin');
curl_setopt($ch, CURLOPT_URL, $link);
curl_setopt($ch, CURLOPT_REFERER, $refer);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.2; WOW64; rv:30.0) Gecko/20100101 Firefox/30.0');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file);
curl_setopt($ch, CURLOPT_SSLVERSION, 3);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$sres = trim(curl_exec($ch));
if ($sres == '') {
tusi('平台连接失败');
} else {
$reds = json_decode(trim($sres));
$td = $reds->base_resp;
if ($td->ret == - 8) {
} elseif ($td->ret == - 23) {
tusi('平台信息错误:帐号或密码错误');
} elseif ($td->ret == - 27) {
tusi('平台信息错误:验证码错误');
} else {
$token = $reds->redirect_url;
$token = explode('&token=', $token);
$token = $token[1];
$ch = curl_init("https://mp.weixin.qq.com/advanced/advanced?action=interface&t=advanced/interface&token={$token}&lang=zh_CN");
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file);
$contents = curl_exec($ch);
curl_close($ch);
$mID = explode("operation_seq", $contents);
$operation_seq = substr($mID[1], 3, 9);
$link = "https://mp.weixin.qq.com/advanced/callbackprofile?t=ajax-response&token={$token}&lang=zh_CN";
$tp = Conf::$http_path;
$wid = Session::get('wid');
$cb = md5(Session::get('wid') . Conf::$management_center_target);
$post = "url={$tp}mpapi.html?appid={$wid}&callback_token={$cb}&operation_seq=" . $operation_seq;
$refer = "https://mp.weixin.qq.com/advanced/advanced?action=interface&t=advanced/interface&token={$token}&lang=zh_CN";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $link);
curl_setopt($ch, CURLOPT_REFERER, $refer);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file);
curl_setopt($ch, CURLOPT_SSLVERSION, 3);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$sres = trim(curl_exec($ch));
sleep(1);
tusi('平台账户信息绑定成功');
Response::exejs("alert('关注你的公众帐号,回复“你好”检测是否升级成功');");
$p->isval = '1';
Redirect::delay_to('/admin/userCenter/pubs.html', 2);
}
}
}
$p->uid = Session::get('uid');
$p->save();
Session::set('wid', $p->id);
}
评论7
最新资源