protected function _initialize() { //S('access_token',null); //如果没有access_token if (S('at_time') + 7200 <= time()) { $wx_info = C('wx_info'); $Auth = new WechatAuth($wx_info['AppID'], $wx_info['Secret']); //获取access_token $access_token = $Auth->getAccessToken(); if (!empty($access_token['access_token'])) { //保存到缓存7198秒 S('access_token', $access_token['access_token'], 7198); S('at_time', time()); } else { $this->error('获取信息失败,请通知管理员'); } } if (empty(S('access_token'))) { $wx_info = C('wx_info'); $Auth = new WechatAuth($wx_info['AppID'], $wx_info['Secret']); //获取access_token $access_token = $Auth->getAccessToken(); if (!empty($access_token['access_token'])) { //保存到缓存7198秒 S('access_token', $access_token['access_token'], 7198); S('at_time', time()); } else { $this->error('获取信息失败,请通知管理员'); } } }
public function index() { $wechatauth = new WechatAuth(C('WEIXIN.APPID'), C('WEIXIN.SECRET'), C('')); $access_token = $wechatauth->getAccessToken(); $result = $wechatauth->getServerIp($access_token); if (isset($result['errcode'])) { $this->error($result['errmsg']); } slog($result); $this->assign('ip', $result['ip_list']); $this->display(); }
/** * @return array|mixed * @throws \Exception * Judge weChat access_token */ protected function tokenJudge() { $res = M('token')->where("id = 1")->find(); $time = $res['m_time']; $now = time(); if ($now - $time >= 3600) { $weChat = new WechatAuth(); $data = $weChat->getAccessToken(); $token = $data['access_token']; $save = ['token' => $token, 'm_time' => time()]; M('token')->where("id = 1")->save($save); } else { $token = $res['token']; } return $token; }
public function menudel() { $wx_info = C('wx_info'); $Auth = new WechatAuth($wx_info['AppID'], $wx_info['Secret'], S('access_token')); $rs = $Auth->menuDelete(); print_r($rs); }
/** * 资源文件上传方法 * @param string $type 上传的资源类型 * @return string 媒体资源ID */ private function upload($type) { $appid = $this->flat['wt_appid']; $appsecret = $this->flat['wt_appsecret']; $token = session("token"); if ($token) { $auth = new WechatAuth($appid, $appsecret, $token); } else { $auth = new WechatAuth($appid, $appsecret); $token = $auth->getAccessToken(); session(array('expire' => $token['expires_in'])); session("token", $token['access_token']); } switch ($type) { case 'image': $filename = './Public/image.jpg'; $media = $auth->materialAddMaterial($filename, $type); break; case 'voice': $filename = './Public/voice.mp3'; $media = $auth->materialAddMaterial($filename, $type); break; case 'video': $filename = './Public/video.mp4'; $discription = array('title' => '视频标题', 'introduction' => '视频描述'); $media = $auth->materialAddMaterial($filename, $type, $discription); break; case 'thumb': $filename = './Public/music.jpg'; $media = $auth->materialAddMaterial($filename, $type); break; default: return ''; } if ($media["errcode"] == 42001) { //access_token expired session("token", null); $this->upload($type); } return $media['media_id']; }
/** * 微信消息接口入口 * 所有发送到微信的消息都会推送到该操作 * 所以,微信公众平台后台填写的api地址则为该操作的访问地址 */ public function index() { $token = 'maimaimai'; //微信后台填写的TOKEN /* 加载微信SDK */ $wechat = new Wechat($token); /* 获取请求信息 */ $data = $wechat->request(); if ($data && is_array($data)) { $wx_info = C('wx_info2'); $Auth = new WechatAuth($wx_info['AppID'], $wx_info['Secret'], S('access_token2')); switch ($data['MsgType']) { case Wechat::MSG_TYPE_EVENT: switch ($data['Event']) { case Wechat::MSG_EVENT_SUBSCRIBE: // 来源openid $form_openid = $data['FromUserName']; //获取来源者信息 $form = $Auth->userInfo($form_openid); $old_wx['nickname'] = $form['nickname']; $old_wx['sex'] = $form['sex']; $old_wx['city'] = $form['city']; $old_wx['province'] = $form['province']; $result = M('wx_user')->where($old_wx)->find(); //判断 if ($result) { $form['yyg_openid'] = $result['openid']; } $db = M('wx_jzq_user')->where(array('openid' => $form['openid']))->Find(); if (!$db) { M('wx_jzq_user')->where(array('openid' => $form['openid']))->delete(); M('wx_jzq_user')->add($form); } $wechat->replyText("欢迎!发送<查询>可以查询邀请送红包活动信息"); } break; case Wechat::MSG_TYPE_TEXT: switch ($data['Content']) { case '查询': $re = M('wx_jzq_user')->where(array('openid' => $form['openid']))->Find(); if ($re['openid'] = !null && ($re['yyg_openid'] = !null)) { $m = M('wx_user')->where(array('openid' => $re['yyg_openid']))->find(); if ($m['fahongbao'] != 0) { $wechat->replyText("明天准备收红包"); break; } else { $wechat->replyText("邀请人数不足,请努力"); break; } } else { $form_openid = $data['FromUserName']; //获取来源者信息 $form = $Auth->userInfo($form_openid); $old_wx['nickname'] = $form['nickname']; $old_wx['sex'] = $form['sex']; $old_wx['city'] = $form['city']; $old_wx['province'] = $form['province']; //判断 $result = M('wx_user')->where($old_wx)->find(); if ($result) { $form['yyg_openid'] = $result['openid']; } $db = M('wx_jzq_user')->where(array('openid' => $form['openid']))->Find(); if (!$db) { M('wx_jzq_user')->where(array('openid' => $form['openid']))->delete(); M('wx_jzq_user')->add($form); } if ($db['yyg_openid'] == null) { $wechat->replyText("请再次查询"); break; } break; } } break; } } }
/** * @param $openid * @param $order [订单号] */ private function successMsgSend($openid, $order) { $weChat = new WechatAuth(); $token = $this->tokenJudge(); $weChat->tokenWrite($token); $content = "支付成功!\n\n你的订单号为" . $order . "的订单已经成功支付,请等待跑腿哥接单!"; $weChat->sendText($openid, $content); return true; }
public function weixinQr($sence_id, $expire_seconds = 0) { $wechatauth = new WechatAuth(C('WEIXIN.APPID'), C('WEIXIN.SECRET')); $result = $wechatauth->qrcodeCreate($sence_id, $expire_seconds); if (isset($result['errcode'])) { return false; } else { return $wechatauth->showqrcode($result['ticket']); } }
public function menudel() { vendor('Weixinpay.WxPayJsApiPay'); $appid = \WxPayConfig::APPID; $appsecret = \WxPayConfig::APPSECRET; $wxmsg = new WxUserInfo(); $access_token = $wxmsg->accessToken(); $Auth = new WechatAuth($appid, $appsecret, $access_token); $rs = $Auth->menuDelete(); print_r($rs); }
function detail() { $id = I("get.id"); $flat = $this->flat_model->where("id = {$id}")->find(); $appid = $flat['wt_appid']; $appsecret = $flat['wt_appsecret']; $auth = new WechatAuth($appid, $appsecret); ////获取组 $group = $auth->userGet(); //groupsGet(); $this->assign("group", $group); $this->display(); }