public function get_access_token(){ $post = array( 'appid' => $this->_post('appid','trim'), ); $info = M('Wxuser')->where("appid='{$post['appid']}'")->getField('id'); if(empty($info)) { $return = array( 'errCode' => 10001, 'errMsg' => '无效的appid', ); } else { $apiOauth = new apiOauth(); $access_token = $apiOauth->update_authorizer_access_token($post['appid']); $return = array( 'errCode' => 0, 'errMsg' => 'success', 'access_token' => $access_token, ); } echo json_encode($return); }
public function _initialize() { parent::_initialize(); if (ALI_FUWU_GROUP) { $isgostr = "只有认证的服务号或者服务窗才可以使用!"; } else { $isgostr = "只有认证的服务号才可以使用!"; } $this->isgostr = $isgostr; $this->assign("isgostr", $this->isgostr); if (intval($this->wxuser["winxintype"]) != 3 && $this->wxuser["fuwuappid"] == "") { $this->error($isgostr); exit; } $where = array("token" => $this->token); $this->thisWxUser = M("Wxuser")->where($where)->find(); if ($this->thisWxUser["type"] == 0) { $diyApiConfig = M("Diymen_set")->where($where)->find(); if ((empty($this->thisWxUser["appid"]) || empty($this->thisWxUser["appsecret"])) && (empty($diyApiConfig["appid"]) || empty($diyApiConfig["appsecret"]))) { $this->error("请先设置AppID和AppSecret再使用本功能", "?g=User&m=Index&a=edit&id=" . $this->thisWxUser["id"]); } else { $this->thisWxUser["appid"] = $diyApiConfig["appid"]; $this->thisWxUser["appsecret"] = $diyApiConfig["appsecret"]; } } $apiOauth = new apiOauth(); $this->access_token = $apiOauth->update_authorizer_access_token($this->thisWxUser["appid"]); }
public function sendTempMsg($tempKey,$dataArr){ /* //example $tempKey = 'TM00130'; $dataArr = array('href' => 'http://www.baidu.com' , 'wecha_id' => 'oLA6VjgLrB3qPspOBRMYZZJpVkGQ' , 'first' => '您好,您已成功预约看房。' , 'apartmentName' => '丽景华庭' , 'roomNumber' => 'A栋534' , 'address' => '广州市微信路88号', 'time' => '2013年10月30日 15:32', 'remark' => '请您准时到达看房。'); */ $open = M('Tempmsg')->where(array('token'=>$this->myToken,'tempkey'=>"$tempKey"))->getField('status'); if($open){ //S($this->thisWxUser['appid'],NULL); // 获取配置信息 $dbinfo = M('Tempmsg')->where(array('token' => $this->myToken,'tempkey'=>"$tempKey"))->find(); $apiOauth = new apiOauth(); $access_token = $apiOauth->update_authorizer_access_token('',$this->thisWxUser); // 准备发送请求的数据 $requestUrl = 'https://api.weixin.qq.com/cgi-bin/message/template/send?access_token='.$access_token; //$data = $this->getData($tempKey,$dataArr,$dbinfo['textcolor']); preg_match_all('{{(\w+)\.DATA}}', $dbinfo['content'], $preg); $content = $preg[1]; $jsonData = ''; foreach($dataArr as $k => $v){ if(in_array($k, $content)){ $jsonData .= '"'.$k.'":{"value":"'.$v.'","color":"'.$dbinfo['textcolor'].'"},'; } } $jsonData = rtrim($jsonData,','); $data = "{".$jsonData."}"; $sendData = '{"touser":"******"wecha_id"].'","template_id":"'.$dbinfo["tempid"].'","url":"'.$dataArr["href"].'","topcolor":"'.$dbinfo["topcolor"].'","data":'.$data.'}'; return $this->postCurl($requestUrl,$sendData); } }
public function _initialize() { parent::_initialize(); if (ALI_FUWU_GROUP) { $isgostr = '只有认证的服务号或者服务窗才可以使用!'; } else { $isgostr = '只有认证的服务号才可以使用!'; } $this->isgostr = $isgostr; $this->assign('isgostr', $this->isgostr); if (intval($this->wxuser['winxintype']) != 3 && $this->wxuser['fuwuappid'] == '') { $this->error($isgostr); exit; } $where = array('token' => $this->token); $this->thisWxUser = M('Wxuser')->where($where)->find(); if ($this->thisWxUser['type'] == 0) { $diyApiConfig = M('Diymen_set')->where($where)->find(); if ((empty($this->thisWxUser['appid']) || empty($this->thisWxUser['appsecret'])) && (empty($diyApiConfig['appid']) || empty($diyApiConfig['appsecret']))) { $this->error('请先设置AppID和AppSecret再使用本功能', '?g=User&m=Index&a=edit&id=' . $this->thisWxUser['id']); } else { $this->thisWxUser['appid'] = $diyApiConfig['appid']; $this->thisWxUser['appsecret'] = $diyApiConfig['appsecret']; } } $apiOauth = new apiOauth(); $this->access_token = $apiOauth->update_authorizer_access_token($this->thisWxUser['appid']); }
private function _getGroup() { $apiOauth = new apiOauth(); $access_token = $apiOauth->update_authorizer_access_token($this->wxuser['appid']); $url = 'https://api.weixin.qq.com/cgi-bin/groups/get?access_token='.$access_token; $result = HttpClient::getInstance()->get($url); $result = json_decode($result, true); return $result; }
public function getGroupId() { $apiOauth = new apiOauth(); $access_token = $apiOauth->update_authorizer_access_token($this->thisWxUser['appid']); $url = 'https://api.weixin.qq.com/cgi-bin/groups/getid?access_token=' . $access_token; $result = HttpClient::getInstance()->post($url, array('post' => json_encode(array('openid' => $this->wechat_id)))); $result = json_decode($result); return $result->groupid; }
public function getSgin() { $apiOauth = new apiOauth(); $access_token = $apiOauth->update_authorizer_access_token($this->wxuser['appid'], $this->wxuser); $ticket = $apiOauth->getAuthorizerTicket($this->wxuser['appid'], $access_token); $url = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; $sign_data = $this->addSign($ticket, $url); $share_html = $this->createHtml($sign_data); return $share_html; }
public function sub() { if ($this->thisWxUser['appid'] && $this->thisWxUser['winxintype'] == 3) { //服务号 $apiOauth = new apiOauth(); $access_token = $apiOauth->update_authorizer_access_token($this->thisWxUser['appid']); $url = 'https://api.weixin.qq.com/cgi-bin/user/info?openid=' . $this->wecha_id . '&access_token=' . $access_token; $classData = json_decode($this->curlGet($url)); if ($classData->subscribe && $classData->subscribe == 1) { $datainfo['wechaname'] = str_replace(array("'", "\\"), array(''), $classData->nickname); $datainfo['sex'] = $classData->sex; $datainfo['portrait'] = $classData->headimgurl; $datainfo['token'] = $this->token; $datainfo['wecha_id'] = $this->wecha_id; $datainfo['city'] = $classData->city; $datainfo['province'] = $classData->province; $datainfo['tel'] = ''; $datainfo['birthday'] = ''; $datainfo['address'] = ''; $datainfo['info'] = ''; $datainfo['sign_score'] = 0; $datainfo['expend_score'] = 0; $datainfo['continuous'] = 0; $datainfo['add_expend'] = 0; $datainfo['add_expend_time'] = 0; $datainfo['live_time'] = 0; $datainfo['getcardtime'] = 0; } } else { //订阅号 $datainfo['wechaname'] = ''; $datainfo['sex'] = ''; $datainfo['portrait'] = ''; $datainfo['tel'] = ''; $datainfo['birthday'] = ''; $datainfo['address'] = ''; $datainfo['info'] = ''; $datainfo['sign_score'] = 0; $datainfo['expend_score'] = 0; $datainfo['continuous'] = 0; $datainfo['add_expend'] = 0; $datainfo['add_expend_time'] = 0; $datainfo['live_time'] = 0; $datainfo['getcardtime'] = 0; $datainfo['token'] = $this->token; $datainfo['wecha_id'] = $this->wecha_id; } if (!M('Userinfo')->where(array('token' => $this->token, 'wecha_id' => $this->wecha_id))->getField('id')) { //首次关注 M('Userinfo')->add($datainfo); } }
public function _initialize() { parent::_initialize(); $where = array('token' => $this->token); $this->thisWxUser = M('Wxuser')->where($where)->find(); if ($this->thisWxUser['type'] == 0) { $diyApiConfig = M('Diymen_set')->where($where)->find(); if ((empty($this->thisWxUser['appid']) || empty($this->thisWxUser['appsecret'])) && (empty($diyApiConfig['appid']) || empty($diyApiConfig['appsecret']))) { $this->error('请先设置AppID和AppSecret再使用本功能', '?g=User&m=Index&a=edit&id=' . $this->thisWxUser['id']); } else { $this->thisWxUser['appid'] = $diyApiConfig['appid']; $this->thisWxUser['appsecret'] = $diyApiConfig['appsecret']; } } $apiOauth = new apiOauth(); $this->access_token = $apiOauth->update_authorizer_access_token($this->thisWxUser['appid']); }
public function sendTempMsg($tempKey, $dataArr) { /* //example $tempKey = 'TM00130'; $dataArr = array('href' => 'http://www.baidu.com' , 'wecha_id' => 'oLA6VjgLrB3qPspOBRMYZZJpVkGQ' , 'first' => '您好,您已成功预约看房。' , 'apartmentName' => '丽景华庭' , 'roomNumber' => 'A栋534' , 'address' => '广州市微信路88号', 'time' => '2013年10月30日 15:32', 'remark' => '请您准时到达看房。'); */ $open = M('Tempmsg')->where(array('token' => $this->myToken, 'tempkey' => "{$tempKey}"))->getField('status'); if ($open) { //S($this->thisWxUser['appid'],NULL); // 获取配置信息 $dbinfo = M('Tempmsg')->where(array('token' => $this->myToken, 'tempkey' => "{$tempKey}"))->find(); $apiOauth = new apiOauth(); $access_token = $apiOauth->update_authorizer_access_token('', $this->thisWxUser); // 准备发送请求的数据 $requestUrl = 'https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=' . $access_token; $data = $this->getData($tempKey, $dataArr, $dbinfo['textcolor']); $sendData = '{"touser":"******"wecha_id"] . '","template_id":"' . $dbinfo["tempid"] . '","url":"' . $dataArr["href"] . '","topcolor":"' . $dbinfo["topcolor"] . '","data":' . $data . '}'; return $this->postCurl($requestUrl, $sendData); } }
public function getSgin() { if (empty($this->wxuser["is_syn"])) { $apiOauth = new apiOauth(); $access_token = $apiOauth->update_authorizer_access_token($this->wxuser["appid"], $this->wxuser); $ticket = $apiOauth->getAuthorizerTicket($this->wxuser["appid"], $access_token); } else { $domain = M("Users")->where(array("id" => $this->wxuser["uid"]))->getField("source_domain"); $url = $domain . A("Home/Auth")->getCallbackUrl($this->wxuser["is_syn"], "share"); $json = HttpClient::getInstance()->get($url); $json = json_decode($json, true); $ticket = $json["ticket"]; $this->wxuser["appid"] = $json["appid"]; } $url = "http://" . $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"]; $sign_data = $this->addSign($ticket, $url); $share_html = $this->createHtml($sign_data); return $share_html; }
public function getSgin() { $now = time(); //$share_data = M('Wxuser')->where(array('token'=>$this->token))->field('share_ticket,share_dated')->find(); if (empty($this->wxuser['share_ticket']) || empty($this->wxuser['share_dated']) || $this->wxuser['share_ticket'] != '' && $this->wxuser['share_dated'] != '' && $this->wxuser['share_dated'] < $now) { $apiOauth = new apiOauth(); $access_token = $apiOauth->update_authorizer_access_token($wxuser['appid'], $this->wxuser); $ticketData = $this->getTicket($access_token); if ($ticketData['errcode'] > 0) { $this->error['ticket_error'] = array('errcode' => $ticketData['errcode'], 'errmsg' => $ticketData['errmsg']); } else { M('Wxuser')->where(array('id' => $this->wxuser['id']))->save(array('share_ticket' => $ticketData['ticket'], 'share_dated' => $now + $ticketData['expires_in'])); $ticket = $ticketData['ticket']; } } else { $ticket = $this->wxuser['share_ticket']; } //$url = $this->getUrl(); $url = "http://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; $sign_data = $this->addSign($ticket, $url); //dump($sign_data); $share_html = $this->createHtml($sign_data); return $share_html; }
protected function isSubscribe() { S('fans_' . $this->token . '_' . $this->wecha_id, NULL); return D('Userinfo')->issub($this->token, $this->wecha_id); $wecha_id = $this->wecha_id; if ($this->owxuser['appid'] == '' || $this->owxuser['type'] == 0 && $this->owxuser['appsecret'] == '') { if ($this->owxuser['winxintype'] == 1 || $this->owxuser['winxintype'] == 2) { if ($wecha_id) { return true; } else { return false; } } else { return false; } } else { if ($this->owxuser['winxintype'] == 3 || $this->owxuser['winxintype'] == 4) { $apiOauth = new apiOauth(); $access_token = $apiOauth->update_authorizer_access_token($this->owxuser['appid'], $this->owxuser); $url = 'https://api.weixin.qq.com/cgi-bin/user/info?openid=' . $wecha_id . '&access_token=' . $access_token; $classData = json_decode($this->curlGet($url)); if ($classData->subscribe == 0) { return false; } else { return true; } } else { if ($this->owxuser['winxintype'] == 1 || $this->owxuser['winxintype'] == 2) { if ($wecha_id) { return true; } else { return false; } } else { return false; } } } }
private function _getAccessToken() { $where = array('token' => $this->token); $this->thisWxUser = M('Wxuser')->where($where)->find(); $apiOauth = new apiOauth(); $access_token = $apiOauth->update_authorizer_access_token($this->thisWxUser['appid']); return $access_token; }
protected function isSubscribe() { S("fans_" . $this->token . "_" . $this->wecha_id, NULL); return D("Userinfo")->issub($this->token, $this->wecha_id); $wecha_id = $this->wecha_id; if ($this->owxuser["appid"] == "" || $this->owxuser["type"] == 0 && $this->owxuser["appsecret"] == "") { if ($this->owxuser["winxintype"] == 1 || $this->owxuser["winxintype"] == 2) { if ($wecha_id) { return true; } else { return false; } } else { return false; } } else { if ($this->owxuser["winxintype"] == 3 || $this->owxuser["winxintype"] == 4) { $apiOauth = new apiOauth(); $access_token = $apiOauth->update_authorizer_access_token($this->owxuser["appid"], $this->owxuser); $url = "https://api.weixin.qq.com/cgi-bin/user/info?openid=" . $wecha_id . "&access_token=" . $access_token; $classData = json_decode($this->curlGet($url)); if ($classData->subscribe == 0) { return false; } else { return true; } } else { if ($this->owxuser["winxintype"] == 1 || $this->owxuser["winxintype"] == 2) { if ($wecha_id) { return true; } else { return false; } } else { return false; } } } }
public function upsave() { if ($_POST['biz'] != 1 && $_POST['qr'] == '') { $this->error('请填写二维码'); } $res = M("wxuser")->where(array('id' => $_POST['id']))->find(); $this->token = $res['token']; session('token', $res['token']); $_POST['appid'] = trim($_POST['appid']); $_POST['appsecret'] = trim($_POST['appsecret']); if (($_POST['appid'] != '' || $_POST['appsecret'] != '') && $res['type'] != 1 && $_POST['winxintype'] == 3) { $appid = $_POST['appid']; $secret = $_POST['appsecret']; $apiOauth = new apiOauth(); $access_token = $apiOauth->update_authorizer_access_token($appid); /* $url_access_token = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid={$appid}&secret={$secret}"; $data_access_token = json_decode($this->https_request($url_access_token), true); $access_token = $data_access_token['access_token']; if($data_access_token['errcode'] == 40001 || $data_access_token['errcode'] == 41002 || $data_access_token['errcode'] == 41004 || $data_access_token['errcode'] == 40125){ $this->error('您填的appid和appsecret不正确!'); }*/ if ($_POST['winxintype'] == 3) { $url = "https://api.weixin.qq.com/cgi-bin/customservice/getkflist?access_token={$access_token}"; $wxdata = json_decode($this->https_request($url), true); if ($wxdata['errcode'] == 48001) { $this->error('您填的appid和appsecret不是认证后的服务号!请修改您的appid和appsecret或者微信号类型'); } } /*elseif($_POST['winxintype'] == 4){ $url = "https://api.weixin.qq.com/cgi-bin/user/get?access_token={$access_token}"; $wxdata = json_decode($this->https_request($url), true); if($wxdata['errcode'] == 48001){ $this->error('您填的appid和appsecret未认证!请修改您的appid和appsecret或者微信号类型'); } }*/ } if ($_POST['wx_liaotian'] * 1 == 1) { $queryname = M('token_open')->where(array('token' => $this->token))->getField('queryname'); $queryname = explode(',', $queryname); if (!in_array('liaotian', $queryname)) { $openwhere = array('uid' => session('uid'), 'token' => session('token')); //删除掉重复的token $deleteWhere = array(); $deleteWhere['uid'] = array('neq', session('uid')); $deleteWhere['token'] = session('token'); M('Token_open')->where($deleteWhere)->delete(); // $open = M('Token_open')->where($openwhere)->find(); $str['queryname'] = str_replace(',,', ',', $open['queryname'] . ',liaotian'); // if (!$open) { M('Token_open')->add(array('uid' => session('uid'), 'token' => session('token'))); } // $backback = M('Token_open')->where($openwhere)->save($str); } } else { $queryname = M('token_open')->where(array('token' => $this->token))->getField('queryname'); $queryname = explode(',', $queryname); if (in_array('liaotian', $queryname)) { $openwhere = array('uid' => session('uid'), 'token' => session('token')); $open = M('Token_open')->where($openwhere)->find(); //删除掉重复的token $deleteWhere = array(); $deleteWhere['uid'] = array('neq', session('uid')); $deleteWhere['token'] = session('token'); M('Token_open')->where($deleteWhere)->delete(); // $str['queryname'] = ltrim(str_replace(',,', ',', str_replace('liaotian', '', $open['queryname'])), ','); $backback = M('Token_open')->where($openwhere)->save($str); } } if ($_POST['wx_lbsNews'] * 1 == 1) { $queryname = M('token_open')->where(array('token' => $this->token))->getField('queryname'); $queryname = explode(',', $queryname); if (!in_array('lbsNews', $queryname)) { $openwhere = array('uid' => session('uid'), 'token' => session('token')); //删除掉重复的token $deleteWhere = array(); $deleteWhere['uid'] = array('neq', session('uid')); $deleteWhere['token'] = session('token'); M('Token_open')->where($deleteWhere)->delete(); // $open = M('Token_open')->where($openwhere)->find(); $str['queryname'] = str_replace(',,', ',', $open['queryname'] . ',lbsNews'); // if (!$open) { M('Token_open')->add(array('uid' => session('uid'), 'token' => session('token'))); } // $backback = M('Token_open')->where($openwhere)->save($str); } } else { $queryname = M('token_open')->where(array('token' => $this->token))->getField('queryname'); $queryname = explode(',', $queryname); if (in_array('lbsNews', $queryname)) { $openwhere = array('uid' => session('uid'), 'token' => session('token')); $open = M('Token_open')->where($openwhere)->find(); //删除掉重复的token $deleteWhere = array(); $deleteWhere['uid'] = array('neq', session('uid')); $deleteWhere['token'] = session('token'); M('Token_open')->where($deleteWhere)->delete(); // $str['queryname'] = ltrim(str_replace(',,', ',', str_replace('lbsNews', '', $open['queryname'])), ','); $backback = M('Token_open')->where($openwhere)->save($str); } } if (isset($_POST['zweixin'])) { $_POST['wxid'] = $_POST['zwxid']; $_POST['weixin'] = $_POST['zweixin']; } S('wxuser_' . $this->token, NULL); M('Diymen_set')->where(array('token' => $this->token))->save(array('appid' => trim($this->_post('appid')), 'appsecret' => trim($this->_post('appsecret')))); // $db = D('Wxuser'); if (isset($_POST['demoStep'])) { $back = '/bindHelp?id=' . intval($_POST['id']); } else { $back = ''; } if ($db->create() === false) { $this->error($db->getError()); } else { $id = $db->save(); if ($id) { if (isset($_POST['demoStep'])) { header('Location:' . $this->siteUrl . U('Index/bindHelp', array('id' => intval($_POST['id'])))); } else { $appid = $this->_post('appid', 'trim'); $appid = str_replace("_no", "", $appid); M('Wxuser')->where(array('appid' => $appid, 'id' => array('neq', $this->_post('id', 'intval'))))->save(array('appid' => $appid . '_no')); $this->success('操作成功', U('index')); } } else { $this->error('操作失败', U('index')); } } }
public function sub() { if ($this->thisWxUser["appid"] && ($this->thisWxUser["winxintype"] == 3)) { $apiOauth = new apiOauth(); $access_token = $apiOauth->update_authorizer_access_token($this->thisWxUser["appid"]); $url = "https://api.weixin.qq.com/cgi-bin/user/info?openid=" . $this->wecha_id . "&access_token=" . $access_token; $classData = json_decode($this->curlGet($url)); if ($classData->subscribe && ($classData->subscribe == 1)) { $datainfo["wechaname"] = str_replace(array("'", "\\"), array(""), $classData->nickname); $datainfo["sex"] = $classData->sex; $datainfo["portrait"] = $classData->headimgurl; $datainfo["token"] = $this->token; $datainfo["wecha_id"] = $this->wecha_id; $datainfo["city"] = $classData->city; $datainfo["province"] = $classData->province; $datainfo["tel"] = ""; $datainfo["birthday"] = ""; $datainfo["address"] = ""; $datainfo["info"] = ""; $datainfo["sign_score"] = 0; $datainfo["expend_score"] = 0; $datainfo["continuous"] = 0; $datainfo["add_expend"] = 0; $datainfo["add_expend_time"] = 0; $datainfo["live_time"] = 0; $datainfo["getcardtime"] = 0; } } else { $datainfo["wechaname"] = ""; $datainfo["sex"] = ""; $datainfo["portrait"] = ""; $datainfo["tel"] = ""; $datainfo["birthday"] = ""; $datainfo["address"] = ""; $datainfo["info"] = ""; $datainfo["sign_score"] = 0; $datainfo["expend_score"] = 0; $datainfo["continuous"] = 0; $datainfo["add_expend"] = 0; $datainfo["add_expend_time"] = 0; $datainfo["live_time"] = 0; $datainfo["getcardtime"] = 0; $datainfo["token"] = $this->token; $datainfo["wecha_id"] = $this->wecha_id; } if (!M("Userinfo")->where(array("token" => $this->token, "wecha_id" => $this->wecha_id))->getField("id")) { $uid = D("Userinfo")->add($datainfo); if (empty($uid)) { return false; } if ($cardSet = D("Member_card_set")->where(array("token" => $this->token, "sub_give" => 1))->find()) { if ($card = M("Member_card_create")->field("id, number")->where("token='" . $this->token . "' and cardid=" . intval($cardSet["id"]) . " and wecha_id = ''")->order("id ASC")->find()) { $is_card = M("Member_card_create")->where(array("token" => $this->token, "wecha_id" => $this->wecha_id))->find(); if (empty($is_card)) { M("Member_card_create")->where(array("id" => $card["id"]))->save(array("wecha_id" => $this->wecha_id)); $now = time(); if (M("Userinfo")->where(array("token" => $this->token, "wecha_id" => $this->wecha_id))->save(array("getcardtime" => $now))) { $gwhere = array( "token" => $this->token, "cardid" => $cardSet["id"], "is_open" => "1", "start" => array("lt", $now), "end" => array("gt", $now) ); $gifts = M("Member_card_gifts")->where($gwhere)->select(); foreach ($gifts as $key => $value ) { if ($value["type"] == "1") { $arr = array(); $arr["itemid"] = 0; $arr["token"] = $this->token; $arr["wecha_id"] = $this->wecha_id; $arr["expense"] = 0; $arr["time"] = $now; $arr["cat"] = 3; $arr["staffid"] = 0; $arr["notes"] = "开卡赠送积分"; $arr["score"] = $value["item_value"]; M("Member_card_use_record")->add($arr); M("Userinfo")->where(array("token" => $this->token, "wecha_id" => $this->wecha_id))->setInc("total_score", $arr["score"]); } else { $cinfo = M("Member_card_coupon")->where(array("token" => $this->token, "id" => $value["item_value"]))->find(); if ($cinfo["is_weixin"] == 0) { $data["token"] = $this->token; $data["wecha_id"] = $this->wecha_id; $data["coupon_id"] = $value["item_value"]; $data["is_use"] = "0"; $data["cardid"] = $cardSet["id"]; $data["add_time"] = $now; if ($cinfo["type"] == 1) { $data["coupon_attr"] = serialize(array("coupon_name" => $cinfo["title"])); } else if ($cinfo["type"] == 2) { $data["coupon_attr"] = serialize(array("coupon_name" => $cinfo["title"], "gift_name" => $cinfo["gift_name"], "integral" => $cinfo["integral"])); } else { $data["coupon_attr"] = serialize(array("coupon_name" => $cinfo["title"], "least_cost" => $cinfo["least_cost"], "reduce_cost" => $cinfo["reduce_cost"])); } if ($value["item_attr"] == 1) { $data["coupon_type"] = "1"; } else if ($value["item_attr"] == 2) { $data["coupon_type"] = "3"; } else { $data["coupon_type"] = "2"; } $data["cancel_code"] = $this->_create_code(12); M("Member_card_coupon_record")->add($data); } } } } } else { M("Member_card_create")->where(array("token" => $this->token, "wecha_id" => $this->wecha_id))->delete(); M("Member_card_create")->where(array("id" => $card["id"]))->save(array("wecha_id" => $this->wecha_id)); } } } } M("Userinfo")->where(array("token" => $this->token, "wecha_id" => $this->wecha_id))->setField("issub", "1"); }
public function servicesay($to_openid, $from_nickname, $url) { $isurl = strstr($url, '&'); if ($isurl != '') { $url = str_replace('&', '&', $url); } $where_wxuser['token'] = $this->token; $appid = $this->m_wxuser->where($where_wxuser)->getField("appid"); $secret = $this->m_wxuser->where($where_wxuser)->getField("appsecret"); $wxuser = $this->m_wxuser->where($where_wxuser)->find(); //$data['err'] = $this->token;echo json_encode($data);exit; if ($appid == '' || $secret == '') { $data['err_code'] = 1; $data['err_msg'] = '公众号没有设置appid和appsecret!'; echo json_encode($data); exit; } $apiOauth = new apiOauth(); $url_access_token = $apiOauth->update_authorizer_access_token($appid, $wxuser); //$url_access_token = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid={$appid}&secret={$secret}"; $data_access_token = json_decode($this->https_request($url_access_token), true); if ($data_access_token['access_token'] != '') { $access_token = $data_access_token['access_token']; //获取客服列表判断是否有公众号客服 $url_kf_list = "https://api.weixin.qq.com/cgi-bin/customservice/getkflist?access_token={$access_token}"; $kf_list = json_decode($this->https_request($url_kf_list), true); //echo $this->https_request($url_kf_list);exit; if ($kf_list['kf_list'] == '') { $data['err_code'] = $kf_list['errcode']; $data['err_msg'] = '客服列表获取失败'; echo json_encode($data); exit; } foreach ($kf_list['kf_list'] as $vo) { if ($vo['kf_account'] == "kefu@" . $wxuser['weixin']) { $kefu = $vo['kf_account']; $img = $vo['kf_headimgurl']; } } //判断是否有公众号客服 if ($kefu != '') { //判断有公众号客服 //设置客服头像 if ($img == '') { $kf_headimgurl_url = "http://api.weixin.qq.com/customservice/kfaccount/uploadheadimg?access_token={$access_token}&kf_account={$kefu}"; $imgurl = str_replace($this->siteUrl, '', $wxuser['headerpic']); $imgurl = str_replace('./', '/', $imgurl); //$data_kf_headimgurl['media'] = "@".$_SERVER['DOCUMENT_ROOT'].str_replace(array('./'),array('/'))."/tpl/User/default/common/images/portrait.jpg;type=image/jpg"; $data_kf_headimgurl['media'] = "@" . $_SERVER['DOCUMENT_ROOT'] . $imgurl . ";type=image/jpg"; $uploadheadimg = json_decode($this->https_request($kf_headimgurl_url, $data_kf_headimgurl), true); if ($uploadheadimg['errcode'] != 0) { $data['err_code'] = $uploadheadimg['errcode']; $data['err_msg'] = '头像设置失败'; echo json_encode($data); exit; } } //$data['headimg'] = $img;echo json_encode($data);exit; $fasongdata = '{"touser":"******","msgtype":"text","text":{"content":"您的好友' . $from_nickname . '给您发来了一条新的消息,\\n\\n<a href=\'' . $url . '\'>点击查看</a>"},"customservice":{"kf_account":"' . $kefu . '"}}'; $url_send = "https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token={$access_token}"; $send = json_decode($this->https_request($url_send, $fasongdata), true); if ($send['errcode'] == 0) { $data['err_code'] = 0; $data['err_msg'] = '发送成功'; echo json_encode($data); } else { $data['err_code'] = $send['errcode']; $data['err_msg'] = '发送失败'; echo json_encode($data); exit; } } else { //判断没有公众号客服 $url_kfadd = "https://api.weixin.qq.com/customservice/kfaccount/add?access_token=" . $access_token; $kf_account = "kefu@" . $wxuser['weixin']; $data_kfadd = '{"kf_account":"' . $kf_account . '","nickname":"' . mb_substr($wxuser['wxname'], 0, 6, 'utf-8') . '","password":"******"}'; //$data['err_msg'] = $data_kfadd;echo json_encode($data);exit; $add = json_decode($this->https_request($url_kfadd, $data_kfadd), true); if ($add['errcode'] == 0) { //发送消息 $fasongdata = '{"touser":"******","msgtype":"text","text":{"content":"您的好友' . $from_nickname . '给您发来了一条新的消息,<a href=\'' . $url . '\'>点击查看</a>"},"customservice":{"kf_account":"' . $kf_account . '"}}'; $url_send = "https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token={$access_token}"; $send = json_decode($this->https_request($url_send, $fasongdata), true); if ($send['errcode'] == 0) { $data['err_code'] = 0; $data['err_msg'] = '发送成功'; echo json_encode($data); } else { $data['err_code'] = $send['errcode']; $data['err_msg'] = '发送失败'; echo json_encode($data); exit; } } else { $data['err_code'] = $add['errcode']; $data['err_msg'] = '添加客服失败' . $data_kfadd; echo json_encode($data); exit; } } } else { $data['err_code'] = $data_access_token['errcode']; $data['err_msg'] = '未获取access_token'; echo json_encode($data); exit; } }
public function send() { $fans = M('Wechat_group_list')->where(array('token' => $this->token))->order('id ASC')->select(); $i = intval($_GET['i']); $count = count($fans); $thisMessage = M('Send_message')->where(array('id' => intval($_GET['id'])))->find(); if ($i < $count) { $fan = $fans[$i]; $apiOauth = new apiOauth(); $access_token = $apiOauth->update_authorizer_access_token($this->thisWxUser['appid']); if ($access_token) { switch ($thisMessage['msgtype']) { case 'text': $data = '{"touser":"******","msgtype":"text","text":{"content":"' . $thisMessage['text'] . '"}}'; break; case 'image': case 'voice': $data = '{"touser":"******","msgtype":"' . $thisMessage['msgtype'] . '","' . $thisMessage['msgtype'] . '":{"media_id":"' . $thisMessage['mediaid'] . '"}}'; break; case 'video': $data = '{"touser":"******","msgtype":"' . $thisMessage['msgtype'] . '","' . $thisMessage['msgtype'] . '":{"media_id":"' . $thisMessage['mediaid'] . '","description":"' . $thisMessage['text'] . '","title":"' . $thisMessage['title'] . '"}}'; break; case 'music': $data = '{"touser":"******","msgtype":"' . $thisMessage['msgtype'] . '","' . $thisMessage['msgtype'] . '":{"media_id":"' . $thisMessage['mediaid'] . '"}}'; break; case 'news': $imgids = explode(',', $thisMessage['imgids']); $imgID = 0; if ($imgids) { foreach ($imgids as $ii) { if (intval($ii)) { $imgID = $ii; } } } $thisNews = M('Img')->where(array('id' => $imgID))->find(); if ($thisNews['url']) { $url = $this->convertLink($thisNews['url']); } else { $url = C('site_url') . U('Wap/Index/content', array('token' => $this->token, 'wecha_id' => $fan['openid'], 'id' => $thisNews['id'])); } $thisNews['title'] = str_replace('"', '\\"', $thisNews['title']); $data = '{"touser":"******","msgtype":"' . $thisMessage['msgtype'] . '","news":{"articles":[{"title":"' . $thisNews['title'] . '","description":"' . $thisNews['text'] . '","url":"' . $url . '","picurl":"' . $thisNews['pic'] . '"}]}}'; break; } $rt = $this->curlPost('https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token=' . $access_token, $data, 0); if ($rt['rt'] == false) { } else { M('Send_message')->where(array('id' => intval($thisMessage['id'])))->setInc('reachcount'); } $i++; $this->success('发送中:' . $i . '/' . $count, U('Message/send', array('id' => $thisMessage['id'], 'i' => $i))); } else { $this->error('获取access_token发生错误:错误代码' . $json->errcode . ',微信返回错误信息:' . $json->errmsg); } } else { $this->success('发送完成,发送成功' . $thisMessage['reachcount'] . '条', U('Message/sendHistory')); } }
private function get_access_token() { if (empty($this->myToken)) { return $this->print_error('token获取失败'); } $wxUser = M('Wxuser')->where(array('token' => $this->myToken))->field('appid,appsecret')->find(); if (empty($wxUser['appid'])) { return $this->print_error('appid获取失败'); } $apiOauth = new apiOauth(); $access_token = $apiOauth->update_authorizer_access_token($wxUser['appid']); if ($access_token) { //S('access_token',$access_token,5*3600); return $access_token; } else { return false; } }
function deliveryNotify(){ $pay_config_db=M('Alipay_config'); $this->payConfig=$pay_config_db->where(array('token'=>$this->token))->find(); $where=array('token'=>$this->token); $thiswxuser=M('Wxuser')->where($where)->find(); $apiOauth = new apiOauth(); $access_token = $apiOauth->update_authorizer_access_token($thiswxuser['appid']); $url='https://api.weixin.qq.com/pay/delivernotify?access_token='.$access_token; $now=time(); $payinfo=unserialize($this->payConfig['info']); if (!$this->payConfig['paysignkey']){ $string1=sha1('appid='.$this->payConfig['appid'].'&appkey='.$payinfo['weixin']['paysignkey'].'&deliver_msg=ok&deliver_status=1&deliver_timestamp='.$now.'&openid='.$_GET['wecha_id'].'&out_trade_no='.$_GET['orderid'].'&transid='.$_GET['transactionid'].''); }else { $string1=sha1('appid='.$this->payConfig['appid'].'&appkey='.$this->payConfig['paysignkey'].'&deliver_msg=ok&deliver_status=1&deliver_timestamp='.$now.'&openid='.$_GET['wecha_id'].'&out_trade_no='.$_GET['orderid'].'&transid='.$_GET['transactionid'].''); } $postdata='{"appid":"'.$this->payConfig['appid'].'","openid":"'.$_GET['wecha_id'].'","transid":"'.$_GET['transactionid'].'","out_trade_no":"'.$_GET['orderid'].'","deliver_timestamp":"'.$now.'","deliver_status":"1","deliver_msg":"ok","app_signature":"'.$string1.'","sign_method":"sha1"}'; $this->api_notice_increment($url,$postdata); $this->success('同步成功',U('Product/orderInfo',array('token'=>session('token'),'id'=>$_GET['id']))); }
public function upsave() { if ($_POST["biz"] != 1 && $_POST["qr"] == "") { $this->error("请填写二维码"); } $res = M("wxuser")->where(array("id" => $_POST["id"]))->find(); $this->token = $res["token"]; session("token", $res["token"]); $_POST["appid"] = trim($_POST["appid"]); $_POST["appsecret"] = trim($_POST["appsecret"]); if (($_POST["appid"] != "" || $_POST["appsecret"] != "") && $res["type"] != 1 && $_POST["winxintype"] == 3) { $appid = $_POST["appid"]; $secret = $_POST["appsecret"]; $apiOauth = new apiOauth(); $access_token = $apiOauth->update_authorizer_access_token($appid); if ($_POST["winxintype"] == 3) { $url = "https://api.weixin.qq.com/cgi-bin/customservice/getkflist?access_token={$access_token}"; $wxdata = json_decode($this->https_request($url), true); if ($wxdata["errcode"] == 48001) { $this->error("您填的appid和appsecret不是认证后的服务号!请修改您的appid和appsecret或者微信号类型"); } } } if ($_POST["wx_liaotian"] * 1 == 1) { $queryname = M("token_open")->where(array("token" => $this->token))->getField("queryname"); $queryname = explode(",", $queryname); if (!in_array("liaotian", $queryname)) { $openwhere = array("uid" => session("uid"), "token" => session("token")); $deleteWhere = array(); $deleteWhere["uid"] = array("neq", session("uid")); $deleteWhere["token"] = session("token"); M("Token_open")->where($deleteWhere)->delete(); $open = M("Token_open")->where($openwhere)->find(); $str["queryname"] = str_replace(",,", ",", $open["queryname"] . ",liaotian"); if (!$open) { M("Token_open")->add(array("uid" => session("uid"), "token" => session("token"))); } $backback = M("Token_open")->where($openwhere)->save($str); } } else { $queryname = M("token_open")->where(array("token" => $this->token))->getField("queryname"); $queryname = explode(",", $queryname); if (in_array("liaotian", $queryname)) { $openwhere = array("uid" => session("uid"), "token" => session("token")); $open = M("Token_open")->where($openwhere)->find(); $deleteWhere = array(); $deleteWhere["uid"] = array("neq", session("uid")); $deleteWhere["token"] = session("token"); M("Token_open")->where($deleteWhere)->delete(); $str["queryname"] = ltrim(str_replace(",,", ",", str_replace("liaotian", "", $open["queryname"])), ","); $backback = M("Token_open")->where($openwhere)->save($str); } } if ($_POST["wx_lbsNews"] * 1 == 1) { $queryname = M("token_open")->where(array("token" => $this->token))->getField("queryname"); $queryname = explode(",", $queryname); if (!in_array("lbsNews", $queryname)) { $openwhere = array("uid" => session("uid"), "token" => session("token")); $deleteWhere = array(); $deleteWhere["uid"] = array("neq", session("uid")); $deleteWhere["token"] = session("token"); M("Token_open")->where($deleteWhere)->delete(); $open = M("Token_open")->where($openwhere)->find(); $str["queryname"] = str_replace(",,", ",", $open["queryname"] . ",lbsNews"); if (!$open) { M("Token_open")->add(array("uid" => session("uid"), "token" => session("token"))); } $backback = M("Token_open")->where($openwhere)->save($str); } } else { $queryname = M("token_open")->where(array("token" => $this->token))->getField("queryname"); $queryname = explode(",", $queryname); if (in_array("lbsNews", $queryname)) { $openwhere = array("uid" => session("uid"), "token" => session("token")); $open = M("Token_open")->where($openwhere)->find(); $deleteWhere = array(); $deleteWhere["uid"] = array("neq", session("uid")); $deleteWhere["token"] = session("token"); M("Token_open")->where($deleteWhere)->delete(); $str["queryname"] = ltrim(str_replace(",,", ",", str_replace("lbsNews", "", $open["queryname"])), ","); $backback = M("Token_open")->where($openwhere)->save($str); } } if (isset($_POST["zweixin"])) { $_POST["wxid"] = $_POST["zwxid"]; $_POST["weixin"] = $_POST["zweixin"]; } S("wxuser_" . $this->token, NULL); M("Diymen_set")->where(array("token" => $this->token))->save(array("appid" => trim($this->_post("appid")), "appsecret" => trim($this->_post("appsecret")))); $db = D("Wxuser"); if (isset($_POST["demoStep"])) { $back = "/bindHelp?id=" . intval($_POST["id"]); } else { $back = ""; } if ($db->create() === false) { $this->error($db->getError()); } else { $id = $db->save(); if ($id) { if (isset($_POST["demoStep"])) { header("Location:" . $this->siteUrl . U("Index/bindHelp", array("id" => intval($_POST["id"])))); } else { $appid = $this->_post("appid", "trim"); $appid = str_replace("_no", "", $appid); M("Wxuser")->where(array("appid" => $appid, "id" => array("neq", $this->_post("id", "intval"))))->save(array("appid" => $appid . "_no")); $this->success("操作成功", U("index")); } } else { $this->error("操作失败", U("index")); } } }
public function __construct($wxuser) { $this->http = HttpClient::getInstance(); $apiOauth = new apiOauth(); $this->token = $apiOauth->update_authorizer_access_token($wxuser['appid']); }
public function insert() { $appid = $_POST['appid']; $secret = $_POST['secret']; if ($_POST['up_exts'] != '') { $_POST['up_exts'] = str_replace("'", '', $_POST['up_exts']); $_POST['up_exts'] = str_replace('"', '', $_POST['up_exts']); $_POST['up_exts'] = str_replace('‘', '', $_POST['up_exts']); $_POST['up_exts'] = str_replace('“', '', $_POST['up_exts']); $_POST['up_exts'] = str_replace(',', ',', $_POST['up_exts']); $_POST['up_exts'] = str_replace('’', '', $_POST['up_exts']); $_POST['up_exts'] = str_replace('”', '', $_POST['up_exts']); $_POST['up_exts'] = trim($_POST['up_exts']); $_POST['up_exts'] = strtolower($_POST['up_exts']); } else { unset($_POST['up_exts']); } if ($appid != '' && $secret != '') { $apiOauth = new apiOauth(); $access_token = $apiOauth->update_authorizer_access_token($appid); /* $url_access_token = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid={$appid}&secret={$secret}"; $data_access_token = json_decode($this->https_request($url_access_token), true); $access_token = $data_access_token['access_token']; */ $url = "https://api.weixin.qq.com/cgi-bin/customservice/getkflist?access_token={$access_token}"; $wxdata = json_decode($this->https_request($url), true); if ($wxdata['errcode'] == 48001) { $this->error('您填的appid和appsecret并不是认证后的服务号!'); exit; } /* if($data_access_token['errcode'] == 40001 || $data_access_token['errcode'] == 41002 || $data_access_token['errcode'] == 41004 || $data_access_token['errcode'] == 40125){ $this->error('您填的appid和appsecret不正确!'); exit; } */ } $file = $this->_post('files'); unset($_POST['files']); unset($_POST[C('TOKEN_NAME')]); if (isset($_POST['countsz'])) { $_POST['countsz'] = base64_encode($_POST['countsz']); } if ($this->update_config($_POST, CONF_PATH . $file)) { $this->success('操作成功'); } else { $this->success('操作失败'); } }
public function class_send() { if (IS_GET) { // 2015-05-25 需要填写保存后才能生成 修复托管用户获取不到 access_token的BUG $model = M('Wxuser')->where(array('token' => session('token')))->find(); if (empty($model['appid'])) { $this->error('AppId 不能为空,请填写保存后再进行生成菜单'); // , '?g=User&m=Index&a=edit&id='.$this->thisWxUser['id'] } else { if (empty($model['appsecret'])) { if (1 != $model['type']) { $this->error('非托管用户 AppSecret 不能为空,请填写保存后再进行生成菜单'); // , '?g=User&m=Index&a=edit&id='.$this->thisWxUser['id'] } } } $this->thisWxUser['appid'] = $model['appid']; $this->thisWxUser['appsecret'] = $model['appsecret']; $apiOauth = new apiOauth(); $this->access_token = $apiOauth->update_authorizer_access_token($this->thisWxUser['appid']); $data = '{"button":['; $class = M('Diymen_class')->where(array('token' => session('token'), 'pid' => 0, 'is_show' => 1))->limit(3)->order('sort DESC, id ASC')->select(); //dump($class); $kcount = count($class); $k = 1; foreach ($class as $key => $vo) { //主菜单 $data .= '{"name":"' . $vo['title'] . '",'; $c = M('Diymen_class')->where(array('token' => session('token'), 'pid' => $vo['id'], 'is_show' => 1))->limit(5)->order('sort DESC, id ASC')->select(); $count = count($c); //子菜单 $vo['url'] = $this->convertLink($vo['url']); // 2015-05-11 一键拔号 $tel = $this->convertLink('{siteUrl}' . U('Wap/Index/tel', array('tel' => $vo['tel'], 'token' => session('token')))); // 2015-05-20 一键导航 $amap = $this->convertLink('{siteUrl}' . U('Wap/Index/map', array('nav' => $vo['nav'], 'name' => $vo['title'], 'token' => session('token')))); if ($c != false) { $data .= '"sub_button":['; } else { if ($vo['keyword']) { $data .= '"type":"click","key":"' . $vo['keyword'] . '"'; } else { if ($vo['url']) { $data .= '"type":"view","url":"' . $vo['url'] . '"'; } else { if ($vo['wxsys']) { $data .= '"type":"' . $this->_get_sys('send', $vo['wxsys']) . '","key":"' . $vo['wxsys'] . '"'; } else { if ($vo['tel']) { $data .= '"type":"view","url":"' . $tel . '"'; } else { if ($vo['nav']) { $data .= '"type":"view","url":"' . $amap . '"'; } } } } } } $i = 1; foreach ($c as $voo) { $voo['url'] = $this->convertLink($voo['url']); // 2015-05-11 一键拔号 $tel = $this->convertLink($this->siteUrl . U('Wap/Index/tel', array('tel' => $voo['tel'], 'token' => session('token')))); // 2015-05-20 一键导航 $amap = $this->convertLink('{siteUrl}' . U('Wap/Index/map', array('nav' => $voo['nav'], 'name' => $voo['title'], 'token' => session('token')))); if ($i == $count) { if ($voo['keyword']) { $data .= '{"type":"click","name":"' . $voo['title'] . '","key":"' . $voo['keyword'] . '"}'; } else { if ($voo['url']) { $data .= '{"type":"view","name":"' . $voo['title'] . '","url":"' . $voo['url'] . '"}'; } else { if ($voo['wxsys']) { $data .= '{"type":"' . $this->_get_sys('send', $voo['wxsys']) . '","name":"' . $voo['title'] . '","key":"' . $voo['wxsys'] . '"}'; } else { if ($voo['tel']) { $data .= '{"type":"view","name":"' . $voo['title'] . '","url":"' . $tel . '"}'; } else { if ($voo['nav']) { $data .= '{"type":"view","name":"' . $voo['title'] . '","url":"' . $amap . '"}'; } } } } } } else { if ($voo['keyword']) { $data .= '{"type":"click","name":"' . $voo['title'] . '","key":"' . $voo['keyword'] . '"},'; } else { if ($voo['url']) { $data .= '{"type":"view","name":"' . $voo['title'] . '","url":"' . $voo['url'] . '"},'; } else { if ($voo['wxsys']) { $data .= '{"type":"' . $this->_get_sys('send', $voo['wxsys']) . '","name":"' . $voo['title'] . '","key":"' . $voo['wxsys'] . '"},'; } else { if ($voo['tel']) { $data .= '{"type":"view","name":"' . $voo['title'] . '","url":"' . $tel . '"},'; } else { if ($voo['nav']) { $data .= '{"type":"view","name":"' . $voo['title'] . '","url":"' . $amap . '"},'; } } } } } } $i++; } if ($c != false) { $data .= ']'; } if ($k == $kcount) { $data .= '}'; } else { $data .= '},'; } $k++; } $data .= ']}'; file_get_contents('https://api.weixin.qq.com/cgi-bin/menu/delete?access_token=' . $this->access_token); $url = 'https://api.weixin.qq.com/cgi-bin/menu/create?access_token=' . $this->access_token; $rt = $this->api_notice_increment($url, $data); if ($rt['rt'] == false) { $errmsg = GetErrorMsg::wx_error_msg($rt['errorno']); $this->error($rt['errorno'] . ':' . $errmsg . '!'); } else { $this->success('生成菜单成功'); } exit; } else { $this->error('非法操作'); } }
function _getAccessToken() { $apiOauth = new apiOauth(); $access_token = $apiOauth->update_authorizer_access_token($this->thisWxUser['appid']); return $access_token; }