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 '发送成功';
        }
    }
}
function weixin_robot_create_qrcode($scene, $name, $type = 'QR_LIMIT_SCENE', $expire = '1200')
{
    global $wpdb;
    $post = array();
    if ($type == 'QR_SCENE') {
        $post['expire_seconds'] = $expire;
    }
    $post['action_name'] = $type;
    $post['action_info'] = array('scene' => array('scene_id' => $scene));
    $weixin_robot_access_token = weixin_robot_get_access_token();
    $url = 'https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token=' . $weixin_robot_access_token;
    $response = wp_remote_post($url, array('body' => json_encode($post), 'sslverify' => false));
    if (is_wp_error($response)) {
        echo $response->get_error_code() . ':' . $response->get_error_message();
        return false;
    } else {
        $result = json_decode($response['body']);
        $data = array('scene' => $scene, 'name' => $name, 'type' => $type, 'ticket' => $result->ticket);
        if ($type == 'QR_SCENE') {
            $data['expire'] = time() + $result->expire_seconds;
        }
        if (weixin_robot_get_qrcode($scene)) {
            $wpdb->update($wpdb->weixin_qrcodes, $data, array('scene' => $scene));
        } else {
            $wpdb->insert($wpdb->weixin_qrcodes, $data);
        }
        return $data;
    }
}
function weixin_robot_post_custom_menus($message, $weixin_robot_custom_menus)
{
    if (weixin_robot_get_setting('weixin_app_id') && weixin_robot_get_setting('weixin_app_secret')) {
        $weixin_robot_access_token = weixin_robot_get_access_token();
        if ($weixin_robot_access_token) {
            //$url = 'http://wpjam.net/api/weixin.php?action=create_menu&access_token='.$weixin_robot_access_token.'&domain='.wpjam_net_get_domain();
            $url = 'https://api.weixin.qq.com/cgi-bin/menu/create?access_token=' . $weixin_robot_access_token;
            $request = weixin_robot_create_buttons_request($weixin_robot_custom_menus);
            $result = weixin_robot_post_custom_menus_core($url, urldecode(json_encode($request)));
            $message = $message ? $message . '<br />' : $message;
            return $message . '微信:' . $result;
        }
    }
    return $message;
}