/**
 * All rights Reserved, Designed By www.freemud.cn
 *
 * @Title: WeChatClient
 * @Package cn.freemud.service.thirdparty
 * @Description:
 * @author: liming.guo
 * @date: 2018/5/29 16:10
 * @version V1.0
 * @Copyright: 2018 www.freemud.cn Inc. All rights reserved.
 * 注意：本内容仅限于上海非码科技内部传阅，禁止外泄以及用于其他的商业目
 */
package cn.freemud.service.thirdparty;

import cn.freemud.entities.dto.GetWxQrcodeDto;
import cn.freemud.entities.dto.WeChatGetAccessTokenResponseDto;
import cn.freemud.entities.dto.WechatSendMessageDto;
import com.freemud.sdk.api.assortment.order.request.order.GroupBuyRequest;
import com.freemud.sdk.api.assortment.order.response.order.GroupBuyResponse;
import org.springframework.cloud.netflix.feign.FeignClient;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

@FeignClient(name = "WECHAT-SERVICE", url = "${saas.wechatclient.feign.url}")
public interface WeChatClient {

    /**
     *  小程序登录 获取用户openId 和 sercetKey
     *
     * @param appid  小程序appId
     * @param secret   小程序appSecret
     * @param jsCode  code
     * @param grantType  authorization_code
     * @return
     */
    @GetMapping(value = "/sns/jscode2session",produces = MediaType.APPLICATION_FORM_URLENCODED_VALUE, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    String getSession(@RequestParam("appid") String appid, @RequestParam("secret") String secret,
                                           @RequestParam("js_code") String jsCode, @RequestParam("grant_type") String grantType);


    /**
     * 小程序登录 获取用户openId 和 sercetKey  小程序授权模式
     */
    @GetMapping(value = "/sns/component/jscode2session", produces = MediaType.APPLICATION_FORM_URLENCODED_VALUE, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    String getCode2session(@RequestParam("appid") String appid, @RequestParam("js_code") String code,
                           @RequestParam("grant_type") String authorizationCode, @RequestParam("component_appid") String componentAppid,
                           @RequestParam("component_access_token") String componentAccessToken);


    /**
     * 获取小程序access_token
     */
    @GetMapping(value = "/cgi-bin/token", produces = MediaType.APPLICATION_FORM_URLENCODED_VALUE, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    WeChatGetAccessTokenResponseDto getAccessToken(@RequestParam("grant_type") String grantType, @RequestParam("appid") String appid,
                                                   @RequestParam("secret") String secret);


    /**
     * 获取小程序码
     */
    @PostMapping(value = "wxa/getwxacodeunlimit?access_token=12_-kLukRhVUNHrX2JFwSTHK7ZjAkSAKRQuReFhmoZKGywkUbBNTWoR8IDHbfN0jA1ot_i2xlhkV89tKUqM8hDBsAMPlg6d6p0YnqufZY5B-pFzG_JH7rbb43Lcc3gnNAvHQLrD-rpRg3LGi5VDYERgAFADJW",
            produces = MediaType.APPLICATION_FORM_URLENCODED_VALUE, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    String getWxacodeunlimit(@RequestBody GetWxQrcodeDto getWxQrcodeDto);

    @PostMapping(value = "/cgi-bin/message/wxopen/template/send?access_token={accessToken}", produces = MediaType.APPLICATION_FORM_URLENCODED_VALUE,
            consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    String sendMessageNotice(@PathVariable("accessToken") String accessToken, @RequestBody WechatSendMessageDto wechatSendMessageDto);




    /**
     * 发起群收款
     */
    @PostMapping(value = "wxa/business/groupBuy/createOrder?access_token={accessToken}",
            produces = MediaType.APPLICATION_JSON_VALUE,
            consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    GroupBuyResponse groupBuyCreateOrder(@PathVariable("accessToken") String accessToken, @RequestBody GroupBuyRequest groupBuyRequest);

}
