function weixin_robot_init($wp) { // 定义数据库表名 global $wpdb; $wpdb->weixin_messages = $wpdb->prefix . 'weixin_messages'; if (isset($_GET['yixin'])) { $wpdb->weixin_messages = $wpdb->prefix . 'yixin_messages'; } $wpdb->weixin_custom_replies = $wpdb->prefix . 'weixin_custom_replies'; $wpdb->weixin_qrcodes = $wpdb->prefix . 'weixin_qrcodes'; $wpdb->weixin_users = $wpdb->prefix . 'weixin_users'; $wpdb->weixin_credits = $wpdb->prefix . 'weixin_credits'; $wpdb->weixin_checkin = $wpdb->prefix . 'weixin_checkin'; $wpdb->weixin_redeems = $wpdb->prefix . 'weixin_redeems'; $wpdb->weixin_redeem_codes = $wpdb->prefix . 'weixin_redeem_codes'; $wpdb->weixin_postviews = $wpdb->prefix . 'weixin_postviews'; // 被动响应微信用户消息 if (isset($_GET['weixin']) || isset($_GET['yixin']) || isset($_GET['signature'])) { global $wechatObj; if (!isset($wechatObj)) { $wechatObj = new wechatCallback(); $wechatObj->valid(); exit; } } // 将用户的 query_id 保存到 cookie 里面 $query_key = weixin_robot_get_user_query_key(); if (!empty($_GET[$query_key])) { weixin_robot_set_query_cookie($_GET[$query_key]); } // 微信用户中心 if (isset($_GET['weixin_user'])) { if (isset($_GET['profile'])) { if (file_exists(TEMPLATEPATH . '/weixin/weixin-user-profile.php')) { include TEMPLATEPATH . '/weixin/weixin-user-profile.php'; } else { include WEIXIN_ROBOT_PLUGIN_DIR . '/template/weixin-user-profile.php'; } exit; } } }
public function delete_menu($access_token) { $url = "https://api.weixin.qq.com/cgi-bin/menu/delete?access_token=" . $access_token; return file_get_contents($url); } //https请求(支持GET和POST) protected function https_request($url, $data = null) { $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, $url); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE); if (!empty($data)) { curl_setopt($curl, CURLOPT_POST, 1); curl_setopt($curl, CURLOPT_POSTFIELDS, $data); } curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); $output = curl_exec($curl); curl_close($curl); return $output; } } $wechatObj = new Server(); $wechatObj = new wechatCallback(); if (isset($_GET['echostr'])) { $wechatObj->valid(); } else { //$wechatObj->responseMsg(); $wechatObj->Run(); } //$wechatObj->Run();
<?php require_once 'init.inc.php'; // //微信验证 // define("TOKEN", "pilipili"); $wechatObj = new wechatCallback(); // $wechatObj->valid(); // //微信自动回复 $wechatObj->responseMsg(); class wechatCallback { public $fromUsername; public $time; public $keyword; private $appid = 'wxfb056bf940debab2'; private $appsecret = '99c8349844d47bd6c04102b27327732a'; private $istoolong = false; public function valid() { $echoStr = $_GET["echostr"]; //valid signature , option if ($this->checkSignature()) { echo $echoStr; exit; } } public function responseMsg() { //get post data, May be due to the different environments $postStr = $GLOBALS["HTTP_RAW_POST_DATA"]; //extract post data
<?php //提交认证的时候如果无法通过,可以使用该文件来验证通过。 $use_plugin = 1; if ($use_plugin) { include '../../../wp-load.php'; //file_put_contents(WP_CONTENT_DIR.'/uploads/weixin.log',var_export($_SERVER,true)); $wechatObj = new wechatCallback(); $wechatObj->valid(); exit; } else { define("TOKEN", "weixin"); class wechatCallbackapiTest { public function valid() { $echoStr = $_GET["echostr"]; //随机字符串 if ($this->checkSignature()) { echo $echoStr; exit; } } private function checkSignature() { $signature = $_GET["signature"]; $timestamp = $_GET["timestamp"]; $nonce = $_GET["nonce"]; $token = TOKEN; $tmpArr = array($token, $timestamp, $nonce); sort($tmpArr);