function weixin_rebot_sent_user($weixin_openid, $content, $reply_type = 'text')
{
    $weixin_robot_access_token = weixin_robot_get_access_token();
    $url = 'https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token=' . $weixin_robot_access_token;
    $request = array();
    $request['touser'] = $weixin_openid;
    if ($reply_type == 'text') {
        $request['msgtype'] = 'text';
        $request['text'] = array('content' => urlencode($content));
    } elseif ($reply_type == 'img') {
        $articles = $article = array();
        $img_reply_query = new WP_Query(array('post__in' => explode(',', $content), 'orderby' => 'post__in', 'post_type' => 'any'));
        if ($img_reply_query->have_posts()) {
            while ($img_reply_query->have_posts()) {
                $img_reply_query->the_post();
                $article['title'] = urlencode(apply_filters('weixin_title', get_the_title()));
                $article['description'] = urlencode(apply_filters('weixin_description', get_post_excerpt('', apply_filters('weixin_description_length', 150))));
                $article['url'] = urlencode(add_query_arg('weixin_openid', $weixin_openid, apply_filters('weixin_url', get_permalink())));
                if ($counter == 0) {
                    $article['picurl'] = get_post_weixin_thumb('', array(640, 320));
                } else {
                    $article['picurl'] = get_post_weixin_thumb('', array(80, 80));
                }
                $articles[] = $article;
            }
            $request['msgtype'] = 'news';
            $request['news'] = array('articles' => $articles);
        }
        wp_reset_query();
    } elseif ($reply_type == 'image') {
        $request['msgtype'] = 'image';
        $request['image'] = array('media_id' => urlencode($content));
    } elseif ($reply_type == 'voice') {
        $request['msgtype'] = 'voice';
        $request['voice'] = array('media_id' => urlencode($content));
    } elseif ($reply_type == 'video') {
        //$request['msgtype']	= 'video';
        //$request['video']	= array('media_id'=>urlencode($content),'title'=>'','description'=>'');
    } elseif ($reply_type == 'music') {
        //$request['msgtype']	= 'music';
        //$request['music']	= array('media_id'=>urlencode($content));
    }
    if (isset($request['msgtype']) && $request['msgtype']) {
        $response = wp_remote_post($url, array('body' => urldecode(json_encode($request)), 'sslverify' => false));
        if (is_wp_error($response)) {
            echo $response->get_error_code() . ':' . $response->get_error_message();
            exit;
        }
        $response = json_decode($response['body'], true);
        if ($response['errcode']) {
            return $response['errcode'] . ': ' . $response['errmsg'];
        } else {
            return '发送成功';
        }
    }
}
 public function query($keyword = '')
 {
     $weixin_count = weixin_robot_get_setting('weixin_count');
     // 获取除 page 和 attachmet 之外的所有日志类型
     $post_types = get_post_types(array('exclude_from_search' => false));
     unset($post_types['page']);
     unset($post_types['attachment']);
     $weixin_query_array = array('s' => $keyword, 'ignore_sticky_posts' => true, 'posts_per_page' => $weixin_count, 'post_status' => 'publish', 'post_type' => $post_types);
     $weixin_query_array = apply_filters('weixin_query', $weixin_query_array);
     if (empty($this->response)) {
         if (isset($weixin_query_array['s'])) {
             $this->response = 'query';
         } elseif (isset($weixin_query_array['cat'])) {
             $this->response = 'cat';
         } elseif (isset($weixin_query_array['tag_id'])) {
             $this->response = 'tag';
         }
     }
     global $wp_the_query;
     $wp_the_query->query($weixin_query_array);
     $items = '';
     $counter = 0;
     if ($wp_the_query->have_posts()) {
         while ($wp_the_query->have_posts()) {
             $wp_the_query->the_post();
             $title = apply_filters('weixin_title', get_the_title());
             $excerpt = apply_filters('weixin_description', get_post_excerpt('', apply_filters('weixin_description_length', 150)));
             $url = apply_filters('weixin_url', get_permalink());
             if ($counter == 0) {
                 $thumb = get_post_weixin_thumb('', array(640, 320));
             } else {
                 $thumb = get_post_weixin_thumb('', array(80, 80));
             }
             $items = $items . $this->get_item($title, $excerpt, $thumb, $url);
             $counter++;
         }
     }
     $articleCount = count($wp_the_query->posts);
     if ($articleCount > $weixin_count) {
         $articleCount = $weixin_count;
     }
     if ($articleCount) {
         echo sprintf($this->get_picTpl(), $articleCount, $items);
     } else {
         weixin_robot_not_found_reply($keyword);
     }
 }
function weixin_robot_enqueue_scripts()
{
    global $post;
    $img = apply_filters('weixin_share_img', get_post_weixin_thumb($post, array(120, 120)));
    $link = apply_filters('weixin_share_url', get_permalink());
    $title = apply_filters('weixin_share_title', get_the_title());
    $desc = apply_filters('weixin_share_desc', get_post_excerpt($post));
    $weixin_openid = weixin_robot_get_user_openid();
    wp_enqueue_script('jquery');
    wp_enqueue_script('weixin', WEIXIN_ROBOT_PLUGIN_URL . '/static/weixin-share.js', array('jquery'));
    wp_localize_script('weixin', 'weixin_data', array('appid' => '', 'fakeid' => '', 'img' => $img, 'link' => $link, 'title' => $title, 'desc' => $desc, 'credit' => $is_IIS ? 0 : weixin_robot_get_setting('weixin_credit'), 'ajax_url' => admin_url('admin-ajax.php'), 'nonce' => wp_create_nonce('weixin_share'), 'post_id' => get_the_ID(), 'weixin_openid' => $weixin_openid, 'notify' => weixin_robot_get_setting('weixin_share_notify')));
}