package net.wendal.nutzbook.module;

import org.apache.shiro.authz.annotation.RequiresUser;
import org.nutz.ioc.impl.PropertiesProxy;
import org.nutz.ioc.loader.annotation.Inject;
import org.nutz.ioc.loader.annotation.IocBean;
import org.nutz.lang.Lang;
import org.nutz.lang.Strings;
import org.nutz.lang.random.R;
import org.nutz.lang.util.NutMap;
import org.nutz.mvc.annotation.At;
import org.nutz.mvc.annotation.Ok;
import org.nutz.mvc.annotation.POST;
import org.nutz.mvc.annotation.Param;

@IocBean
@At("/pay/bc")
public class BeePayModule extends BaseModule {
    
    @Inject
    PropertiesProxy conf;

    @POST
    @RequiresUser
    @Ok("json")
    @At
    public Object create(@Param("to")int toUserId, @Param("title")String title, @Param("amount")int amount) {
        String out_trade_no = "bc"+System.currentTimeMillis();
        if (amount == 0) {
            amount = R.random(1, 100);
        }
        else if (amount < 1)
            amount = 1;
        else if (amount > 100)
            amount = 100;
        String appid = conf.get("bc.appId");
        String appSecret = conf.get("bc.appSecret");
        if (Strings.isBlank(title))
            title = "你的订单号:"+R.UU32().substring(0, 8);
        NutMap re = new NutMap();
        re.put("out_trade_no", out_trade_no);
        re.put("amount", amount);
        re.put("title", title);
        re.put("sign", Lang.md5(appid+title+amount+out_trade_no+appSecret));
        re.put("debug", true);
        return _map("data", re);
    }
}

@@ -800,37 +800,47 @@
  = %22
-bc%22+System.currentTimeMillis(
+u%22+toUserId+%22z%22+R.UU32().substring(0, 8
 );%0A 
@@ -1183,40 +1183,27 @@
  = %22
-%E4%BD%A0%E7%9A%84%E8%AE%A2%E5%8D%95%E5%8F%B7:%22+R.UU32().substring(0, 8)
+%E9%9A%8F%E6%9C%BA%E6%89%93%E8%B5%8F%E7%BB%99uid=%22+toUserId
 ;%0A  
@@ -1423,32 +1423,34 @@
 cret));%0A        
+//
 re.put(%22debug%22, 

禁用beecloud pay的debug功能