在一家ecstore二开公司有一段时间了,公司希望往自己研发产品上面走,一直在培养新人。
最近要自己去微信登录,自己就在ectore的框架基础上,写的原生微信第三方登录以此来熟悉微信第三方登录,在ecstore上面去写。
一个简单的demo,不是很好,分享给大家,希望能给想做微信第三方登录的朋友带来思路...
首先:
资料准备:水印图片 28*28 png格式 公司logo高清图片 108*108 png格式 公司logo1.在微信开放平台 https://open.weixin.qq.com/中填写基本信息,2.完成邮箱验证,3.并完善开发者资料,注册成为开发者。4.在“账号中心”完成开发者资质认证。5.进入微信开放平台管理中心网站应用,点击“创建应用”按钮。6.填写基本信息,完成点击下一步7.填写平台信息 应用签名:可在微信开发平台的资源中心》》资源下载》》中下载“签名生成工具”,用户获取已经安装到手机的第三方应用的签名。输入应用包名,即可获得该应用的签名值。8.提交审核后,在7个工作日内腾讯将给出审核结果。(通常较快,几个小时就可反馈结果)
获取AppID,AppSecret,之后的处理:
需要在你想加的网站登录页给一个链接:<a href="https://open.weixin.qq.com/connect/qrconnect?appid=your appid &redirect_uri=http://www.sunmil.cn/passport-linshi.html&response_type=code&scope=snsapi_login&state=STATE#wechat_redirect" rel="external nofollow" >微信登录</a><br><br>
处理微信登录开始
定义appid appsecert
private $appid = "your appid";private $appsecert = "your appsecert";private $redirect_uri = http://www.sunmil.cn/wxGetCode;
绑定账号页面
public function weixin(){ //链接数据库 $link = mysqli_connect(DB_HOST, DB_USER,DB_PASSWORD,DB_NAME ) or die('数据库连接失败4'); $link = mysqli_connect('127.0.0.1', 'root','root', 'ec') or die('数据库连接失败'); mysqli_set_charset($link,'utf8'); //接收openid $openid = $_COOKIE['openid']; $sql = "select * from sdb_trustlogin_trustinfo where openid = '$openid' "; $res = mysqli_query($link, $sql); $row = mysqli_fetch_assoc($res); $this->pagedata['realname'] = $row['realname']; $this->pagedata['avatar'] = $row['avatar']; $this->page("site/passport/weixin.html"); }
当第一次微信登录,处理绑定账号页面
public function handle($url=null){ // $url = "http://www.sunmil.cn"; //链接数据库 $link = mysqli_connect(DB_HOST, DB_USER,DB_PASSWORD,DB_NAME ) or die('数据库连接失败3'); mysqli_set_charset($link,'utf8'); $post = utils::_filter_input($_POST); $userData = array( 'login_account' => $post['uname'], 'login_password' => $post['password'] ); $member_id = kernel::single('pam_passport_site_basic')->login($userData,$post['verifycode'],$msg); $b2c_members_model = $this->app->model('members'); $member_point_model = $this->app->model('member_point'); $member_data = $b2c_members_model->getList( 'member_lv_id,experience,point', array('member_id'=>$member_id) ); $member_data = $member_data[0]; $member_data['order_num'] = $this->app->model('orders')->count( array('member_id'=>$member_id) ); $b2c_members_model->update($member_data,array('member_id'=>$member_id)); $this->userObject->set_member_session($member_id); $this->bind_member($member_id); $this->set_cookie('loginName',$post['uname'],time()+31536000);//用于记住密码 // setCartNum()需要传入一个参数 $aCart = array(); $this->app->model('cart_objects')->setCartNum($aCart); $url = $this->userPassport->get_next_page('pc'); if( !$url ){ $url = kernel::single('b2c_frontpage')->gen_url(array('app'=>'b2c','ctl'=>'site_member','act'=>'index')); } //查询数据库 $uname = $_POST['uname']; $sql = "select * from sdb_pam_members where password_account = '$uname' "; $res = mysqli_query($link, $sql); $row = mysqli_fetch_assoc($res); $member_id = $row['member_id']; //链接数据库,插入数据 $openid = $_COOKIE['openid']; $sql = "update sdb_trustlogin_trustinfo set member_id = ('{$member_id}') where openid = '{$openid}'"; $res = mysqli_query($link, $sql); if($res && mysqli_affected_rows($link) > 0){ //删除cookie setcookie("openid", $openid, time()-3600); kernel::single('pam_lock')->flush_lock($member_id); $this->splash('success',$url,app::get('b2c')->_('登录成功'),true); }else{ echo '失败了'; } }
新闻热点
疑难解答