package cn.momia.wap.web.ctrl.user;

import cn.momia.common.api.http.MomiaHttpResponse;
import cn.momia.common.webapp.config.Configuration;
import cn.momia.wap.web.ctrl.AbstractController;
import com.alibaba.fastjson.JSONObject;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import java.net.URLEncoder;
import java.util.HashMap;
import java.util.Map;

@Controller
public class UserController extends AbstractController {
    private static final Logger LOGGER = LoggerFactory.getLogger(UserController.class);

    @RequestMapping(value = "/my", method = RequestMethod.GET)
    public ModelAndView my(HttpServletRequest request) {
        String utoken = getUtoken(request);
        if (!StringUtils.isBlank(utoken)) {
            try {
                MomiaHttpResponse resp = get("/user?utoken=" + utoken);
                return new ModelAndView("my", "user", resp.getData());
            } catch (Exception e) {
                LOGGER.error("fail to get user info", e);
            }
        }

        return new ModelAndView("my");
    }

    @RequestMapping(value = "/user/profile", method = RequestMethod.GET)
    public ModelAndView profile(HttpServletRequest request) {
        String utoken = getUtoken(request);
        if (StringUtils.isBlank(utoken)) return new ModelAndView("redirect:/auth/login?ref=" + URLEncoder.encode(request.getRequestURL().toString()) + "&back=" + request.getHeader("Referer"));

        MomiaHttpResponse resp = get("/user?utoken=" + utoken);
        return new ModelAndView("user/profile", "user", resp.getData());
    }

    @RequestMapping(value = "/user/share", method = RequestMethod.GET)
    public ModelAndView share(HttpServletRequest request) {
        String utoken = getUtoken(request);
        if (StringUtils.isBlank(utoken)) return new ModelAndView("redirect:/auth/login?ref=" + URLEncoder.encode(request.getRequestURL().toString()) + "&back=" + request.getHeader("Referer"));

        MomiaHttpResponse resp = get("/user?utoken=" + utoken);
        String shareUrl = Configuration.getString("Share.Url") + "?invite=" + ((JSONObject) resp.getData()).getString("inviteCode");

        Map<String, Object> share = new HashMap<String, Object>();
        share.put("title", "50元松果亲子课程红包等你拿！");
        share.put("abstracts", "最有同理心的课堂，最有性价比的价格。和孩子一起成长，不错过他给你带来的每一次惊喜！");
        share.put("url", shareUrl);
        share.put("config", new WxConfig(Configuration.getString("Weixin.JsApiAppId"), request.getRequestURL() + "?" + request.getQueryString()));

        return new ModelAndView("user/share", "share", share);
    }
}

@@ -2465,223 +2465,189 @@
    M
-ap%3CString, Object%3E share = new HashMap%3CString, Object%3E();%0A        share.put(%22title%22, %2250%E5%85%83%E6%9D%BE%E6%9E%9C%E4%BA%B2%E5%AD%90%E8%AF%BE%E7%A8%8B%E7%BA%A2%E5%8C%85%E7%AD%89%E4%BD%A0%E6%8B%BF%EF%BC%81%22);%0A        share.put(%22abstracts%22, %22%E6%9C%80%E6%9C%89%E5%90%8C%E7%90%86%E5%BF%83%E7%9A%84%E8%AF%BE%E5%A0%82%EF%BC%8C%E6%9C%80%E6%9C%89%E6%80%A7%E4%BB%B7%E6%AF%94%E7%9A%84%E4%BB%B7%E6%A0%BC%E3%80%82%E5%92%8C%E5%AD%A9%E5%AD%90%E4%B8%80%E8%B5%B7%E6%88%90%E9%95%BF%EF%BC%8C%E4%B8%8D%E9%94%99%E8%BF%87%E4%BB%96%E7%BB%99%E4%BD%A0%E5%B8%A6%E6%9D%A5%E7%9A%84%E6%AF%8F%E4%B8%80%E6%AC%A1%E6%83%8A%E5%96%9C%EF%BC%81%22);%0A        share.put(%22url%22, shareUrl
+omiaHttpResponse shareResp = get(%22/coupon/share?utoken=%22 + utoken);%0A        JSONObject share = (JSONObject) shareResp.getData();%0A        String queryString = request.getQueryString(
 );%0A 
@@ -2762,36 +2762,67 @@
 ) + 
+(StringUtils.isBlank(queryString) ? %22%22 : (
 %22?%22 + 
-re
 que
-st.getQue
 ryString
 ()))
@@ -2817,17 +2817,17 @@
 ryString
-(
+)
 )));%0A%0A  

fix bug