| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044 |
- <?php
- /**
- * Created by PhpStorm.
- * User: xiepeng
- * Date: 2017/8/17
- */
- class weixin
- {
- /**线上***/
- const SCOPE_USERINFO = 'snsapi_base'; //授权方法
- /**测试***/
- const TOKEN_BASE_KEY = "weixin_access_token";
- const JS_TICKET_KEY = "weixin_js_ticket";
- const LimitTime = 7100;
- public $setFlag = false;
- public $msgtype = 'text'; //('text','image','location')
- public $msg = array();
- /****微信支付支付向相关参数****/
- public function __construct()
- {
- }
- public function index()
- {
- $timestamp = $_GET['timestamp'];
- $nonce = $_GET['nonce'];
- $token = 'weixin_xian_rd_2018';
- $signature = $_GET['signature'];
- $echostr = $_GET['echostr'];
- $array = array($timestamp, $nonce, $token);
- sort($array);
- $tmpstr = sha1(implode('', $array));
- if ($tmpstr == $signature && $echostr) {
- echo $echostr;
- }
- }
- public function getAccessToken()
- {
- $rs = Baseconfig::getInfoByKey(self::TOKEN_BASE_KEY);
- if (empty($rs) || (time() - $rs["lastupdate"]) > self::LimitTime) {
- $accessToken = self::refreshToken();
- //var_dump($accessToken);
- } else {
- $accessToken = $rs["value"];
- }
- if(empty($accessToken))
- {
- echo("获取access_token失败") ;
- exit;
- }
- return $accessToken;
- }
- public function refreshToken()
- {
- $conf = $this->_conf();
- $token_access_url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=" . $conf["appid"] . "&secret=" . $conf["appkey"];
- $res = file_get_contents($token_access_url); //
- $result = json_decode($res, true); //接受一个 JSON 格式的字符串并且把它转换为 PHP 变量s
- $access_token = $result['access_token'];
- if(empty($access_token))
- {
- echo("获取刷新access_token失败") ;
- exit;
- }
- $rs = Baseconfig::getInfoByKey(self::TOKEN_BASE_KEY);
- if ($rs) {
- $res = Baseconfig::update($rs["id"], array("value" => $access_token, "lastupdate" => time()));
- } else {
- $res = Baseconfig::add(self::TOKEN_BASE_KEY, $access_token, "微信开发access_token");
- }
- if ($res) {
- return $access_token;
- }
- }
- public function getUserInfo($openId)
- {
- $token = $this->getAccessToken();
- $token_access_url = "https://api.weixin.qq.com/cgi-bin/user/info?access_token=" . $token . "&openid=" . $openId . "&lang=zh_CN";
- $res = file_get_contents($token_access_url); //
- return json_decode($res, true); //接受一个 JSON 格式的字符串并且把它转换为 PHP 变量
- }
- public function getInfoByCode()
- {
- $code = isset($_REQUEST["code"])?$_REQUEST["code"]:"";
- if(empty($code))
- {
- return 0;
- }
- $conf = $this->_conf();
- $token_access_url = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=" . $conf["appid"] . "&secret=" . $conf["appkey"] . "&code=" . $code . "&grant_type=authorization_code";
- $res = file_get_contents($token_access_url); //
- return json_decode($res, true); //接受一个 JSON 格式的字符串并且把它转换为 PHP 变量,若不加TURE,则是一个对象
- }
- public function createMenu()
- {
- global $HTTP_PATH;
- $access_token = $this->getAccessToken();
-
- $data = '{
- "button": [
- {
- "name": "使用贴士",
- "sub_button": [
- {
- "type": "view",
- "name": "锅炉常识",
- "url": "'.$HTTP_PATH.'weixin/weixin_industry_info.php"
- },
- {
- "type": "view",
- "name": "使用指南",
- "url": "'.$HTTP_PATH.'weixin/weixin_product_describe.php"
- }
- ]
- },
- {
- "name": "我的",
- "sub_button": [
- {
- "type": "view",
- "name": "一键报修",
- "url": "'.$HTTP_PATH.'weixin/weixin_repair.php"
- },
- {
- "type": "view",
- "name": "个人信息",
- "url": "'.$HTTP_PATH.'weixin/weixin_personal_detail.php"
- }
- ]
- }
- ]
- }';
- $url = "https://api.weixin.qq.com/cgi-bin/menu/create?access_token=" . $access_token;
- return $this->curlPost($data, $url);
- }
- public function curlPost($data, $url)
- {
- //var_dump($data);
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_URL, $url);
- curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
- curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
- curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (compatible; MSIE 5.01; Windows NT 5.0)');
- // curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
- curl_setopt($ch, CURLOPT_AUTOREFERER, 1);
- curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
- $tmpInfo = curl_exec($ch);
- if (curl_errno($ch)) {
- return curl_error($ch) ;
- }
- curl_close($ch);
- return $tmpInfo;
- }
- public function getMsg()
- {
- $postStr = $GLOBALS["HTTP_RAW_POST_DATA"];
- if (!empty($postStr)) {
- $this->msg = (array)simplexml_load_string($postStr, 'SimpleXMLElement', LIBXML_NOCDATA);
- $this->msgtype = strtolower($this->msg['MsgType']);
- }
- }
- public function makeText($text='')
- {
- $CreateTime = time();
- $FuncFlag = $this->setFlag ? 1 : 0;
- $textTpl = "<xml>
- <ToUserName><![CDATA[{$this->msg['FromUserName']}]]></ToUserName>
- <FromUserName><![CDATA[{$this->msg['ToUserName']}]]></FromUserName>
- <CreateTime>{$CreateTime}</CreateTime>
- <MsgType><![CDATA[text]]></MsgType>
- <Content><![CDATA[%s]]></Content>
- <FuncFlag>%s</FuncFlag>
- </xml>";
- return sprintf($textTpl,$text,$FuncFlag);
- }
- public function makeTextPic($arr)
- {
- $CreateTime = time();
- $len = count($arr);
- $textTpl = "<xml><ToUserName><![CDATA[{$this->msg['FromUserName']}]]></ToUserName><FromUserName><![CDATA[{$this->msg['ToUserName']}]]></FromUserName><CreateTime>{$CreateTime}</CreateTime><MsgType><![CDATA[news]]></MsgType><ArticleCount>{$len}</ArticleCount><Articles>";
- $itemTpl = "<item><Title><![CDATA[%s]]></Title><Description><![CDATA[%s]]></Description><PicUrl><![CDATA[%s]]></PicUrl><Url><![CDATA[%s]]></Url></item>";
- foreach ($arr as $item)
- {
- $textTpl .= sprintf($itemTpl,$item["title"],$item["description"],$item["picUrl"],$item["url"]);
- }
- $textTpl .= "</Articles></xml>";
- return $textTpl;
- }
- public function reply($data)
- {
- echo $data;
- }
- //客服消息
- public function messageToUserName($content,$fromUsername)//content 就是回复的消息,$fromUsername就是openid
- {
- //这里要获取token
- $access_token = $this->getAccessToken();
- $data = '{
- "touser":"'.$fromUsername.'",
- "msgtype":"text",
- "text":
- {
- "content":"'.$content.'"
- }
- }';
- $url = "https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token=".$access_token;
- $result = $this->curlPost($data,$url);
- $final = json_decode($result);
- return $final;
- }
- public function getSignPackage() {
- $jsapiTicket = $this->getJsTicket();
- $conf = $this->_conf();
- // 注意 URL 一定要动态获取,不能 hardcode.
- $protocol = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' || $_SERVER['SERVER_PORT'] == 443) ? "https://" : "http://";
- $url = "$protocol$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
- $nonceStr = $this->createNonceStr();
- $timestamp = time();
- // 这里参数的顺序要按照 key 值 ASCII 码升序排序
- $string = "jsapi_ticket=$jsapiTicket&noncestr=$nonceStr×tamp=$timestamp&url=$url";
- $signature = sha1($string);
- $signPackage = array(
- "appId" => $conf["appid"],
- "nonceStr" => $nonceStr,
- "timestamp" => $timestamp,
- "url" => $url,
- "signature" => $signature,
- "rawString" => $string
- );
- return $signPackage;
- }
- //url示例 “weixinHtml/new_repaire.html”
- public function getSignPackageByURL($url = '') {
- $jsapiTicket = $this->getJsTicket();
- $conf = $this->_conf();
- // 注意 URL 一定要动态获取,不能 hardcode.
- $protocol = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' || $_SERVER['SERVER_PORT'] == 443) ? "https://" : "http://";
- $url = "$protocol$_SERVER[HTTP_HOST]/".trim($url);
- $nonceStr = $this->createNonceStr();
- $timestamp = time();
- // 这里参数的顺序要按照 key 值 ASCII 码升序排序
- $string = "jsapi_ticket=$jsapiTicket&noncestr=$nonceStr×tamp=$timestamp&url=$url";
- $signature = sha1($string);
- $signPackage = array(
- "appId" => $conf["appid"],
- "nonceStr" => $nonceStr,
- "timestamp" => $timestamp,
- "url" => $url,
- "signature" => $signature,
- "rawString" => $string
- );
- return $signPackage;
- }
- private function createNonceStr($length = 16) {
- $chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
- $str = "";
- for ($i = 0; $i < $length; $i++) {
- $str .= substr($chars, mt_rand(0, strlen($chars) - 1), 1);
- }
- return $str;
- }
- public function downLoadFile($serverId,$foldername){
- $access_token = $this->getAccessToken();
- $url = "https://api.weixin.qq.com/cgi-bin/media/get?access_token=".$access_token."&media_id=".$serverId;
- if (!file_exists($foldername)) {
- mkdir($foldername, 0777, true);
- }
- $targetName = date('YmdHis').rand(1000,9999).'.jpg';
- $targetPathName = $foldername.$targetName;
- //获取微信“获取临时素材”接口返回来的内容(即刚上传的图片)
- $a = file_get_contents($url);
- //以读写方式打开一个文件,若没有,则自动创建
- $resource = fopen($targetPathName , 'w+');
- //将图片内容写入上述新建的文件
- fwrite($resource, $a);
- //关闭资源
- fclose($resource);
- return $targetName;
- }
- public function downLoadFiles($serverId,$foldername,$access_token){
- //用于下载师傅端上传的图片到后台
- $url = "https://api.weixin.qq.com/cgi-bin/media/get?access_token=".$access_token."&media_id=".$serverId;
- if (!file_exists($foldername)) {
- mkdir($foldername, 0777, true);
- }
- $targetName = date('YmdHis').rand(1000,9999).'.jpg';
- $targetPathName = $foldername.$targetName;
- //获取微信“获取临时素材”接口返回来的内容(即刚上传的图片)
- $a = file_get_contents($url);
- //以读写方式打开一个文件,若没有,则自动创建
- $resource = fopen($targetPathName , 'w+');
- //将图片内容写入上述新建的文件
- fwrite($resource, $a);
- //关闭资源
- fclose($resource);
- return $targetName;
- }
- public function sendImageToUser($openId,$mediaId)
- {
- $acccess_token = $this->getAccessToken();
- $url="https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token={$acccess_token}";
- $sendData=' {
- "touser":"'.$openId.'",
- "msgtype":"image",
- "image":
- {
- "media_id":"'.$mediaId.'"
- }
- }';
- return $this->curlPost($sendData,$url);
- }
- public function sendMsgToUser($openId,$content)
- {
- $acccess_token = $this->getAccessToken();
- $url="https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token={$acccess_token}";
- $sendData='{
- "touser": "'.$openId.'",
- "msgtype": "text",
- "text": {
- "content": "'.$content.'"
- }
- }';
- return $this->curlPost($sendData,$url);
- }
- public function getJsTicket(){ // 只允许本类调用,继承的都不可以调用,公开调用就更不可以了
- $rs = Baseconfig::getInfoByKey(self::JS_TICKET_KEY);
- if(empty($rs)||(time()-$rs["lastupdate"])>self::LimitTime)
- {
- $jsticket = self::refreshJsTicket();
- }
- else
- {
- $jsticket = $rs["value"];
- }
- return $jsticket ;
- }
- public function refreshJsTicket()
- {
- $access_token = $this->getAccessToken();
- $url = "https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token=".$access_token."&type=jsapi"; // 两小时有效
- $rurl = file_get_contents($url);
- $rurl = json_decode($rurl,true);
- if($rurl['errcode'] != 0){
- return false;
- }else{
- $jsticket = $rurl['ticket'];
- $rs = Baseconfig::getInfoByKey(self::JS_TICKET_KEY);
- if($rs)
- {
- $res = Baseconfig::update($rs["id"],array("value"=>$jsticket,"lastupdate"=>time()));
- }
- else
- {
- $res = Baseconfig::add(self::JS_TICKET_KEY,$jsticket,"微信开发js_ticket");
- }
- if($res)
- {
- return $jsticket;
- }
- }
- }
- /**
- *
- * 获取支付结果通知数据
- * return array
- */
- public function getNotifyData(){
- //获取通知的数据
- $xml = $GLOBALS['HTTP_RAW_POST_DATA'];
- $data = array();
- if( empty($xml) ){
- return false;
- }
- $data = self::xml_to_data( $xml );
- if( !empty($data['return_code']) ){
- if( $data['return_code'] == 'FAIL' ){
- return false;
- }
- }
- return $data;
- }
- /**
- * 将xml转为array
- * @param string $xml
- * return array
- */
- public function xml_to_data($xml){
- if(!$xml){
- return false;
- }
- //将XML转为array
- //禁止引用外部xml实体
- libxml_disable_entity_loader(true);
- $data = json_decode(json_encode(simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOCDATA)), true);
- return $data;
- }
- /**
- * 用户隐秘授权
- * @param $redirectUrl
- * @return string
- */
- function login_url($redirectUrl)
- {
- $conf = $this->_conf();
- $params = array(
- 'appid' => $conf["appid"],
- 'redirect_uri' => $redirectUrl,
- 'response_type' => 'code',
- 'scope' => self::SCOPE_USERINFO,
- 'state' => time(),
- );
- return 'https://open.weixin.qq.com/connect/oauth2/authorize?' . http_build_query($params) . '#wechat_redirect';
- }
- public static function savePicToServer($url,$fileName) {
- // 要存在你服务器哪个位置?
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
- $fp = fopen($fileName,'wb');
- curl_setopt($ch,CURLOPT_URL,$url);
- curl_setopt($ch,CURLOPT_FILE,$fp);
- curl_setopt($ch,CURLOPT_HEADER,0);
- curl_exec($ch);
- curl_close($ch);
- fclose($fp);
- }
- public function _conf()
- {
- $arr = Baseconfig::getInfoByArr(array(Baseconfig::CFG_WEIXIN_APPID,Baseconfig::CFG_WEIXIN_APPKEY));
- $info = array();
- foreach ($arr as $v)
- {
- if ($v['key'] == Baseconfig::CFG_WEIXIN_APPID)
- {
- $info['appid'] = $v['value'];
- }
- if ($v['key'] == Baseconfig::CFG_WEIXIN_APPKEY)
- {
- $info['appkey'] = $v['value'];
- }
- }
- return $info;
- }
- public function sendMsgToUserHaveUrl($openid,$text)
- {
- $ToUserName = Baseconfig::getInfoByKey(Baseconfig::CFG_WEIXIN_APPID)['value'];
- $CreateTime = time();
- $textTpl = "<xml>
- <ToUserName><![CDATA[$ToUserName}]]></ToUserName>
- <FromUserName><![CDATA[{$openid}]]></FromUserName>
- <CreateTime>{$CreateTime}</CreateTime>
- <MsgType><![CDATA[text]]></MsgType>
- <Content><![CDATA[%s]]></Content>
- </xml>";
- return sprintf($textTpl,$text);
- }
- public function get_template(){
- $acccess_token = $this->getAccessToken();
- $url = "https://api.weixin.qq.com/cgi-bin/template/get_all_private_template?access_token=".$acccess_token;
- $sendData='';
- $res = $this->curlPost($sendData,$url);
- return json_decode($res, true);
- }
- //推送用户下单时的订单,客服推送
- public function send_user_by_template($dataUrl,$openid,$dataInfo,$template_id) { //发送$kf_template_id模板消息
- $acccess_token = $this->getAccessToken();
- $url = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token={$acccess_token}";
- $data =' {
- "touser":"'.$openid.'",
- "template_id":"'.$template_id.'",
- "url":"'.$dataUrl.'",
- "data":{
- "first": {
- "value":"您收到一个新的预约订单,请及时处理",
- "color":"#173177"
- },
- "keyword1":{
- "value": "'.$dataInfo['type'].'"
- },
- "keyword2": {
- "value":"'.$dataInfo['register_person'].'"
- },
- "keyword3": {
- "value":"'.$dataInfo['link_phone'].'"
- },
- "keyword4": {
- "value":"'.$dataInfo['register_phone'].'"
- },
- "keyword5": {
- "value":"'.$dataInfo['address'].'"
- },
- "remark":{
- "value":"点击查看订单详情",
- "color":"#173177"
- }
- }
- }';
- $result = $this->curlPost($data , $url);
- // $result = $this->send_post( $url, $data);
- return $result;
- }
- //发放的优惠劵推送
- public function send_coupon_by_template($dataUrl,$openid,$dataInfo,$template_id) { //发送模板消息
- $acccess_token = $this->getAccessToken();
- $url = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token={$acccess_token}";
- $data =' {
- "touser":"'.$openid.'",
- "template_id":"'.$template_id.'",
- "url":"'.$dataUrl.'",
- "data":{
- "first": {
- "value":"您收到了由“小元服务”为您发放的优惠券",
- "color":"#173177"
- },
- "keyword1":{
- "value": "'.$dataInfo['type'].'"
- },
- "keyword2": {
- "value":"'.$dataInfo['time'].'"
- },
-
- "remark":{
- "value":"点击查看优惠券",
- "color":"#173177"
- }
- }
- }';
- $result = $this->curlPost($data , $url);
- return $result;
- }
- //推送客户端派单消息的模板函数
- //user sxx
- public function send_coupon_by_templates($dataUrl,$openid,$dataInfo,$template_id) {
- $acccess_token = $this->getAccessToken();
- $url = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token={$acccess_token}";
- $data =' {
- "touser":"'.$openid.'",
- "template_id":"'.$template_id.'",
- "url":"'.$dataUrl.'",
- "data":{
- "first": {
- "value":"您已成功预约",
- "color":"#173177"
- },
- "keyword1":{
- "value": "'.$dataInfo['type'].'"
- },
- "keyword2": {
- "value":"'.$dataInfo['time'].'"
- },
-
- "remark":{
- "value":"点击查看详情",
- "color":"#173177"
- }
- }
- }';
- $result = $this->curlPost($data , $url);
- return $result;
- }
- //推送客户端已接单消息的模板函数
- //user sxx
- public function send_coupon_by_templatess($dataUrl,$openid,$dataInfo,$template_id) {
- $acccess_token = $this->getAccessToken();
- $url = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token={$acccess_token}";
- $data =' {
- "touser":"'.$openid.'",
- "template_id":"'.$template_id.'",
- "url":"'.$dataUrl.'",
- "data":{
- "first": {
- "value":"维修师傅已接单,请保持电话畅通",
- "color":"#173177"
- },
- "keyword1":{
- "value": "'.$dataInfo['name'].'"
- },
- "keyword2": {
- "value":"'.$dataInfo['linkphone'].'"
- },
- "keyword3": {
- "value":"'.$dataInfo['type'].'"
- },
- "keyword4": {
- "value":"'.$dataInfo['time'].'"
- },
-
- "remark":{
- "value":"点击查看详情",
- "color":"#173177"
- }
- }
- }';
- $result = $this->curlPost($data , $url);
- return $result;
- }
- //推送客户端待支付消息的模板函数
- //user sxx
- public function send_coupon_by_pay($dataUrl,$openid,$dataInfo,$template_id) {
- $acccess_token = $this->getAccessToken();
- $url = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token={$acccess_token}";
- $data =' {
- "touser":"'.$openid.'",
- "template_id":"'.$template_id.'",
- "url":"'.$dataUrl.'",
- "data":{
- "first": {
- "value":"您预约的订单已经维修完成,请您尽快支付",
- "color":"#173177"
- },
- "keyword1":{
- "value": "'.$dataInfo['time'].'"
- },
- "keyword2": {
- "value":"服务费'.$dataInfo['money1'].',配件售价'.$dataInfo['money2'].',共计'.$dataInfo['money3'].'"
- },
- "keyword3": {
- "value":"'.$dataInfo['name'].'"
- },
-
- "remark":{
- "value":"点击查看详情",
- "color":"#173177"
- }
- }
- }';
- $result = $this->curlPost($data , $url);
- return $result;
- }
- //推送客户端支付成功消息的模板函数(报修故障过保/其他类型)
- //user sxx
- public function send_coupon_by_finsh1($dataUrl,$openid,$dataInfo,$template_id) {
- $acccess_token = $this->getAccessToken();
- $url = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token={$acccess_token}";
- $data =' {
- "touser":"'.$openid.'",
- "template_id":"'.$template_id.'",
- "url":"'.$dataUrl.'",
- "data":{
- "first": {
- "value":"您好,您本次服务已完成。",
- "color":"#173177"
- },
- "keyword1":{
- "value": "'.$dataInfo['type'].'"
- },
- "keyword2": {
- "value": "'.$dataInfo['money3'].'"
- },
-
- "remark":{
- "value":"查看订单详情",
- "color":"#173177"
- }
- }
- }';
- $result = $this->curlPost($data , $url);
- return $result;
- }
- //推送客户端支付成功消息的模板函数(报修故障(保质期内))
- //user sxx
- public function send_coupon_by_finsh2($dataUrl,$openid,$dataInfo,$template_id) {
- $acccess_token = $this->getAccessToken();
- $url = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token={$acccess_token}";
- $data =' {
- "touser":"'.$openid.'",
- "template_id":"'.$template_id.'",
- "url":"'.$dataUrl.'",
- "data":{
- "first": {
- "value":"您好,您本次服务已完成。",
- "color":"#173177"
- },
- "keyword1":{
- "value": "'.$dataInfo['type'].'"
- },
- "keyword2": {
- "value":"0元(保质期内不收取任何费用)"
- },
-
- "remark":{
- "value":"查看订单详情",
- "color":"#173177"
- }
- }
- }';
- $result = $this->curlPost($data , $url);
- return $result;
- }
- //推送客户端支付成功消息的模板函数(报修故障过保/其他类型(现金支付))
- //user sxx
- public function send_coupon_by_finsh3($dataUrl,$openid,$dataInfo,$template_id) {
- $acccess_token = $this->getAccessToken();
- $url = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token={$acccess_token}";
- $data =' {
- "touser":"'.$openid.'",
- "template_id":"'.$template_id.'",
- "url":"'.$dataUrl.'",
- "data":{
- "first": {
- "value":"您好,您本次服务已完成。",
- "color":"#173177"
- },
- "keyword1":{
- "value": "'.$dataInfo['type'].'"
- },
- "keyword2": {
- "value":"'.$dataInfo['money3'].'(现金支付)"
- },
-
- "remark":{
- "value":"查看订单详情",
- "color":"#173177"
- }
- }
- }';
- $result = $this->curlPost($data , $url);
- return $result;
- }
- //推送给密语客服的申请重派提醒
- //user sxx
- public function send_custom_by_template($dataUrl,$openid,$dataInfo,$template_id) {
- $acccess_token = $this->getAccessToken();
- $url = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token={$acccess_token}";
- $data =' {
- "touser":"'.$openid.'",
- "template_id":"'.$template_id.'",
- "url":"'.$dataUrl.'",
- "data":{
- "first": {
- "value":"'.$dataInfo['name'].'申请重派,请及时处理",
- "color":"#173177"
- },
- "keyword1":{
- "value": "'.$dataInfo['type'].'"
- },
- "keyword2": {
- "value":"'.$dataInfo['time'].'"
- },
-
- "remark":{
- "value":"点击查看详情",
- "color":"#173177"
- }
- }
- }';
- $result = $this->curlPost($data , $url);
- return $result;
- }
- // //推送客户端在保支付成功消息的模板函数
- // //user sxx
- // public function send_coupon_by_finshs($dataUrl,$openid,$dataInfo,$template_id) {
- // $acccess_token = $this->getAccessToken();
- //
- // $url = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token={$acccess_token}";
- //
- // $data =' {
- // "touser":"'.$openid.'",
- // "template_id":"'.$template_id.'",
- // "url":"'.$dataUrl.'",
- // "data":{
- // "first": {
- // "value":"您预约的'.$dataInfo['type'].'",
- // "color":"#173177"
- // },
- // "keyword1":{
- // "value": "'.$dataInfo['type'].'"
- // },
- // "keyword2": {
- // "value":"'.$dataInfo['time'].'"
- // },
- //
- // "remark":{
- // "value":"点击去评价",
- // "color":"#173177"
- // }
- // }
- // }';
- //
- // $result = $this->curlPost($data , $url);
- // return $result;
- // }
- // //推送师傅端待接单消息的模板函数
- // //user sxx
- // public function send_coupon_by_teacher($dataUrl,$openid,$dataInfo,$template_id) {
- // $acccess_token = $this->getAccessToken();
- //
- // $url = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token={$acccess_token}";
- // $data =' {
- // "touser":"'.$openid.'",
- // "template_id":"'.$template_id.'",
- // "url":"'.$dataUrl.'",
- // "data":{
- // "first": {
- // "value":"您有新的订单,请尽快接单",
- // "color":"#173177"
- // },
- // "keyword1":{
- // "value": "'.$dataInfo['time'].'"
- // },
- // "keyword2": {
- // "value":"'.$dataInfo['type'].'"
- // },
- //
- // "remark":{
- // "value":"点击查看详情",
- // "color":"#173177"
- // }
- // }
- // }';
- //
- // $result = $this->curlPost($data , $url);
- // return $result;
- // }
- //
- // //推送师傅端已支付消息的模板函数
- // //user sxx
- // public function send_coupon_by_pays($dataUrl,$openid,$dataInfo,$template_id) {
- // $acccess_token = $this->getAccessToken();
- //
- // $url = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token={$acccess_token}";
- // $data =' {
- // "touser":"'.$openid.'",
- // "template_id":"'.$template_id.'",
- // "url":"'.$dataUrl.'",
- // "data":{
- // "first": {
- // "value":"用户已经付款",
- // "color":"#173177"
- // },
- // "keyword1":{
- // "value": "'.$dataInfo['name'].'"
- // },
- // "keyword2": {
- // "value":"'.$dataInfo['style'].'"
- // },
- // "keyword3": {
- // "value":"'.$dataInfo['money'].'"
- // },
- // "keyword4": {
- // "value":"'.$dataInfo['address'].'"
- // },
- // "keyword5": {
- // "value":"'.$dataInfo['time'].'"
- // },
- //
- // "remark":{
- // "value":"点击查看详情",
- // "color":"#173177"
- // }
- // }
- // }';
- //
- // $result = $this->curlPost($data , $url);
- // return $result;
- // }
- public function send_post( $url, $post_data )
- {
- $options = array(
- 'http' => array(
- 'method' => 'POST',
- 'header' => 'Content-type:application/json;charset=utf-8',
- //header 需要设置为 JSON
- 'content' => $post_data,
- 'timeout' => 60
- //超时时间
- )
- );
- $context = stream_context_create($options);
- $result = file_get_contents($url, false, $context);
- return $result;
- }
- }
|