Open source wechat applet project based on "play android" open API

❤ the applet has been approved and is online!!! It's an instant experience.

Project source address, welcome star: https://github.com/mtjsoft/wanandroid

1. Applet Name: play Android

Based on the wechat applet version of play android completed by play android open API of Hongyang Daxin, let's learn about applet development.

2. Applet code:

3. Description of the completion of the applet:

For details of the current article, use the copy link to the clipboard. Because personal applets do not support opening external links. I am helpless. No way. There are too many restrictions on individual small programs. If you can, you should try to create an enterprise account to play! I am preparing to register a small program account of "individual business". After the registration is successful, I will try to add the external link of the article details.

4. Future plans

① After the small program account of "individual business" is registered, add the link of article details.

② , add the "to do" module provided by android's open API.

5. Applet interface




6. Applet online interface:

Since the app must only support https protocol for the domain name of the server, I forwarded the api data of playing android on my own server.

/**
 * Play android open api,
 * My server domain name address: https://www.mtjsoft.cn
 */
@RestController
@RequestMapping(value = "/wanandroid/api/")
public class WanAndroidApiController {

    /**========================================1.Home page related=================================================================**/
    /**
     * Homepage article list
     *
     * @param pagernumber Methods: GET
     *                    Parameters: page number, splicing in connection, starting from 0.
     * @return
     * @throws Exception
     */
    @GetMapping(value = "/article/list")
    public String indexList(@RequestParam(value = "pagernumber") int pagernumber) throws Exception {
        String url = "http://www.wanandroid.com/article/list/" + pagernumber + "/json";
        HttpMethod method = HttpMethod.GET;
        MultiValueMap<String, String> params = new LinkedMultiValueMap<String, String>();
        return HttpClient.init().client(url, method, params, null);
    }


    /**
     * Home page banner
     *
     * @return
     * @throws Exception
     */
    @GetMapping(value = "/banner")
    public String indexBanner() throws Exception {
        //url
        String url = "http://www.wanandroid.com/banner/json";
        //get request
        HttpMethod method = HttpMethod.GET;
        // Package parameters. Do not replace them with Map and HashMap, otherwise the parameters cannot be passed
        MultiValueMap<String, String> params = new LinkedMultiValueMap<String, String>();
        return HttpClient.init().client(url, method, params, null);
    }

    /**
     * Frequently used websites
     *
     * @return
     * @throws Exception
     */
    @GetMapping(value = "/friend")
    public String friend() throws Exception {
        //url
        String url = "http://www.wanandroid.com/friend/json";
        //get request
        HttpMethod method = HttpMethod.GET;
        // Package parameters. Do not replace them with Map and HashMap, otherwise the parameters cannot be passed
        MultiValueMap<String, String> params = new LinkedMultiValueMap<String, String>();
        return HttpClient.init().client(url, method, params, null);
    }

    /**
     * Search hot words
     *
     * @return
     * @throws Exception
     */
    @GetMapping(value = "/hotkey")
    public String hotkey() throws Exception {
        //url
        String url = "http://www.wanandroid.com/hotkey/json";
        //get request
        HttpMethod method = HttpMethod.GET;
        // Package parameters. Do not replace them with Map and HashMap, otherwise the parameters cannot be passed
        MultiValueMap<String, String> params = new LinkedMultiValueMap<String, String>();
        return HttpClient.init().client(url, method, params, null);
    }


    /**========================================2.System=================================================================**/

    /**
     * System data
     *
     * @return
     * @throws Exception
     */
    @GetMapping(value = "/tree")
    public String tree() throws Exception {
        //url
        String url = "http://www.wanandroid.com/tree/json";
        //get request
        HttpMethod method = HttpMethod.GET;
        // Package parameters. Do not replace them with Map and HashMap, otherwise the parameters cannot be passed
        MultiValueMap<String, String> params = new LinkedMultiValueMap<String, String>();
        return HttpClient.init().client(url, method, params, null);
    }

    /**
     * Articles under knowledge system
     *
     * @param pagernumber Methods: GET
     *                    Parameters:
     *                    cid id of classification, id of the above secondary directory
     *                    Page: spliced on the link, starting at 0.
     * @param cid
     * @return
     * @throws Exception
     */
    @GetMapping(value = "/tree/list")
    public String treeList(@RequestParam(value = "pagernumber") int pagernumber, @RequestParam(value = "cid") String cid) throws Exception {
        //url
        String url = "http://www.wanandroid.com/article/list/" + pagernumber + "/json?cid="+cid;
        //get request
        HttpMethod method = HttpMethod.GET;
        // Package parameters. Do not replace them with Map and HashMap, otherwise the parameters cannot be passed
        MultiValueMap<String, String> params = new LinkedMultiValueMap<String, String>();
        return HttpClient.init().client(url, method, params, null);
    }

