在好例子网,分享、交流、成长!
您当前所在位置:首页PHP 开发实例PHP语言基础 → thinkphp 实现微信红包 源码下载(含数据库)

thinkphp 实现微信红包 源码下载(含数据库)

PHP语言基础

下载此实例
  • 开发语言:PHP
  • 实例大小:6.37M
  • 下载次数:121
  • 浏览次数:1606
  • 发布时间:2016-01-08
  • 实例类别:PHP语言基础
  • 发 布 人:crazycode
  • 文件格式:.zip
  • 所需积分:2
 相关标签: 微信 php 红包 thinkPHP

实例介绍

【实例简介】
【实例截图】

【核心代码】

<?php
namespace Home\Controller;

class IndexController extends BaseController {

    private $app_id = 'wxc43356a7940e32d4';

    private $app_secret = 'ec234926610a429dfaca36328af9b014';

    public function sendAction() {
        $userID = I('get.uid');
        $actionto = I('get.ac');
        $userobj = M('user');
        $userinfo = $userobj->field('user_id, user_name, user_regdate, user_image')->where('user_id = "'.$userID.'"')->find();
        if ($userinfo) {
            session('userinfo', $userinfo);
        } else {
            session('userinfo', array('user_id' => $userID, 'user_name'=>'访客'));
        }
        $this->redirect('index/'.$actionto);
    }
    
    public function gotoOauthAction() {
        $parent = I('get.parentid');
        $redirect_url = urlencode('http://'.$_SERVER['SERVER_NAME'].'/index.php/index/index?parentid='.$parent.'&from=singlemessage&isappinstalled=0');
        $gotourl = 'https://open.weixin.qq.com/connect/oauth2/authorize?appid='.$this->app_id.'&redirect_uri='.$redirect_url.'&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect';
        redirect($gotourl);
    }

    public function indexAction() {
      /*  $refresh_token = session('refresh_token');*/
        $parent = I('get.parentid');
       /* $code = I('get.code');
        if (!$refresh_token) {
            if (!$code) {
                $this->redirect('gotoOauth', array('parentid' => $parent));
            }
            $url = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=".$this->app_id."&secret=".$this->app_secret."&code=".$code."&grant_type=authorization_code";
            $json_content = file_get_contents($url);
            $json_obj = json_decode($json_content, true);
            $access_token = $json_obj['access_token'];
            $openid = $json_obj['openid'];
            session(array('name'=>'access_token_id', 'expire'=>$json_obj['expires_in']));
            session('refresh_token', $json_obj['refresh_token']);
        }
        else {
            $url ="https://api.weixin.qq.com/sns/oauth2/refresh_token?appid=".$this->app_id."&grant_type=refresh_token&refresh_token=".$refresh_token;
            $json_content = file_get_contents($url);
            $json_obj = json_decode($json_content, true);
            $access_token = $json_obj['access_token'];
            $openid = $json_obj['openid'];
        }*/

       /* $userinfostr = file_get_contents("http://weishangcheng.webs.dlwebs.com/oauth.php?redirect_type=getinfo&return_url=http://weishangcheng.webs.dlwebs.com/oauthtest.php");
        echo $userinfostr;
        exit;*/
        $userinfostr=I('post.userinfo');
        /*echo urldecode($userinfostr);
        exit;*/
        $userinfo = json_decode(urldecode($userinfostr), true);


        $money = M('money');
        $setting = M("setting");
        $user = M('user');
        $setinfo = $setting->where('set_id = 1')->find();
        $my_money_list = array();
        $totel_money = 0;
        if ($userinfo) {
            $wxuser = $user->where('user_id = "'.$userinfo['openid'].'"')->find();
            if (!$wxuser) {
                $data = array('user_id'=>$userinfo['openid'], 'user_name'=>$userinfo['nickname'], 'user_regdate'=>date('Y-m-d H:i:s'), 'user_image'=>$userinfo['headimgurl'], 'user_status'=>'1', 'user_money'=>0);
                $user_result = $user->add($data);
            }
            //设置自己的初始资金
            $own_money = $money->where('money_owner = "'.$userinfo['openid'].'" and money_from = "0"')->find();
            if ($own_money) {
                $this->assign('is_get_money', 1);
            } else {
                $data = array('money_owner'=>$userinfo['openid'], 'money_number'=>$setinfo['set_beginmoney'], 'money_from'=>'0', 'money_time'=>date('Y-m-d H:i:s'));
                $own_money_result = $money->add($data);
                if ($own_money_result) {
                    $user->where('user_id = "'.$userinfo['openid'].'"')->setInc('user_money', $setinfo['set_beginmoney']);
                }
                $this->assign('is_get_money', 0);
            }
            //得到我从别人那里分享来的资金
            $my_get_money = $money->where('money_owner = "'.$userinfo['openid'].'" and money_from != "0"')->select();
            foreach ($my_get_money as $my_money) {
                $usermoneyinfo = $user->where('user_id = "'.$my_money['money_from'].'"')->find();
                $my_money = array_merge($my_money, $usermoneyinfo);
                $my_money_list[] = $my_money;
            }
            //得到我的总金额
            $wxuser = $user->where('user_id = "'.$userinfo['openid'].'"')->find();
            $totel_money = $wxuser['user_money'];
        }
        //给分享给我的人加钱
        if ($parent && $parent != $userinfo['openid']) {
            $wxmoney = $money->where('money_owner = "'.$parent.'" and money_from = "'.$userinfo['openid'].'"')->find();
            if (!$wxmoney) {
//                $share_money = rand(1, $setinfo['set_sharemoney']);
                $share_money = 0.1;
                $data = array('money_owner'=>$parent, 'money_number'=>$share_money, 'money_from'=>$userinfo['openid'], 'money_time'=>date('Y-m-d H:i:s'));
                $money_result = $money->add($data);
                if ($money_result) {
                    $user->where('user_id = "'.$parent.'"')->setInc('user_money', $share_money);
                }
            }
        }
        $this->assign('my_money_list', $my_money_list);
        $this->assign('userinfo', $userinfo);
        $this->assign('setinfo', $setinfo);
        $this->assign('totel_money', $totel_money);
        
        $this->assign('parentid', $parent);
        $this->assign('code', $code);
        $this->display();
    }

