/** * 活动详情 * @param int $id * autor:xjw129xjt */ public function detail($id = 0) { $check_isSign = D('event_attend')->where(array('uid' => is_login(), 'event_id' => $id))->select(); $this->assign('check_isSign', $check_isSign); $event_content = D('Event')->where(array('status' => 1, 'id' => $id))->find(); if (!$event_content) { $this->error('404 not found'); } D('Event')->where(array('id' => $id))->setInc('view_count'); $event_content['user'] = query_user(array('id', 'username', 'nickname', 'space_url', 'space_link', 'avatar64', 'rank_html', 'signature'), $event_content['uid']); $event_content['type'] = $this->getType($event_content['type_id']); $menber = D('event_attend')->where(array('event_id' => $id, 'status' => 1))->select(); foreach ($menber as $k => $v) { $event_content['member'][$k] = query_user(array('id', 'username', 'nickname', 'space_url', 'space_link', 'avatar64', 'rank_html', 'signature'), $v['uid']); } $params['mp_id'] = $map['mp_id'] = get_mpid(); $this->assign('mp_id', $params['mp_id']); $uid = get_ucuser_uid(); //获取粉丝用户uid,一个神奇的函数,没初始化过就初始化一个粉丝 if ($uid === false) { $this->error('只可在微信中访问'); } $user = get_uid_ucuser($uid); //获取公众号粉丝用户信息 $url = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; $surl = get_shareurl(); if (!empty($surl)) { $this->assign('share_url', $surl); } $appinfo = get_mpid_appinfo($params['mp_id']); //获取公众号信息 $this->assign('appinfo', $appinfo); $options['appid'] = $appinfo['appid']; //初始化options信息 $options['appsecret'] = $appinfo['secret']; $options['encodingaeskey'] = $appinfo['encodingaeskey']; $weObj = new TPWechat($options); $auth = $weObj->checkAuth(); $js_ticket = $weObj->getJsTicket(); if (!$js_ticket) { } $js_sign = $weObj->getJsSign($url); $this->assign('js_sign', $js_sign); $this->assign('user', $user); $this->assign('content', $event_content); $this->setTitle('{$content.title|op_t}' . '——活动'); $this->setKeywords('{$content.title|op_t}' . ',活动'); $this->getRecommend(); $this->display(); }
/** * 实现的init_ucuser钩子方法,对公众号粉丝进行初始化,在需要初始化粉丝信息的地方通过 hook('init_ucuser',$params); 调用 * @params string $mp_id 公众号在系统中的唯一标识,member_public表的id,必填 * @params string $weObj 公众号实例 * @return void hook函数木有返回值 * 注意: */ public function init_ucuser($params) { if ($params['mp_id'] && $params['weObj'] instanceof TPWechat) { //带有公众号在系统中唯一ID,存在公众号实例,例如weixincontroller中的被动响应 $map['openid'] = get_openid(); $map['mp_id'] = $params['mp_id']; $ucuser = D('Ucuser'); $data = $ucuser->where($map)->find(); if (!$data) { //公众号没有这个粉丝信息,就注册一个 //先在Member表注册会员,使系统中uid统一,公众号粉丝在绑定手机后可登录网站 $aUsername = $aNickname = $map['openid']; //substr(,20); //以openid作为默认UcenterMember用户名和Member昵称 $aPassword = UCenterMember()->create_rand(); //随机密码,用户未通过公众号注册,就不可登录网站 $email = $aUsername . '@mp_id' . $map['mp_id'] . '.com'; //以openid@mpid123.com作为默认邮箱 $mobile = arr2str(UCenterMember()->rand_mobile()); //生成随机手机号已通过model校验,不实际使用,准确手机以微信绑定的为准 $aUnType = 5; //微信公众号粉丝注册 $aRole = 3; //默认公众号粉丝用户角色 /* 注册用户 */ $uid = UCenterMember()->register($aUsername, $aNickname, $aPassword, $email, $mobile, $aUnType); if (0 < $uid) { //注册成功 initRoleUser($aRole, $uid); //初始化角色用户 set_user_status($uid, 1); //微信注册的用户状态直接设置为1 } else { //注册失败,显示错误信息 } $uid = $ucuser->registerUser($uid, $map['mp_id'], $map['openid']); //用注册member获取的统一uid注册微信粉丝 get_ucuser_uid($uid); //设置session中uid } else { get_ucuser_uid($data['uid']); //设置session中uid } } else { //不存在公众号实例或没显式传mp_id参数,例如分享到朋友圈的内容,访问参数中必须带有公众号在系统中唯一标识mp_id $umap['openid'] = get_openid(); //只存在公众号信息的,在get_openid中通过oauth获取用户openid $umap['mp_id'] = I('mp_id'); //从controller的访问请求中获取mp_id if (!empty($umap['mp_id'])) { $ucuser = D('Ucuser'); $data = $ucuser->where($umap)->find(); if (!$data) { //公众号没有这个粉丝信息,就注册一个 //先在Member表注册会员,使系统中uid统一,公众号粉丝在绑定手机后可登录网站 $aUsername = $aNickname = $umap['openid']; //以openid作为默认UcenterMember用户名和Member昵称 $aPassword = UCenterMember()->create_rand(); //随机密码,用户未通过公众号注册,就不可登录网站 $email = $aUsername . '@mp_id' . $umap['mp_id'] . 'com'; //以openid@mpid123.com作为默认邮箱 $mobile = arr2str(UCenterMember()->rand_mobile()); //生成随机手机号已通过model校验,不实际使用,准确手机以微信绑定的为准 $aUnType = 5; //微信公众号粉丝注册 $aRole = 3; //默认公众号粉丝用户角色 /* 注册用户 */ $uid = UCenterMember()->register($aUsername, $aNickname, $aPassword, $email, $mobile, $aUnType); if (0 < $uid) { //注册成功 initRoleUser($aRole, $uid); //初始化角色用户 set_user_status($uid, 1); //微信注册的用户状态直接设置为1 } else { //注册失败,显示错误信息 } $uid = $ucuser->registerUser($uid, $umap['mp_id'], $umap['openid']); //用注册member获取的统一uid注册微信粉丝 get_ucuser_uid($uid); //设置session中uid } else { get_ucuser_uid($data['uid']); //设置session中uid } } else { //没有公众号信息,未能初始化粉丝 } } }
public function forget() { $params['mp_id'] = $map['mp_id'] = get_mpid(); $this->assign('mp_id', $params['mp_id']); $map['id'] = I('id'); $uid = get_ucuser_uid(); //获取粉丝用户uid,一个神奇的函数,没初始化过就初始化一个粉丝 if ($uid === false) { $this->error('只可在微信中访问'); } if (IS_POST) { $aMobile = I('post.mobile', '', 'op_t'); $verify = I('post.verify', '', 'op_t'); $password = I('post.password', '', 'op_t'); $repassword = I('post.repassword', '', 'op_t'); //确认两次输入的密码正确 if ($password != $repassword) { $this->error('两次输入的密码不一致'); } //读取SESSION中的验证信息 $mobile = session('reset_password_mobile'); //提交修改密码和接收验证码的手机号码不一致 if ($aMobile != $mobile) { $this->error('提交修改密码和接收验证码的手机号码不一致'); } $res = D('Verify')->checkVerify($aMobile, "mobile", $verify, 0); //确认验证信息正确 if (!$res) { echo '验证码错误'; return false; } else { echo true; } //将新的密码写入数据库 $data1 = array('uid' => $uid, 'mobile' => $aMobile, 'password' => $password); $model = D('Common/Ucuser'); $data1 = $model->create($data1); if (!$data1) { $this->error('密码格式不正确'); } $result = $model->where(array('uid' => $uid))->save($data1); if ($result === false) { $this->error('数据库写入错误'); } //将新的密码写入数据库 $data = array('id' => $uid, 'mobile' => $aMobile, 'password' => $password); $model = UCenterMember(); $data = $model->create($data); if (!$data) { $this->error('密码格式不正确'); } $result = $model->where(array('id' => $uid))->save($data); if ($result === false) { $this->error('数据库写入错误'); } //显示成功消息 $this->success('密码重置成功', addons_url('Ucuser://Ucuser/login')); } $this->display(); }
/** * * jsApi微信支付示例 * 注意: * 1、微信支付授权目录配置如下 http://test.uctoo.com/addon/Wxpay/Index/jsApiPay/mp_id/ * 2、支付页面地址需带mp_id参数 * 3、管理后台-基础设置-公众号管理,微信支付必须配置的参数都需填写正确 * @param array $mp_id 公众号在系统中的ID * @return 将微信支付需要的参数写入支付页面,显示支付页面 */ public function jsApiPay($mp_id = 0) { empty($mp_id) && ($mp_id = get_mpid()); $params['mp_id'] = $mp_id; //系统中公众号ID $this->assign('mp_id', $params['mp_id']); $uid = get_ucuser_uid(); //获取粉丝用户uid,一个神奇的函数,没初始化过就初始化一个粉丝 if ($uid === false) { $this->error('只可在微信中访问'); } $user = get_uid_ucuser($uid); //获取本地存储公众号粉丝用户信息 $this->assign('user', $user); $url = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; $surl = get_shareurl(); if (!empty($surl)) { $this->assign('share_url', $surl); } //odata通用订单数据,订单数据可以从订单页面提交过来 $odata['uid'] = $uid; $odata['mp_id'] = $params['mp_id']; // 当前公众号在系统中ID $odata['order_id'] = "time" . date("YmdHis"); // $odata['order_status'] = 1; //不带该字段-全部状态, 2-待发货, 3-已发货, 5-已完成, 8-维权中 $odata['order_total_price'] = 1; //订单总价,单位:分 $odata['buyer_openid'] = $user['openid']; $odata['buyer_nick'] = $user['nickname']; $odata['receiver_mobile'] = $user['mobile']; $odata['product_id'] = 1; $odata['product_name'] = "UCToo"; $odata['product_price'] = 100; //商品价格,单位:分 $odata['product_sku'] = "UCToo_Wxpay"; $odata['product_count'] = 1; $odata['module'] = MODULE_NAME; $odata['model'] = "order"; $odata['aim_id'] = 1; $order = D("Order"); // 实例化order对象 $order->create($odata); // 生成数据对象 $result = $order->add(); // 写入数据 if ($result) { // 如果主键是自动增长型 成功后返回值就是最新插入的值 } //获取公众号信息,jsApiPay初始化参数 $info = get_mpid_appinfo($odata['mp_id']); $this->options['appid'] = $info['appid']; $this->options['mchid'] = $info['mchid']; $this->options['mchkey'] = $info['mchkey']; $this->options['secret'] = $info['secret']; $this->options['notify_url'] = $info['notify_url']; $this->wxpaycfg = new WxPayConfig($this->options); //①、初始化JsApiPay $tools = new JsApiPay($this->wxpaycfg); $wxpayapi = new WxPayApi($this->wxpaycfg); //②、统一下单 $input = new WxPayUnifiedOrder($this->wxpaycfg); //这里带参数初始化了WxPayDataBase // $input->SetAppid($info['appid']);//公众账号ID // $input->SetMch_id($info['mchid']);//商户号 $input->SetBody($odata['product_name']); $input->SetAttach($odata['product_sku']); $input->SetOut_trade_no($odata['order_id']); $input->SetTotal_fee($odata['order_total_price']); $input->SetTime_start(date("YmdHis")); $input->SetTime_expire(date("YmdHis", time() + 600)); // $input->SetGoods_tag("WXG"); //商品标记,代金券或立减优惠功能的参数 // $input->SetNotify_url($info['notify_url']); //http://test.uctoo.com/index.php/UShop/Index/notify $input->SetTrade_type("JSAPI"); $input->SetOpenid($user['openid']); $order = $wxpayapi->unifiedOrder($input); $jsApiParameters = $tools->GetJsApiParameters($order); //获取共享收货地址js函数参数 $editAddress = $tools->GetEditAddressParameters(); //③、在支持成功回调通知中处理成功之后的事宜,见 notify.php /** * 注意: * 1、当你的回调地址不可访问的时候,回调通知会失败,可以通过查询订单来确认支付是否成功 * 2、jsapi支付时需要填入用户openid,WxPay.JsApiPay.php中有获取openid流程 (文档可以参考微信公众平台“网页授权接口”, * 参考http://mp.weixin.qq.com/wiki/17/c0f37d5704f0b64713d5d2c37b468d75.html) */ $this->assign('order', $odata); $this->assign('jsApiParameters', $jsApiParameters); $this->assign('editAddress', $editAddress); $this->display(); }