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"]); }
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 addrSign() { $url = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; $this->url = $url; $apiOauth = new apiOauth(); $oauthData = $apiOauth->webOauth($this->wxuser, 'snsapi_base'); return $this->getSign($oauthData['access_token']); }
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 get_js_ticket() { $post = array('appid' => $this->_post('appid', 'trim'), 'access_token' => $this->_post('access_token', 'trim')); $info = M('Wxuser')->where("appid='{$post['appid']}'")->getField('id'); if (empty($info)) { $return = array('errCode' => 10002, 'errMsg' => '无效的appid'); } else { $apiOauth = new apiOauth(); $apiTicket = $apiOauth->getAuthorizerTicket($post['appid'], $post['access_token']); if (empty($apiTicket)) { $return = array('errCode' => 10003, 'errMsg' => '获取ticket失败'); } else { $return = array('errCode' => 0, 'errMsg' => 'success', 'ticket' => $apiTicket); } } echo json_encode($return); }
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; } } } }
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('非法操作'); } }
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; }
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 oauth_back() { $ac_id = intval($_GET['ac_id']); $auth_code = $_GET['auth_code']; $expires_in = $_GET['expires_in']; if (!empty($auth_code) && !empty($expires_in)) { $apiOauth = new apiOauth(); $authorization_info = $apiOauth->get_authorization_info($auth_code); $authorizer_info = $apiOauth->get_authorizer_info($authorization_info['authorizer_appid']); $appid = $authorization_info['authorizer_appid']; $where = array('uid' => session('uid')); if (!empty($ac_id)) { $where['id'] = $ac_id; } else { $where['appid'] = $appid; } //file_put_contents('authorization_info.txt',json_encode($authorization_info)); //file_put_contents('authorizer_info.txt',json_encode($authorizer_info)); $wxinfo = M('Wxuser')->where($where)->find(); if ($wxinfo) { $save = array(); $save['type'] = 1; $save['encode'] = 2; $save['wxid'] = $authorizer_info['user_name']; $save['wxname'] = $authorizer_info['nick_name']; $save['weixin'] = $authorizer_info['alias']; $save['headerpic'] = empty($authorizer_info['head_img']) ? '' : $authorizer_info['head_img']; $service_type = $authorizer_info['service_type_info']['id']; $verify_type = $authorizer_info['verify_type_info']['id']; if (($service_type == 0 || $service_type == 1) && $verify_type == 0) { $res['winxintype'] = 4; } else { if ($service_type == 2 && $verify_type == 0) { $res['winxintype'] = 3; } else { if ($service_type == 2 && $verify_type == -1) { $save['winxintype'] = 2; } else { if (($service_type == 0 || $service_type == 1) && $verify_type == -1) { $save['winxintype'] = 1; } } } } $save['appid'] = $authorization_info['authorizer_appid']; $save['authorizer_access_token'] = $authorization_info['authorizer_access_token']; $save['authorizer_refresh_token'] = $authorization_info['authorizer_refresh_token']; $save['authorizer_expires'] = $authorization_info['expires_in'] + time(); if (M('Wxuser')->where($where)->save($save)) { $update = array('appid' => $save['appid'] . '_no', 'authorizer_access_token' => '', 'authorizer_refresh_token' => '', 'authorizer_expires' => 0); M('Wxuser')->where("appid = '{$save['appid']}' AND id != {$wxinfo['id']}")->save($update); $status = true; } } else { $status = $this->add_authorizer($authorizer_info, $authorization_info); } if ($status) { $this->success('公众号授权成功', U('Index/index')); } else { $this->error('公众号授权失败', U('Index/index')); } } else { $this->error('授权错误', U('Index/oauth')); } }
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')); } }
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; } }
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; } }
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('操作失败'); } }
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 oauth_back() { $ac_id = intval($_GET["ac_id"]); $auth_code = $_GET["auth_code"]; $expires_in = $_GET["expires_in"]; if (!empty($auth_code) && !empty($expires_in)) { $apiOauth = new apiOauth(); $authorization_info = $apiOauth->get_authorization_info($auth_code); $authorizer_info = $apiOauth->get_authorizer_info($authorization_info["authorizer_appid"]); $appid = $authorization_info["authorizer_appid"]; $where = array("uid" => session("uid")); if (!empty($ac_id)) { $where["id"] = $ac_id; } else { $where["appid"] = $appid; } $wxinfo = M("Wxuser")->where($where)->find(); if ($wxinfo) { $save = array(); $save["type"] = 1; $save["encode"] = 2; $save["wxid"] = $authorizer_info["user_name"]; $save["wxname"] = $authorizer_info["nick_name"]; $save["weixin"] = $authorizer_info["alias"]; $save["headerpic"] = empty($authorizer_info["head_img"]) ? "" : $authorizer_info["head_img"]; $service_type = $authorizer_info["service_type_info"]["id"]; $verify_type = $authorizer_info["verify_type_info"]["id"]; if (($service_type == 0 || $service_type == 1) && $verify_type == 0) { $res["winxintype"] = 4; } else { if ($service_type == 2 && $verify_type == 0) { $res["winxintype"] = 3; } else { if ($service_type == 2 && $verify_type == -1) { $save["winxintype"] = 2; } else { if (($service_type == 0 || $service_type == 1) && $verify_type == -1) { $save["winxintype"] = 1; } } } } $save["appid"] = $authorization_info["authorizer_appid"]; $save["authorizer_access_token"] = $authorization_info["authorizer_access_token"]; $save["authorizer_refresh_token"] = $authorization_info["authorizer_refresh_token"]; $save["authorizer_expires"] = $authorization_info["expires_in"] + time(); if (M("Wxuser")->where($where)->save($save)) { $update = array("appid" => $save["appid"] . "_no", "authorizer_access_token" => "", "authorizer_refresh_token" => "", "authorizer_expires" => 0); M("Wxuser")->where("appid = '{$save["appid"]}' AND id != {$wxinfo["id"]}")->save($update); $status = true; } } else { $status = $this->add_authorizer($authorizer_info, $authorization_info); } if ($status) { $this->success("公众号授权成功", U("Index/index")); } else { $this->error("公众号授权失败", U("Index/index")); } } else { $this->error("授权错误", U("Index/oauth")); } }
public function __construct($wxuser) { parent::__construct(); $this->wxuser = $wxuser; $this->access_token = $this->update_authorizer_access_token('', $this->wxuser); }
public function __construct($wxuser) { $this->http = HttpClient::getInstance(); $apiOauth = new apiOauth(); $this->token = $apiOauth->update_authorizer_access_token($wxuser['appid']); }
function _getAccessToken() { $apiOauth = new apiOauth(); $access_token = $apiOauth->update_authorizer_access_token($this->thisWxUser['appid']); return $access_token; }