    public function eventAction() {
        $fromUserName = I('post.fromUserName');
        $nickname = I('post.nickname');
        $headimgurl = I('post.headimgurl');
        $eventType = I('post.eventType');
        $user = M('user');
        if ($eventType == 'subscribe') {
            $status = '1';
        } else {
            $status = '0';
        }
        $userinfo = $user->where('user_id = "'.$fromUserName.'"')->find();
        if ($userinfo) {
            $result = $user->where('user_id = "'.$fromUserName.'"')->setField('user_status', $status);
        } else {
            $data = array('user_id'=>$fromUserName, 'user_name'=>$nickname, 'user_regdate'=>date('Y-m-d H:i:s'), 'user_image'=>$headimgurl, 'user_status'=>$status);
            $result = $user->add($data);
        }
        return '关注成功';
    }
    
    public function tixianAction() {
        $openid = I('get.openid');
        $setting = M("setting");
        $setinfo = $setting->where('set_id = 1')->find();
        $untildate = strtotime($setinfo['set_untildate']);
        $now = time();
        if ($now > $untildate) {
            $this->error('啊呀,你来迟了,哈蓝女神被人捋走了,一个不剩(不气馁,下期可累积继续)');
        }
        $user = M('user');
        $wxuser = $user->where('user_id = "'.$openid.'"')->find();
        if ($wxuser['user_money'] < $setinfo['set_getmoney']) {
            $this->error($setinfo['set_getmoney']."都没有,还想泡哈蓝女神?快去赚吧!(第一波2015.1.12~1.19)");
        }
        $this->assign('totel_money', $wxuser['user_money']);
        $this->assign('setinfo', $setinfo);
        $this->assign('openid', $openid);
        $this->display();
    }

    public function savetxAction() {
        $post = filterAllParam('post');

        $setting = M("setting");
        $setinfo = $setting->where('set_id = 1')->find();
        $user = M('user');
        $wxuser = $user->where('user_id = "'.$post['tx_userid'].'"')->find();
        if (!$wxuser) {
            $this->error('未知用户');
        }
        if ($wxuser['user_money'] < $setinfo['set_getmoney']) {
            $this->error("您账户金额小于可提现金额,账户金额大于".$setinfo['set_getmoney'].'时可提现');
        }
        if ($post['tx_number'] > $wxuser['user_money']) {
            $this->error('您输入的金额大于你账户拥有的资金');
        }

        $tixian = M("tixian");
        unset($post['tx_card2']);
        unset($post['totel_money']);
        $post['tx_date'] = date('Y-m-d H:i:s');
        $isok = $tixian->add($post);
        if ($isok) {
            $user->where('user_id = "'.$post['tx_userid'].'"')->setDec('user_money', $post['tx_number']);
            $this->success('提现成功', U('index/index'));
        } else {
            $this->error("提现失败");
        }
    }
}

实例下载地址

thinkphp 实现微信红包 源码下载(含数据库)

不能下载?内容有错? 点击这里报错 + 投诉 + 提问

好例子网口号:伸出你的我的手 — 分享

网友评论

发表评论

(您的评论需要经过审核才能显示)

查看所有0条评论>>

小贴士

感谢您为本站写下的评论,您的评论对其它用户来说具有重要的参考价值,所以请认真填写。

  • 类似“顶”、“沙发”之类没有营养的文字,对勤劳贡献的楼主来说是令人沮丧的反馈信息。
  • 相信您也不想看到一排文字/表情墙,所以请不要反馈意义不大的重复字符,也请尽量不要纯表情的回复。
  • 提问之前请再仔细看一遍楼主的说明,或许是您遗漏了。
  • 请勿到处挖坑绊人、招贴广告。既占空间让人厌烦,又没人会搭理,于人于己都无利。

关于好例子网

本站旨在为广大IT学习爱好者提供一个非营利性互相学习交流分享平台。本站所有资源都可以被免费获取学习研究。本站资源来自网友分享,对搜索内容的合法性不具有预见性、识别性、控制性,仅供学习研究,请务必在下载后24小时内给予删除,不得用于其他任何用途,否则后果自负。基于互联网的特殊性,平台无法对用户传输的作品、信息、内容的权属或合法性、安全性、合规性、真实性、科学性、完整权、有效性等进行实质审查;无论平台是否已进行审查,用户均应自行承担因其传输的作品、信息、内容而可能或已经产生的侵权或权属纠纷等法律责任。本站所有资源不代表本站的观点或立场,基于网友分享,根据中国法律《信息网络传播权保护条例》第二十二与二十三条之规定,若资源存在侵权或相关问题请联系本站客服人员,点此联系我们。关于更多版权及免责申明参见 版权及免责申明

;
报警