public function weixin()
 {
     //file_put_contents('./content.txt', 'sjfsdf');
     $wechatObj = new \Weixin();
     $wechatObj->responseMsg();
     //$wechatObj->valid();
 }
示例#2
0
 public function indexAction()
 {
     echo '<pre>';
     // print_r(Requests::register_autoloader());
     $wx = new Weixin('AddressBook');
     $x = $wx->getToken('wx4091606e5fc6e45c', 'eYNyP1ky4U-1f-91JVv55_f7-JGv-_UzIrxOfVVCqo1cOtCucsg0Uw4P_nJvKdqf');
     print_r($x);
     exit;
 }
示例#3
0
文件: Weixin.php 项目: noikiy/kohana
 public function action_create_qrcode()
 {
     $param = array('expire_seconds' => 600, 'action_name' => 'QR_SCENE', 'action_info' => array('scene' => array('scene_id' => '123')));
     $wx = new Weixin();
     $ret = $wx->create_qrcode($param);
     var_dump($ret);
     //$url = 'https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket='.$ret['ticket'];
     //echo $url;
 }
示例#4
0
文件: Weixin.php 项目: andygoo/kohana
 public function action_down_image()
 {
     $media_id = isset($_GET['media_id']) ? $_GET['media_id'] : '';
     if (!empty($media_id)) {
         $wx = new Weixin();
         $ret = $wx->down_media($media_id);
         echo $ret;
     }
 }
示例#5
0
 public function __call($method, $arguments)
 {
     $instance = \Weixin::instance('message');
     if (method_exists($instance, $method)) {
         call_user_func_array([$instance, $method], $arguments);
     }
 }
示例#6
0
 /**
  * default action 'index'
  *
  * @param Request $request
  * @param Response $response
  */
 public function index(Request $request, Response $response)
 {
     $t = $request->arg(1);
     $wx = new Weixin([], $t);
     if (!isset($_GET['echostr'])) {
         if ($wx->checkSignature()) {
             //签名检测
             $wx->responseMsg();
         } else {
             echo '';
         }
     } else {
         //接口验证
         $wx->valid();
     }
     exit;
 }
示例#7
0
文件: Api.php 项目: houdunwang/hdcms
 public function __construct()
 {
     //加载站点缓存
     service('site')->loadSite();
     //与微信官网通信绑定验证
     \Weixin::valid();
     $this->instance = \Weixin::instance('message');
 }
 public function __construct()
 {
     //判断hash是否存在
     if (empty($_GET["hash"])) {
         echo '#10000非法请求';
         die;
     }
     G('begin');
     $info = S('Accountinfo');
     if (empty($info)) {
         $info = M("Account")->where(array('account_oldid' => $_GET["hash"]))->find();
         $info['Weixin_trace'] = false;
         S('Accountinfo', $info);
     }
     $info['Weixin_trace'] = false;
     //判断hash是否存在
     if (empty($info)) {
         echo '#10001账号不存在';
         die;
     } else {
         $this->Account_info = $info;
     }
     global $_G;
     $_G = $info;
     $token = $info['account_token'];
     import('Weixin.ORG.Weixin');
     $wechatObj = new \Weixin($_GET["echostr"], $token, $GLOBALS["HTTP_RAW_POST_DATA"], $_GET["signature"], $_GET["timestamp"], $_GET["nonce"]);
     $wechatinfo = $wechatObj->responseMsg();
     if (is_array($wechatinfo) && !empty($token)) {
         session('token', $token);
         session('from', $wechatinfo['fromusername']);
         session('openid', $wechatinfo['fromusername']);
         session('to', $wechatinfo['tousername']);
         //过滤器行为
         hook('weixin_begin_filter', &$wechatinfo);
         global $_W;
         $_W = $wechatinfo;
         //预处理行为
         hook('weixin_begin');
     } else {
         echo '这里是微信请求的接口地址,请将本地址填写的微信的TOKEN请求地址';
         die;
     }
 }
示例#9
0
 public function actionIndex()
 {
     $signature = Yii::app()->request->getQuery('signature');
     $timestamp = Yii::app()->request->getQuery('timestamp');
     $nonce = Yii::app()->request->getQuery('nonce');
     $echostr = Yii::app()->request->getQuery('echostr');
     //接口验证时使用
     if (!Weixin::checkSignature($timestamp, $nonce, $signature)) {
         Yii::app()->end();
     } elseif ($echostr) {
         Yii::app()->end($echostr);
     }
     //解析传入的XML
 }
示例#10
0
文件: site.php 项目: houdunwang/hdcms
 public function doSitePushWechat()
 {
     $id = q('get.id');
     $data = $this->db->where('id', $id)->pluck('data');
     $data = json_decode($data, TRUE);
     $data = $this->addHttp($data);
     $res = \Weixin::instance('button')->createButton($data);
     if ($res['errcode'] == 0) {
         $this->db->whereNotIn('id', [$id])->update(['status' => 0]);
         $this->db->where('id', $id)->update(['status' => 1]);
         message('推送微信菜单成功', 'back', 'success');
     }
     message($res['errinfo'], 'back', 'error', 5);
 }
