leaguepush(); // $this->leaguepush(array('title'=>'俱乐部邀请通知','username'=>'张三','type'=>'类型1'),'otmyT6mZXtSbPY0g22jSoSiRUc6o'); // $this->weishoupushs(array('order_sn'=>'2342342342','order_amount'=>11,'paid_time'=>date('Y-m-d H:i:s'))); } public function leaguepush($add_data,$openid) { $appid = 'wxae874d12ca3f56b8';//公众号的appid $secret = '0984255faae9d7c0c8a9926aa396d22b'; // 获取token $token = $this->getAccToken($appid,$secret); // var_dump($token);exit; // file_put_contents(__DIR__."tztoken.txt",json_encode($token)); $url = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=".$token; $data = [ "touser"=>$openid, "appid"=>"wxae874d12ca3f56b8",//公众号 "template_id"=>"GQwDq5V_xM3wRfTOAHOfFrOLwKahJwRRCp4KWBla3FM",//模板id "url"=>"https://www.fpvone.cn/index/user/login.html", "data"=>[ 'thing6' => array( 'value'=> $add_data['title'], ), 'thing3'=>array( 'value'=> $add_data['username'], ), 'thing19'=>array( 'value'=> $add_data['type'], ), ], ]; return $this->httpUtil($url,json_encode($data),'POST'); //发送请求 } public function getAccToken($appid,$secret){ $token_url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid={$appid}&secret={$secret}"; $token_res = $this->httpUtil($token_url); $token_res = json_decode($token_res, true); $token = $token_res['access_token']; return $token; } public function httpUtil($url, $data = '', $method = 'GET'){ try { // file_put_contents(__DIR__."tzaaa.txt",$url); $curl = curl_init(); // 启动一个CURL会话 curl_setopt($curl, CURLOPT_URL, $url); // 要访问的地址 curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); // 对认证证书来源的检查 curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); // 从证书中检查SSL加密算法是否存在 // curl_setopt($curl, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']); // 模拟用户使用的浏览器 curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1); // 使用自动跳转 curl_setopt($curl, CURLOPT_AUTOREFERER, 1); // 自动设置Referer // file_put_contents(__DIR__."tzeee.txt",json_encode($_SERVER['HTTP_USER_AGENT'])); if ($method == 'POST') { curl_setopt($curl, CURLOPT_POST, 1); // 发送一个常规的Post请求 if ($data != '') { curl_setopt($curl, CURLOPT_POSTFIELDS, $data); // Post提交的数据包 } } // file_put_contents(__DIR__."tzddd.txt",000); curl_setopt($curl, CURLOPT_TIMEOUT, 30); // 设置超时限制防止死循环 curl_setopt($curl, CURLOPT_HEADER, 0); // 显示返回的Header区域内容 curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); // 获取的信息以文件流的形式返回 $tmpInfo = curl_exec($curl); // 执行操作 // file_put_contents(__DIR__."tzfff.txt",000); curl_close($curl); // 关闭CURL会话 return $tmpInfo; // 返回数据 } catch (Exception $e) { // file_put_contents(__DIR__."tzbbb.txt",json_encode($e->getMessage())); return $e->getMessage(); } } public function weishoupushs($order) { // file_put_contents(__DIR__."tztem.txt",json_encode($order['order_sn'])); $appid = 'wxae874d12ca3f56b8';//公众号的appid $secret = '0984255faae9d7c0c8a9926aa396d22b'; // 获取token $token = $this->getAccToken($appid,$secret); // file_put_contents(__DIR__."tztoken.txt",json_encode($token)); //$url = "https://api.weixin.qq.com/cgi-bin/message/wxopen/template/uniform_send?access_token=".$token; $url = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=".$token; $thirdOauth = new ThirdOauth(); $admin = $thirdOauth->where('admin_id',7)->find(); if(!empty($admin)) {$admin = $admin->toArray();} else{ $admin['openid'] = 'otmyT6mZXtSbPY0g22jSoSiRUc6o'; } // var_dump($admin['openid']);exit; $data = [ "touser"=>$admin['openid'], "appid"=>"wxae874d12ca3f56b8",//公众号 //"template_id"=>"nVfy1Tz1EXQ3T2YcGkwgicAjrD0M3N1Ca-CHIJCwjQY",//模板id "template_id"=>"t-UC5eLA8R5f7NHKnH39oLxYlOHS5mvu6BeaNUgJx_8",//模板id "url"=>"https://shop.fpvone.cn", // "miniprogram"=>[ // "appid"=>"wx18aa***",//小程序 // //"pagepath"=>"/pagesIndex/house/billingDetails?type=3&house_user_id=" . $house_user_id . "&house_code_id=" . $house_code_id//pagesIndex/house/billingDetails 未收账单路径 index?foo=bar // "pagepath"=>"/pagesIndex/house/billingDetails?type=3&id=" . $data['house_user_id'] . "&ids=" . $data['house_code_id']//pagesIndex/house/billingDetails 未收账单路径 index?foo=bar // ], "data"=>[ 'character_string1' => array( 'value'=>$order['order_sn'], ), 'amount3'=>array( 'value'=>$order['order_amount'], ), 'time9'=>array( 'value'=>$order['paid_time'], // 'value'=>date('Y-m-d H:i:s'), ), ], ]; // file_put_contents(__DIR__."tztem1.txt",json_encode($data)); return $this->httpUtil($url,json_encode($data),'POST'); //发送请求 } public function tuikuanpush($order) { $appid = 'wxae874d12ca3f56b8';//公众号的appid $secret = '0984255faae9d7c0c8a9926aa396d22b'; // 获取token $token = $this->getAccToken($appid,$secret); // var_dump($order['order_sn']);exit; // file_put_contents(__DIR__."tztoken.txt",json_encode($token)); $url = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=".$token; $thirdOauth = new ThirdOauth(); $admin = $thirdOauth->where('admin_id',7)->find(); if(!empty($admin)) {$admin = $admin->toArray();} else{ $admin['openid'] = 'otmyT6mZXtSbPY0g22jSoSiRUc6o'; } // var_dump($admin);exit; $data = [ "touser"=>$admin['openid'], "appid"=>"wxae874d12ca3f56b8",//公众号 //"template_id"=>"nVfy1Tz1EXQ3T2YcGkwgicAjrD0M3N1Ca-CHIJCwjQY",//模板id "template_id"=>"dz0Dg4k1O3tjPQEnGyoOP_wSbKDIQr0tlaVULac9NiQ",//模板id "url"=>"https://shop.fpvone.cn", "data"=>[ 'character_string12' => array( 'value'=>$order['order_sn'], ), 'amount4'=>array( 'value'=>$order['order_amount'], ), 'time3'=>array( 'value'=>$order['updatetime'], // 'value'=>date('Y-m-d H:i:s'), ), ], ]; return $this->httpUtil($url,json_encode($data),'POST'); //发送请求 } public function renzhengpush($add_data,$openid) { $appid = 'wxae874d12ca3f56b8';//公众号的appid $secret = '0984255faae9d7c0c8a9926aa396d22b'; // 获取token $token = $this->getAccToken($appid,$secret); // var_dump($token);exit; // file_put_contents(__DIR__."tztoken.txt",json_encode($token)); $url = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=".$token; // $thirdOauth = new ThirdOauth(); // $admin = $thirdOauth->where('admin_id',7)->find(); // if(!empty($admin)) {$admin = $admin->toArray();} // else{ // $admin['openid'] = 'otmyT6mZXtSbPY0g22jSoSiRUc6o'; // } // var_dump($admin);exit; $data = [ "touser"=>$openid, "appid"=>"wxae874d12ca3f56b8",//公众号 //"template_id"=>"nVfy1Tz1EXQ3T2YcGkwgicAjrD0M3N1Ca-CHIJCwjQY",//模板id "template_id"=>"u3sFFtaYZRiqq2S1h6ODsRl30_n0cJnftizBe1nOFVA",//模板id // "url"=>"https://shop.fpvone.cn", "data"=>[ 'thing1' => array( 'value'=>$add_data['real_name'], ), // 'phone_number2'=>array( // 'value'=>456, // ), 'time4'=>array( 'value'=>date('Y-m-d H:i:s'), // 'value'=>date('Y-m-d H:i:s'), ), ], ]; return $this->httpUtil($url,json_encode($data),'POST'); //发送请求 } public function clubpush($add_data,$openid) { $appid = 'wxae874d12ca3f56b8';//公众号的appid $secret = '0984255faae9d7c0c8a9926aa396d22b'; // 获取token $token = $this->getAccToken($appid,$secret); // var_dump($token);exit; // file_put_contents(__DIR__."tztoken.txt",json_encode($token)); $url = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=".$token; // $thirdOauth = new ThirdOauth(); // $admin = $thirdOauth->where('admin_id',7)->find(); // if(!empty($admin)) {$admin = $admin->toArray();} // else{ // $admin['openid'] = 'otmyT6mZXtSbPY0g22jSoSiRUc6o'; // } // var_dump($admin);exit; $data = [ "touser"=>$openid, "appid"=>"wxae874d12ca3f56b8",//公众号 //"template_id"=>"nVfy1Tz1EXQ3T2YcGkwgicAjrD0M3N1Ca-CHIJCwjQY",//模板id "template_id"=>"u3sFFtaYZRiqq2S1h6ODsRl30_n0cJnftizBe1nOFVA",//模板id // "url"=>"https://shop.fpvone.cn", "data"=>[ 'thing1' => array( 'value'=> $add_data['name_short'], ), // 'phone_number2'=>array( // 'value'=>456, // ), 'time4'=>array( 'value'=>date('Y-m-d H:i:s'), // 'value'=>date('Y-m-d H:i:s'), ), ], ]; return $this->httpUtil($url,json_encode($data),'POST'); //发送请求 } }