    /**========================================3.Navigation=================================================================**/
    /**
     * Navigation data
     *
     * @return
     * @throws Exception
     */
    @GetMapping(value = "/navi")
    public String navi() throws Exception {

        //url
        String url = "http://www.wanandroid.com/navi/json";
        //get request
        HttpMethod method = HttpMethod.GET;
        // Package parameters. Do not replace them with Map and HashMap, otherwise the parameters cannot be passed
        MultiValueMap<String, String> params = new LinkedMultiValueMap<String, String>();
        return HttpClient.init().client(url, method, params, null);
    }

    /**========================================4.Project=================================================================**/
    /**
     * Project classification
     *
     * @return
     * @throws Exception
     */
    @GetMapping(value = "/project")
    public String project() throws Exception {
        //url
        String url = "http://www.wanandroid.com/project/tree/json";
        //get request
        HttpMethod method = HttpMethod.GET;
        // Package parameters. Do not replace them with Map and HashMap, otherwise the parameters cannot be passed
        MultiValueMap<String, String> params = new LinkedMultiValueMap<String, String>();
        return HttpClient.init().client(url, method, params, null);
    }

    /**
     * Item list data
     *
     * @param pagernumber Methods: GET
     *                    Parameters:
     *                    cid Classification id, the above item classification interface
     *                    Page: spliced in the link, starting with 1.
     * @param cid
     * @return
     * @throws Exception
     */
    @GetMapping(value = "/project/list")
    public String projectList(@RequestParam(value = "pagernumber") int pagernumber, @RequestParam(value = "cid") String cid) throws Exception {
        //url
        String url = "http://www.wanandroid.com/project/list/" + pagernumber + "/json";
        //get request
        HttpMethod method = HttpMethod.GET;
        // Package parameters. Do not replace them with Map and HashMap, otherwise the parameters cannot be passed
        MultiValueMap<String, String> params = new LinkedMultiValueMap<String, String>();
        params.add("cid", cid);
        return HttpClient.init().client(url, method, params, null);
    }

    /**========================================5. Login and registration=================================================================**/

    /**
     * Sign in
     *
     * @param username Method: POST
     *                 Parameters:
     *                 username,password
     *                 After login, the account password will be returned in the cookie. As long as the cookie persistent storage is done in the client, the login verification can be automatically performed.
     * @param password
     * @return
     * @throws Exception
     */
    @PostMapping(value = "/login")
    public String login(@RequestParam(value = "username") String username, @RequestParam(value = "password") String password) throws Exception {
        //url
        String url = "http://www.wanandroid.com/user/login";
        //get request
        HttpMethod method = HttpMethod.POST;
        // Package parameters. Do not replace them with Map and HashMap, otherwise the parameters cannot be passed
        MultiValueMap<String, String> params = new LinkedMultiValueMap<String, String>();
        params.add("username", username);
        params.add("password", password);
        return HttpClient.init().client(url, method, params, username);
    }

    /**
     * Log out, clear the local cookie
     *
     * @param username
     * @throws Exception
     */
    @GetMapping(value = "/loginout")
    public void loginout(@RequestParam(value = "username") String username) throws Exception {
        HttpClient.init().deteleCookie(username);
    }


    /**
     * register
     *
     * @param username   Method: POST
     *                   parameter
     *                   username,password,repassword
     * @param password
     * @param repassword
     * @return
     * @throws Exception
     */
    @PostMapping(value = "/register")
    public String register(@RequestParam(value = "username") String username, @RequestParam(value = "password") String password
            , @RequestParam(value = "repassword") String repassword) throws Exception {
        //url
        String url = "http://www.wanandroid.com/user/register";
        //get request
        HttpMethod method = HttpMethod.POST;
        // Package parameters. Do not replace them with Map and HashMap, otherwise the parameters cannot be passed
        MultiValueMap<String, String> params = new LinkedMultiValueMap<String, String>();
        params.add("username", username);
        params.add("password", password);
        params.add("repassword", repassword);
        return HttpClient.init().client(url, method, params, null);
    }