示例#11
0
 public function __construct()
 {
     parent::__construct();
     $jsapi_ticket = $this->redis->get('jsapi_ticket');
     //var_dump($jsapi_ticket);
     if (empty($jsapi_ticket)) {
         $ret_json = $this->get_jsapi_ticket();
         $ret_array = json_decode($ret_json, true);
         if (isset($ret_array['ticket'])) {
             $jsapi_ticket = $ret_array['ticket'];
             $this->redis->setex('jsapi_ticket', $ret_array['expires_in'] - 60, $jsapi_ticket);
         }
     }
     $this->jsapi_ticket = $jsapi_ticket;
 }
示例#12
0
 /**
  * 当用户第一次关注公众号的时候,进行数据库插入操作
  * @param referer  0 为搜索关注,1 为二维码关注
  * @param type  二维码类型,1 为临时二维码,2为永久
  */
 public function weixin_subscribe($openid, $referer = 0, $sell_id = 0)
 {
     $sqlUser = new sql_userMod();
     $res = $sqlUser->get_user_openid($openid);
     if ($res) {
         $sqlUser->set_user_subscribe($res['p_id'], $res['sub_time'] + 1);
     } else {
         $r = connectRedis($this->config['RD_HOST'], $this->config['RD_PORT'], $this->config['RD_DB']);
         $token = $r->get('token');
         $wx_res = Weixin::get_user_info($token, $openid);
         if ($wx_res) {
             $res = $sqlUser->add_user_subscribe($wx_res, $referer, str_replace('sell_id', '', $sell_id));
             dump($res);
         }
     }
 }
示例#13
0
 /**
  * 使用微信openid自动登录
  */
 public function loginByOpenid()
 {
     //认证订阅号或服务号,并且开启自动登录时获取微信帐户openid自动登录
     if ($info = \Weixin::instance('oauth')->snsapiUserinfo()) {
         $user = $this->where('openid', $info['openid'])->first();
         if (!$user) {
             //帐号不存在时使用openid添加帐号
             $data['openid'] = $info['openid'];
             $data['nickname'] = $info['nickname'];
             $data['icon'] = $info['headimgurl'];
             if ($uid = !$this->add($data)) {
                 message($this->getError(), 'back', 'error');
             }
             $user = Db::table('member')->where('uid', $uid)->first();
         }
         Session::set('member', $user);
         return TRUE;
     }
     return FALSE;
 }
示例#14
0
 public function weixinLogin()
 {
     if (IS_WEIXIN && v('site.wechat.level') >= 3) {
         //认证订阅号或服务号,并且开启自动登录时获取微信帐户openid自动登录
         if ($info = \Weixin::instance('oauth')->snsapiUserinfo()) {
             $user = $this->db->where('openid', $info['openid'])->first();
             if (!$user) {
                 //帐号不存在时使用openid添加帐号
                 $this->db['openid'] = $info['openid'];
                 $this->db['nickname'] = $info['nickname'];
                 $this->db['icon'] = $info['headimgurl'];
                 $uid = $this->db->save();
                 $user = $this->db->find($uid);
             }
             //更新access_token
             $user['access_token'] = md5($user['username'] . $user['password'] . c('app.key'));
             $user->save();
             Session::set('member_uid', $user['uid']);
             return TRUE;
         }
     }
 }
示例#15
0
文件: Pay.php 项目: houdunwang/hdcms
 public function weixinNotify()
 {
     $res = Weixin::instance('pay')->getNotifyMessage();
     $pay = Db::table('pay')->where('tid', $res['out_trade_no'])->first();
     $data['status'] = 1;
     $data['type'] = 'wechat';
     Db::table('pay')->where('tid', $res['out_trade_no'])->update($data);
     //记录支付记录
     $log['siteid'] = SITEID;
     $log['uid'] = $pay['uid'];
     Db::table('credits_record')->insert($log);
     $module = Db::table('modules')->where('name', $pay['module'])->first();
     //通知模块
     if ($module['is_system'] == 1) {
         //系统模块
         $class = '\\module\\' . $pay['module'] . '\\pay';
     } else {
         $class = '\\addons\\' . $pay['module'] . '\\pay';
     }
     if (class_exists($class)) {
         $obj = new $class($pay['module']);
         $obj->doWebAsync($res);
     }
 }
示例#16
0
<?php

