package com.heyu.api.controller.vv;


import com.heyu.api.alibaba.request.vv.AppLinkRequest;
import com.heyu.api.alibaba.request.vv.AppSchemeRequest;
import com.heyu.api.alibaba.request.vv.AppShortLinkRequest;
import com.heyu.api.common.annotation.AppRealyLogin;
import com.heyu.api.common.annotation.Describe;
import com.heyu.api.data.utils.R;
import com.heyu.api.data.utils.WeChatUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
@RequestMapping("/app/create")
public class AppLinkController {


    // 自行配置：正式版为 "release"，体验版为 "trial"，开发版为 "develop"。默认是正式版。
    private String envVersion = "trial";

    @Autowired
    private WeChatUtils weChatUtils;

    /***
     * 链接
     * http://localhost:8888/app/create/link
     *

     curl -sS -X POST 'http://172.16.5.230:8888/app/create/link' \
     -H 'Content-Type: application/json' \
     -d '{}'


     */
    @Describe("生成link")
    @RequestMapping("/link")
    //@AppRealyLogin
    public R link(@RequestBody AppLinkRequest request) {
        String url = weChatUtils.jumpAppletShortUrl("/pages/index/index", "?type=1", 30);

        return R.ok();
    }



    /***
     * 短链接
     * http://localhost:8888/app/create/shortLink
     */
    @Describe("生成")
    @RequestMapping("/shortLink")
    @AppRealyLogin
    public R shortlink(@RequestBody AppShortLinkRequest request) {
        String url = weChatUtils.genShortlink("/pages/index/index", "ewiiwe", 30);
        return R.ok().setData(url);
    }




    /***
     * 链接
     * http://localhost:8888/app/create/scheme
     */
    @Describe("生成")
    @RequestMapping("/scheme")
    @AppRealyLogin
    public R scheme(@RequestBody AppSchemeRequest request) {
        String url = weChatUtils.jumpAppletSchemeUrl("abc", "89ew8392", 30);
        return R.ok();
    }

}