    /**========================================6. Collection=================================================================**/
    /**
     * List of favorite articles
     *
     * @param pagernumber Methods: GET
     *                    Parameters: page number: spliced in the link, starting from 0.
     * @return
     * @throws Exception
     */
    @GetMapping(value = "/collect/list")
    public String collectList(@RequestParam(value = "pagernumber") int pagernumber, @RequestParam(value = "username") String username) throws Exception {
        //url
        String url = "http://www.wanandroid.com/lg/collect/list/" + pagernumber + "/json";
        //get request
        HttpMethod method = HttpMethod.GET;
        // Package parameters. Do not replace them with Map and HashMap, otherwise the parameters cannot be passed
        MultiValueMap<String, String> params = new LinkedMultiValueMap<String, String>();
        return HttpClient.init().client(url, method, params, username);
    }

    /**
     * Articles in the collection station
     *
     * @param id Method: POST
     *           Parameter: Article id, spliced in the link.
     *           Note the number in the link for the id you want to collect
     * @return
     * @throws Exception
     */
    @PostMapping(value = "/collect")
    public String collect(@RequestParam(value = "id") int id, @RequestParam(value = "username") String username) throws Exception {
        //url
        String url = "http://www.wanandroid.com/lg/collect/" + id + "/json";
        //get request
        HttpMethod method = HttpMethod.POST;
        // Package parameters. Do not replace them with Map and HashMap, otherwise the parameters cannot be passed
        MultiValueMap<String, String> params = new LinkedMultiValueMap<String, String>();
        return HttpClient.init().client(url, method, params, username);
    }

    /**
     * Cancel collection from article list
     *
     * @param id Method: POST parameter:
     *           id:Splicing on links
     * @return
     * @throws Exception
     */
    @PostMapping(value = "/uncollectoriginId")
    public String uncollectoriginId(@RequestParam(value = "id") int id, @RequestParam(value = "username") String username) throws Exception {
        //url
        String url = "http://www.wanandroid.com/lg/uncollect_originId/" + id + "/json";
        //get request
        HttpMethod method = HttpMethod.POST;
        // Package parameters. Do not replace them with Map and HashMap, otherwise the parameters cannot be passed
        MultiValueMap<String, String> params = new LinkedMultiValueMap<String, String>();
        return HttpClient.init().client(url, method, params, username);
    }

    /**
     * Cancel collection from my favorites page
     *
     * @param id Method: POST
     *           Parameters:
     *           id:Splicing on links
     *           originId:Distribute the list page, otherwise - 1
     *           originId It represents the id of the article before your collection; however, the collection supports active addition. In this case, if there is no originId, it is - 1
     * @return
     * @throws Exception
     */
    @PostMapping(value = "/uncollect")
    public String uncollect(@RequestParam(value = "id") int id, @RequestParam(value = "username") String username,
                            @RequestParam(value = "originId") String originId) throws Exception {
        //url
        String url = "http://www.wanandroid.com/lg/uncollect/" + id + "/json";
        //get request
        HttpMethod method = HttpMethod.POST;
        // Package parameters. Do not replace them with Map and HashMap, otherwise the parameters cannot be passed
        MultiValueMap<String, String> params = new LinkedMultiValueMap<String, String>();
        params.add("originId",originId);
        return HttpClient.init().client(url, method, params, username);
    }

    /**========================================7. Search=================================================================**/
    /**
     * search
     *
     * @param key         Method: POST
     *                    Parameters:
     *                    Page: spliced on the link, starting at 0.
     *                    k :  Search keywords
     *                    Note: multiple keywords are supported, separated by spaces
     * @param pagernumber
     * @return
     * @throws Exception
     */
    @PostMapping(value = "/query")
    public String query(@RequestParam(value = "key") String key, @RequestParam(value = "pagernumber") int pagernumber) throws Exception {
        //url
        String url = "http://www.wanandroid.com/article/query/" + pagernumber + "/json";
        //get request
        HttpMethod method = HttpMethod.POST;
        // Package parameters. Do not replace them with Map and HashMap, otherwise the parameters cannot be passed
        MultiValueMap<String, String> params = new LinkedMultiValueMap<String, String>();
        params.add("k", key);
        return HttpClient.init().client(url, method, params, null);
    }

    /**========================================8. HTML=================================================================**/
    @GetMapping(value = "/html")
    public String html(@RequestParam(value = "link") String link)throws Exception{
        //get request
        HttpMethod method = HttpMethod.GET;
        // Package parameters. Do not replace them with Map and HashMap, otherwise the parameters cannot be passed
        MultiValueMap<String, String> params = new LinkedMultiValueMap<String, String>();
        return HttpClient.init().client(link, method, params, null);
    }
}

Tags: JSON Android github

Posted on Tue, 07 Jan 2020 03:34:35 -0800 by MatrixDancer