$weixin = new Weixin('ruchee', 'Ruchee的荒草园子');
$weixin->api();
class Weixin
{
    private $wx;
    public function __construct($token = '', $appname = '')
    {
        $this->wx = new WeixinCallback();
        $this->wx->set_token($token);
        $this->wx->set_appname($appname);
    }
    public function api()
    {
        if (!isset($_GET['echostr'])) {
            $this->wx->responseMsg();
        } else {
            $this->wx->valid();
        }
    }
    public function test($param)
    {
        $this->wx->receiveText($param);
    }
}
class WeixinCallback
{
    private $token = '';
    private $appname = '';
    public function set_token($token)
示例#17
0
<?php

require __DIR__ . '/weixin.php';
$params = array('account' => 'zhangsan', 'password' => '123456', 'url' => 'http://zhangsan.duapp.com', 'token' => 'zhangsan');
$wx = new Weixin($params);
$wx->modify();
var_dump($wx->is_binded());
示例#18
0
 public function testrewardAction()
 {
     $weixin = new \Weixin();
     $data = [0 => 0, 1 => 0, 2 => 0, 3 => 0, 4 => 0];
     for ($i = 0; $i < 10000; $i++) {
         $n = $weixin->getReward('okGRSs8g346G3jBHOsevQFhFuBOI');
         $data[$n] += 1;
     }
     print_r($data);
     die;
 }
示例#19
0
 /**
  * action 'oauth', the OAuth callback
  * 
  * @param Request $request
  * @param Response $response
  */
 public function oauth(Request $request, Response $response)
 {
     //trace_debug('weixin_oauth2_callback_doing', $_GET);
     $code = $request->get('code', '');
     if ('' != $code) {
         //授权通过
         $state = $request->get('state', '');
         $refer = $request->get('refer', '/');
         $from = $request->arg(2);
         if (empty($from)) {
             $from = 'weixin';
         }
         $auth_action = $request->get('act', '');
         $refer = rawurldecode($refer);
         //收获地址base oauth回调
         if ('jsapi_address' == $auth_action) {
             $response->redirect($refer . '&code=' . $code . '&state=' . $state);
         }
         //授权出错
         if (!in_array($state, array('base', 'detail'))) {
             Fn::show_error_message('授权出错,不能访问应用!');
         }
         $wx = new Weixin();
         //用code换取access token
         $code_ret = $wx->request_access_token($code);
         if (!empty($code_ret['errcode'])) {
             Fn::show_error_message('微信授权错误<br/>' . $code_ret['errcode'] . '(' . $code_ret['errmsg'] . ')');
         }
         //获取到openid
         $openid = $code_ret['openid'];
         $uid = 0;
         $auth_method = 'oauth2_' . $state;
         //认证方式
         //查询本地是否存在对应openid的用户
         $uinfo_bd = Member::getTinyInfoByOpenid($openid, $from);
         if (empty($uinfo_bd)) {
             //用户不存在,则要尝试建立
             //保存微信用户信息到本地库
             $udata = ['openid' => $openid, 'auth_method' => $auth_method];
             $uid = Member::createUser($udata, $from);
             $uinfo_bd = ['uid' => $uid];
         } else {
             //用户已存在,对state='base',则仅需设置登录状态;而对state='detail',需保存或更新用户数据
             $uid = intval($uinfo_bd['uid']);
         }
         //detail认证模式,需更新用户数据
         if ('detail' == $state && empty($uinfo_bd['nickname'])) {
             $uinfo_wx = $wx->userInfoByOAuth2($openid, $code_ret['access_token']);
             if (!empty($uinfo_wx['errcode'])) {
                 //失败!则报错
                 Fn::show_error_message('微信获取用户信息出错!<br/>' . $uinfo_wx['errcode'] . '(' . $uinfo_wx['errmsg'] . ')');
             }
             //保存微信用户信息到本地库
             $udata = ['unionid' => isset($uinfo_wx['unionid']) ? $uinfo_wx['unionid'] : '', 'subscribe' => isset($uinfo_wx['subscribe']) ? $uinfo_wx['subscribe'] : 0, 'subscribe_time' => isset($uinfo_wx['subscribe_time']) ? $uinfo_wx['subscribe_time'] : 0, 'nickname' => isset($uinfo_wx['nickname']) ? $uinfo_wx['nickname'] : '', 'logo' => isset($uinfo_wx['headimgurl']) ? $uinfo_wx['headimgurl'] : '', 'sex' => isset($uinfo_wx['sex']) ? $uinfo_wx['sex'] : 0, 'lang' => isset($uinfo_wx['language']) ? $uinfo_wx['language'] : '', 'country' => isset($uinfo_wx['country']) ? $uinfo_wx['country'] : '', 'province' => isset($uinfo_wx['province']) ? $uinfo_wx['province'] : '', 'city' => isset($uinfo_wx['city']) ? $uinfo_wx['city'] : '', 'auth_method' => $auth_method];
             Member::updateUser($udata, $openid, $from);
             //尝试用基本型接口获取用户信息,以便确认用户是否已经关注(基本型接口存在 50000000次/日 调用限制,且仅对关注者有效)
             if (FALSE && !$uinfo_bd['subscribe'] && !$udata['subscribe']) {
                 $uinfo_wx = $wx->userInfo($openid);
                 //trace_debug('weixin_basic_userinfo', $uinfo_wx);
                 if (!empty($uinfo_wx['errcode'])) {
                     //失败!说明很可能没关注,维持现状不处理
                 } else {
                     //成功!说明之前已经关注,得更新关注标记
                     $udata = ['subscribe' => isset($uinfo_wx['subscribe']) ? $uinfo_wx['subscribe'] : 0, 'subscribe_time' => isset($uinfo_wx['subscribe_time']) ? $uinfo_wx['subscribe_time'] : 0];
                     Member::updateUser($udata, $openid, $from);
                 }
             }
         }
         //End: if ('detail'===$state)
         //设置本地登录状态
         if ('login' == $auth_action) {
             if (empty($uid)) {
                 Fn::show_error_message('微信授权登录失败!');
             }
             Member::setLocalLogin($uid);
         }
         //跳转
         $response->redirect($refer);
     } else {
         //授权未通过
         Fn::show_error_message('未授权,不能访问应用!');
     }
 }
示例#20
0
 private function receiveEvent($object)
 {
     $contentStr = '';
     switch ($object->Event) {
         case 'subscribe':
             $weixin = new Weixin();
             $info = $weixin->get_user_info($object->FromUserName);
             $password = rand(100, 999) . rand(100, 999);
             $return = empty($info['nickname']) ? NULL : WeixinData::SetUser($object->FromUserName, $info['nickname'], $password);
             if (isset($return)) {
                 $contentStr = is_array($return) ? '你已经关注且注册过帐号请再扫描二维码登录......帐号是:' . $return[0]['username'] : '******' . $info['nickname'] . '密码:' . $password;
             } else {
                 $contentStr = '不是有效的openid,请在手机端操作!!openid是:' . $object->FromUserName;
             }
             break;
         case 'unsubscribe':
             $contentStr = '取消关注';
             break;
         case 'SCAN':
             $weixin = new Weixin();
             $info = $weixin->get_user_info($object->FromUserName);
             $return = WeixinData::GetUser($object->FromUserName);
             if (!empty($return)) {
                 $login = WeixinData::SetweixinUser($object->FromUserName, $info['nickname'], $object->EventKey);
                 $contentStr = empty($login) ? '由于数据处理错误,登录失败!' : $info['nickname'] . '在AliceBlog的帐号已经登录啦,请等待跳转~登录数字:' . $object->EventKey;
             } else {
                 $contentStr = 'sorry,网站并没有你的帐号,请联系管理员。openid是:' . $object->FromUserName;
             }
             break;
         case 'LOCATION':
             $contentStr = '上传位置:纬度 ' . $object->Latitude . ';经度 ' . $object->Longitude;
             break;
         case 'CLICK':
             switch ($object->EventKey) {
                 case 'company':
                     $contentStr[] = array('Title' => '个人简介', 'Description' => '我的个人微博及个人Blog', 'PicUrl' => 'http://discuz.comli.com/weixin/weather/icon/cartoon.jpg', 'Url' => 'http://520.leunico.sinaapp.com/');
                     break;
                 case '游戏':
                     $contentStr[] = array('Title' => 'OAuth2.0网页授权演示', 'Description' => 'OAuth2.0网页授权演示', 'PicUrl' => 'http://discuz.comli.com/weixin/weather/icon/cartoon.jpg', 'Url' => 'https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxb33bef172a0860cf&redirect_uri=http://520.leunico.sinaapp.com/wechat/oauth.php&response_type=code&scope=snsapi_userinfo&state=1#wechat_redirect');
                     break;
                 default:
                     $contentStr[] = array('Title' => '默认菜单回复', 'Description' => '您正在使用的是Leunico测试帐号的自定义菜单测试接口', 'PicUrl' => 'http://discuz.comli.com/weixin/weather/icon/cartoon.jpg', 'Url' => 'http://520.leunico.sinaapp.com/');
                     break;
             }
             break;
         default:
             $contentStr = '未找到事件';
             break;
     }
     if (is_array($contentStr)) {
         $resultStr = $this->transmitNews($object, $contentStr);
     } else {
         $resultStr = $this->transmitText($object, $contentStr);
     }
     return $resultStr;
 }
示例#21
0
<?php

header("Content-Type:text/xml");
$data = json_decode($_POST['data'], true);
$Wx = new Weixin($data);
$rst = $Wx->send();
echo $rst;
class Weixin
{
    public function __construct($data)
    {
        $this->url = $data["url"];
        $this->token = $data["token"];
        $this->data = $data;
    }
    private function makeMsg()
    {
        $msg = $this->data['data'];
        $xml = $this->xmlItemPack("xml", $msg);
        $xmlDoc = new SimpleXMLElement($xml);
        return $xmlDoc->asXML();
    }
    public function xmlItemPack($k, $v)
    {
        $head = "<" . $k . ">";
        $foot = "</" . $k . ">";
        if (is_string($v)) {
            $tpl = $head . "<![CDATA[" . $v . "]]>" . $foot;
        } else {
            if (is_numeric($v)) {
                $tpl = $head . $v . $foot;
示例#22
0
文件: index.php 项目: wkgg/uberHacker
    <meta name="viewport" content="target-densitydpi=320,width=640,user-scalable=0,maximum-scale=1.0" />
    <meta name="apple-mobile-web-app-capable" content="yes" />
    <meta name="apple-mobile-web-app-status-bar-style" content="black" />
    <meta name="msapplication-tap-highlight" content="no" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <style>a,body,div,footer,h1,h2,h3,h4,h5,h6,header,html,img,input,li,p,section,select,span,textarea,ul{margin:0;padding:0;-webkit-tap-highlight-color:rgba(255,0,0,0);border:none;outline:0;-webkit-touch-callout:none}html{min-height:100%}body{min-height:100%;font-family:'\5FAE\8F6F\96C5\9ED1','黑体','Helvetica Neue',Helvetica,Arial,sans-serif;font-size:30px;background:#f5f5eb}a,body{color:#000}.fixed-bottom,.fixed-screen-bottom{position:fixed;width:100%;height:100%;left:0;bottom:0}.clearfix:after,.clearfix:before{display:table;line-height:0;content:""}.clearfix:after{clear:both}a{text-decoration:none}img{max-width:100%}li{list-style:none}.fl{float:left}.fr{float:right}.radius5{border-radius:5px}.radius10{border-radius:10px}.hide{display:none}.show{display:block}.show-in{display:inline-block}.fixed-bottom{-webkit-backface-visibility:hidden}.fixed-bottom.blackbg{background:#292928;background:rgba(41,41,40,.95)}.icon,.icon-del-img{display:inline-block}.icon{background:url(http://cdnst.momocdn.com/static/m4/img/icon.png?20150126) no-repeat;background-size:250px auto;vertical-align:middle}</style>

    <script src="https://res.wx.qq.com/open/js/jweixin-1.0.0.js" type="text/javascript"></script>

    <?php 
define('APP_DIR', dirname(__FILE__));
require_once APP_DIR . '/action/weixin.php';
require_once APP_DIR . '/action/uber.php';
$appid = 'wx895ed4a1115b7e54';
$appsecret = 'd4624c36b6795d1d99dcf0547af5443d';
$weixin = new Weixin($appid, $appsecret);
$uber_appid = 'cmLDMkZ4cr9rivGlPd8Z6AQM-gdwiU2t';
$uber_appsecret = 'q7ImotFQf1BsgKhsT0STUrq0Vd8IquRSpcoBdS4A';
$uber = new Uber($uber_appid, $uber_appsecret, 'profile');
if (get('code') && get('state') == 'authorization') {
    $uber->oauth();
    exit;
}
$uber->gotoOAuth();
$jsSDK = $weixin->getJsApiConf();
?>

    <script>

        var UberHackthon = {
            ajax : function( url, data, callback, method, errorCallback ) {
示例#23
0
<?php

//引入库
require_once 'Weixin.php';
//创建SDK实例
$weixin = Weixin::init('vrobin', 'wx047be627bb7116c3', '392f899f7e6c57c0ffeb588cf01674bc', true);
/**
 * 创建自定义菜单菜单
 */
$menu = new WeixinMenu();
$menu->addButton('按钮1', 'click', 'EVENT_CLICK_1');
$menu->addButton('按钮2', 'click', 'EVENT_CLICK_2');
$menu->addButton('菜单');
$menu->addSubButton(1, '按钮1-1', 'click', 'EVENT_CLICK_1_1');
$menu->addSubButton(3, '谷歌', 'view', 'http://google.com');
print_r($menu->toArray());
$weixin->createMenu($menu);
print_r($weixin->getMenu());
/**
 * 获取关注用户列表
 */
print_r($weixin->getUserList());
示例#24
0
 public function weixin_back()
 {
     switch ($_GET['order_type']) {
         case 'group':
             $now_order = D('Group_order')->get_order_by_id($this->user_session['uid'], intval($_GET['order_id']));
             break;
         case 'meal':
         case 'takeout':
         case 'food':
             $now_order = D('Meal_order')->get_order_by_id($this->user_session['uid'], intval($_GET['order_id']));
             break;
         case 'weidian':
             $now_order = D('Weidian_order')->get_order_by_id($this->user_session['uid'], intval($_GET['order_id']));
             break;
         case 'recharge':
             $now_order = D('User_recharge_order')->get_order_by_id($this->user_session['uid'], intval($_GET['order_id']));
             break;
         default:
             $this->error_tips('非法的订单');
     }
     $now_order['order_type'] = $_GET['order_type'];
     if (empty($now_order)) {
         $this->error_tips('该订单不存在');
     }
     if ($now_order['paid']) {
         switch ($_GET['order_type']) {
             case 'group':
                 $redirctUrl = C('config.site_url') . '/wap.php?c=My&a=group_order&order_id=' . $now_order['order_id'];
                 break;
             case 'meal':
                 $redirctUrl = C('config.site_url') . '/wap.php?c=Meal&a=detail&orderid=' . $now_order['order_id'] . '&mer_id=' . $now_order['mer_id'] . '&store_id=' . $now_order['store_id'];
                 break;
             case 'takeout':
                 $redirctUrl = C('config.site_url') . '/wap.php?c=Takeout&a=order_detail&order_id=' . $now_order['order_id'] . '&mer_id=' . $now_order['mer_id'] . '&store_id=' . $now_order['store_id'];
                 break;
             case 'food':
                 $redirctUrl = C('config.site_url') . '/wap.php?c=Food&a=order_detail&order_id=' . $now_order['order_id'] . '&mer_id=' . $now_order['mer_id'] . '&store_id=' . $now_order['store_id'];
                 break;
             case 'weidian':
                 $redirctUrl = D('Weidian_order')->get_weidian_url(array('wecha_id' => $now_order['uid'], 'order_no' => $now_order['weidian_order_id'], 'pay_money' => $now_order['money'], 'third_id' => $now_order['third_id'], 'payment_method' => $now_order['pay_type']));
                 break;
             case 'recharge':
                 $redirctUrl = C('config.site_url') . '/wap.php?c=My&a=index';
                 break;
         }
         redirect($redirctUrl);
         exit;
     }
     $import_result = import('@.ORG.pay.Weixin');
     $pay_method = D('Config')->get_pay_method();
     if (empty($pay_method)) {
         $this->error_tips('系统管理员没开启任一一种支付方式!');
     }
     $pay_class = new Weixin($now_order, 0, 'weixin', $pay_method['weixin']['config'], $this->user_session, 1);
     $go_query_param = $pay_class->query_order();
     if ($go_query_param['error'] === 0) {
         switch ($_GET['order_type']) {
             case 'group':
                 D('Group_order')->after_pay($go_query_param['order_param']);
                 break;
             case 'meal':
             case 'takeout':
             case 'food':
                 D('Meal_order')->after_pay($go_query_param['order_param'], $_GET['order_type']);
                 break;
             case 'weidian':
                 D('Weidian_order')->after_pay($go_query_param['order_param']);
                 break;
             case 'recharge':
                 D('User_recharge_order')->after_pay($go_query_param['order_param']);
                 break;
         }
     }
     switch ($_GET['order_type']) {
         case 'group':
             $redirctUrl = C('config.site_url') . '/wap.php?g=Wap&c=My&a=group_order&order_id=' . $now_order['order_id'];
             break;
         case 'meal':
             $redirctUrl = C('config.site_url') . '/wap.php?g=Wap&c=Meal&a=detail&orderid=' . $now_order['order_id'] . '&mer_id=' . $now_order['mer_id'] . '&store_id=' . $now_order['store_id'];
             break;
         case 'takeout':
             $redirctUrl = C('config.site_url') . '/wap.php?g=Wap&c=Takeout&a=order_detail&order_id=' . $now_order['order_id'] . '&mer_id=' . $now_order['mer_id'] . '&store_id=' . $now_order['store_id'];
             break;
         case 'food':
             $redirctUrl = C('config.site_url') . '/wap.php?g=Wap&c=Food&a=order_detail&order_id=' . $now_order['order_id'] . '&mer_id=' . $now_order['mer_id'] . '&store_id=' . $now_order['store_id'];
             break;
         case 'weidian':
             $redirctUrl = D('Weidian_order')->get_weidian_url(array('wecha_id' => $now_order['uid'], 'order_no' => $now_order['weidian_order_id'], 'pay_money' => $now_order['money'], 'third_id' => $go_query_param['order_param']['third_id'], 'payment_method' => $go_query_param['order_param']['pay_type']));
             break;
         case 'recharge':
             $redirctUrl = C('config.site_url') . '/wap.php?c=My&a=index';
             break;
     }
     redirect($redirctUrl);
 }
示例#25
0
 function __construct()
 {
     $this->weixin = Weixin::instance();
 }
示例#26
0
文件: site.php 项目: houdunwang/hdcms
 public function doSitePreview()
 {
     $uid = q('post.uid');
     $id = q('post.id');
     $user = Db::table('member')->find($uid);
     $material = $this->db->find($id);
     $data['touser'] = $user['openid'];
     $data['mpnews']['media_id'] = $material['media_id'];
     $data['msgtype'] = 'mpnews';
     $res = Weixin::instance('message')->preview($data);
     if (empty($res['errcode'])) {
         message('发送消息成功,请查看微信客户端', '', 'success');
     } else {
         message('发送失败' . $res['errmsg'], '', 'error');
     }
 }
 public function index()
 {
     import('Think.ORG.Weixin');
     // 导入微信类
     $wechat = new Weixin();
     $wechat->valid();
     //$wechat->responseMsg();
     $postStr = $GLOBALS["HTTP_RAW_POST_DATA"];
     if (!empty($postStr)) {
         $key_word = M('keyword');
         $postObj = simplexml_load_string($postStr, 'SimpleXMLElement', LIBXML_NOCDATA);
         $fromUsername = trim($postObj->FromUserName);
         //发送方帐号(一个OpenID)
         $toUsername = $postObj->ToUserName;
         //开发者微信号
         $keyword = trim($postObj->Content);
         //用户发来的信息
         $RX_TYPE = trim($postObj->MsgType);
         //类型
         $EventKey = trim($postObj->EventKey);
         //事件KEY值
         $Event = $postObj->Event;
         //事件类型
         $time = time();
         if ($fromUsername != '') {
             $user = M('user')->field('id,username')->where("username='******'")->find();
             if ($user) {
             } else {
                 $date = time();
                 $data['username'] = $fromUsername;
                 //用户名
                 $data['reg_time'] = $date;
                 $data['last_time'] = $date;
                 $userid = M('user')->add($data);
             }
         }
         if ($RX_TYPE == 'event') {
             //**自定义点击事件**//
             if ($Event == 'CLICK') {
                 if ($EventKey != '') {
                     $where = array('key' => $EventKey);
                     $custom_key = M('custom_menu')->where($where)->find();
                     $key_list = $key_word->where("kyword='" . $custom_key['keyword'] . "'")->find();
                     //$key_list= $key_word->where("kyword='".$EventKey."'")->find();
                     if (is_array($key_list)) {
                         if ($key_list['type'] == 1) {
                             $this->wenben($fromUsername, $toUsername, $time, $key_list['kecontent']);
                         } else {
                             $titles = unserialize($key_list['titles']);
                             $imageinfo = unserialize($key_list['imageinfo']);
                             $linkinfo = unserialize($key_list['linkinfo']);
                             $textTpl = "<xml>\r\n\t\t\t\t\t\t\t<ToUserName><![CDATA[%s]]></ToUserName>\r\n\t\t\t\t\t\t\t<FromUserName><![CDATA[%s]]></FromUserName>\r\n\t\t\t\t\t\t\t<CreateTime>%s</CreateTime>\r\n\t\t\t\t\t\t\t<MsgType><![CDATA[%s]]></MsgType>\r\n\t\t\t\t\t\t\t <ArticleCount>%s</ArticleCount> \r\n                            <Articles>";
                             for ($i = 0; $i < count($titles); $i++) {
                                 if (stristr($linkinfo[$i], $_SERVER['SERVER_NAME'])) {
                                     if (stristr($linkinfo[$i], "?")) {
                                         $links = $linkinfo[$i] . "&key=" . $fromUsername;
                                     } else {
                                         $links = $linkinfo[$i] . "?key=" . $fromUsername;
                                     }
                                 } else {
                                     $links = $linkinfo[$i];
                                 }
                                 if (stristr($imageinfo[$i], $_SERVER['SERVER_NAME'])) {
                                     $images = $imageinfo[$i];
                                 } else {
                                     $images = "http://" . $_SERVER['SERVER_NAME'] . __ROOT__ . '/' . $imageinfo[$i];
                                 }
                                 $textTpl .= " <item>\r\n                           <Title><![CDATA[" . $titles[$i] . "]]></Title> \r\n                           <Description><![CDATA[" . $titles[$i] . "]]></Description>\r\n                          <PicUrl><![CDATA[" . $images . "]]></PicUrl>\r\n                           <Url><![CDATA[" . $links . "]]></Url>\r\n                           </item>";
                                 /*  $textTpl.= " <item>
                                      <Title><![CDATA[".$titles[$i]."]]></Title> 
                                      <Description><![CDATA[".$titles[$i]."]]></Description>
                                     <PicUrl><![CDATA[http://".$_SERVER['SERVER_NAME'].__ROOT__.'/'.$imageinfo[$i]."]]></PicUrl>
                                      <Url><![CDATA[".$links."]]></Url>
                                      </item>";*/
                             }
                             $textTpl .= "</Articles>\r\n                           <FuncFlag>0</FuncFlag>\r\n                           </xml> \r\n\t\t\t\t\t\t\t";
                             $this->tuwen($textTpl, $fromUsername, $toUsername, $time, count($titles));
                         }
                     }
                 }
             }
             if ($Event == 'subscribe') {
                 $key_list = $key_word->where("isfollow=1")->find();
                 if (is_array($key_list)) {
                     if ($key_list['type'] == 1) {
                         $this->wenben($fromUsername, $toUsername, $time, $key_list['kecontent']);
                     } else {
                         $titles = unserialize($key_list['titles']);
                         $imageinfo = unserialize($key_list['imageinfo']);
                         $linkinfo = unserialize($key_list['linkinfo']);
                         $textTpl = "<xml>\r\n\t\t\t\t\t\t\t<ToUserName><![CDATA[%s]]></ToUserName>\r\n\t\t\t\t\t\t\t<FromUserName><![CDATA[%s]]></FromUserName>\r\n\t\t\t\t\t\t\t<CreateTime>%s</CreateTime>\r\n\t\t\t\t\t\t\t<MsgType><![CDATA[%s]]></MsgType>\r\n\t\t\t\t\t\t\t <ArticleCount>%s</ArticleCount> \r\n                            <Articles>";
                         for ($i = 0; $i < count($titles); $i++) {
                             if (stristr($linkinfo[$i], $_SERVER['SERVER_NAME'])) {
                                 if (stristr($linkinfo[$i], "?")) {
                                     $links = $linkinfo[$i] . "&key=" . $fromUsername;
                                 } else {
                                     $links = $linkinfo[$i] . "?key=" . $fromUsername;
                                 }
                             } else {
                                 $links = $linkinfo[$i];
                             }
                             if (stristr($imageinfo[$i], $_SERVER['SERVER_NAME'])) {
                                 $images = $imageinfo[$i];
                             } else {
                                 $images = "http://" . $_SERVER['SERVER_NAME'] . __ROOT__ . '/' . $imageinfo[$i];
                             }
                             $textTpl .= " <item>\r\n                           <Title><![CDATA[" . $titles[$i] . "]]></Title> \r\n                           <Description><![CDATA[" . $titles[$i] . "]]></Description>\r\n                          <PicUrl><![CDATA[" . $images . "]]></PicUrl>\r\n                           <Url><![CDATA[" . $links . "]]></Url>\r\n                           </item>";
                         }
                         $textTpl .= "</Articles>\r\n                           <FuncFlag>0</FuncFlag>\r\n                           </xml> \r\n\t\t\t\t\t\t\t";
                         $this->tuwen($textTpl, $fromUsername, $toUsername, $time, count($titles));
                     }
                 }
             }
         }
         if (!empty($keyword)) {
             $key_list = $key_word->where("kyword='" . $keyword . "'")->find();
             if (is_array($key_list)) {
                 if ($key_list['type'] == 1) {
                     $this->wenben($fromUsername, $toUsername, $time, $key_list['kecontent']);
                 } else {
                     $titles = unserialize($key_list['titles']);
                     $imageinfo = unserialize($key_list['imageinfo']);
                     $linkinfo = unserialize($key_list['linkinfo']);
                     $textTpl = "<xml>\r\n\t\t\t\t\t\t\t<ToUserName><![CDATA[%s]]></ToUserName>\r\n\t\t\t\t\t\t\t<FromUserName><![CDATA[%s]]></FromUserName>\r\n\t\t\t\t\t\t\t<CreateTime>%s</CreateTime>\r\n\t\t\t\t\t\t\t<MsgType><![CDATA[%s]]></MsgType>\r\n\t\t\t\t\t\t\t <ArticleCount>%s</ArticleCount> \r\n                            <Articles>";
                     for ($i = 0; $i < count($titles); $i++) {
                         if (stristr($linkinfo[$i], $_SERVER['SERVER_NAME'])) {
                             if (stristr($linkinfo[$i], "?")) {
                                 $links = $linkinfo[$i] . "&key=" . $fromUsername;
                             } else {
                                 $links = $linkinfo[$i] . "?key=" . $fromUsername;
                             }
                         } else {
                             $links = $linkinfo[$i];
                         }
                         if (stristr($imageinfo[$i], $_SERVER['SERVER_NAME'])) {
                             $images = $imageinfo[$i];
                         } else {
                             $images = "http://" . $_SERVER['SERVER_NAME'] . __ROOT__ . '/' . $imageinfo[$i];
                         }
                         $textTpl .= " <item>\r\n                           <Title><![CDATA[" . $titles[$i] . "]]></Title> \r\n                           <Description><![CDATA[" . $titles[$i] . "]]></Description>\r\n                          <PicUrl><![CDATA[" . $images . "]]></PicUrl>\r\n                           <Url><![CDATA[" . $links . "]]></Url>\r\n                           </item>";
                     }
                     $textTpl .= "</Articles>\r\n                           <FuncFlag>0</FuncFlag>\r\n                           </xml> \r\n\t\t\t\t\t\t\t";
                     $this->tuwen($textTpl, $fromUsername, $toUsername, $time, count($titles));
                 }
             } else {
                 $key_list = $key_word->where("ismess=1")->find();
                 if (is_array($key_list)) {
                     if ($key_list['type'] == 1) {
                         $this->wenben($fromUsername, $toUsername, $time, $key_list['kecontent']);
                     } else {
                         $titles = unserialize($key_list['titles']);
                         $imageinfo = unserialize($key_list['imageinfo']);
                         $linkinfo = unserialize($key_list['linkinfo']);
                         $textTpl = "<xml>\r\n\t\t\t\t\t\t\t<ToUserName><![CDATA[%s]]></ToUserName>\r\n\t\t\t\t\t\t\t<FromUserName><![CDATA[%s]]></FromUserName>\r\n\t\t\t\t\t\t\t<CreateTime>%s</CreateTime>\r\n\t\t\t\t\t\t\t<MsgType><![CDATA[%s]]></MsgType>\r\n\t\t\t\t\t\t\t <ArticleCount>%s</ArticleCount> \r\n                            <Articles>";
                         for ($i = 0; $i < count($titles); $i++) {
                             if (stristr($linkinfo[$i], $_SERVER['SERVER_NAME'])) {
                                 if (stristr($linkinfo[$i], "?")) {
                                     $links = $linkinfo[$i] . "&key=" . $fromUsername;
                                 } else {
                                     $links = $linkinfo[$i] . "?key=" . $fromUsername;
                                 }
                             } else {
                                 $links = $linkinfo[$i];
                             }
                             if (stristr($imageinfo[$i], $_SERVER['SERVER_NAME'])) {
                                 $images = $imageinfo[$i];
                             } else {
                                 $images = "http://" . $_SERVER['SERVER_NAME'] . __ROOT__ . '/' . $imageinfo[$i];
                             }
                             $textTpl .= " <item>\r\n                           <Title><![CDATA[" . $titles[$i] . "]]></Title> \r\n                           <Description><![CDATA[" . $titles[$i] . "]]></Description>\r\n                          <PicUrl><![CDATA[" . $images . "]]></PicUrl>\r\n                           <Url><![CDATA[" . $links . "]]></Url>\r\n                           </item>";
                         }
                         $textTpl .= "</Articles>\r\n                           <FuncFlag>0</FuncFlag>\r\n                           </xml> \r\n\t\t\t\t\t\t\t";
                         $this->tuwen($textTpl, $fromUsername, $toUsername, $time, count($titles));
                     }
                 } else {
                 }
             }
         } else {
             echo "Input something...";
         }
     } else {
         echo "";
         exit;
     }
 }
示例#28
0
 /**
  * 关注事件
  *
  * @param string $openid
  * @param integer $reqtime
  * @param string $toUserName
  * @return string
  */
 public function onSubscribe($openid, $reqtime, $toUserName = '')
 {
     $uinfo = $this->wx->userInfo($openid);
     if (empty($uinfo['errcode'])) {
         $from = $this->from;
         $udata = ['openid' => $openid, 'subscribe' => $uinfo['subscribe']];
         if ($uinfo['subscribe']) {
             //已关注
             $udata['unionid'] = isset($uinfo['unionid']) ? $uinfo['unionid'] : '';
             //UnionID
             $udata['subscribe_time'] = $uinfo['subscribe_time'];
             $udata['nickname'] = $uinfo['nickname'];
             $udata['logo'] = $uinfo['headimgurl'];
             $udata['sex'] = $uinfo['sex'];
             $udata['lang'] = $uinfo['language'];
             $udata['country'] = $uinfo['country'];
             $udata['province'] = $uinfo['province'];
             $udata['city'] = $uinfo['city'];
             $udata['auth_method'] = 'base';
         }
         if (!Member::checkExistByOpenid($openid, $from)) {
             //用户不存在
             Member::createUser($udata, $from);
         } else {
             //用户已存在
             unset($udata['openid'], $udata['auth_method']);
             Member::updateUser($udata, $openid, $from);
         }
     }
     $msg = $this->about(1);
     return $msg;
 }
示例#29
0
<?php

Route::get('/wxcheck', function () {
    Weixin::getInstance()->valid();
});
Route::get('/wxmenu', function () {
    $menu = Weixin::getInstance()->getMenu();
    var_dump($menu);
});
示例#30
0
<?php

require './weixin.php';
$arr = array('account' => '', 'password' => '');
$w = new Weixin($arr);
var_dump($w->getAllUserInfo());
//获取所有用户信息
$a = $w->sendMessage('群发内123123123容');
var_dump($a);