@At
@Ok("beetl:/public/wx/pay.html")
public void jsApi(String id, @Param("money") int money, HttpServletRequest req, HttpSession session) {
String openid = Strings.sNull(session.getAttribute("openid"));
String wxid = Strings.sNull(session.getAttribute("wxid"));
log.debug("pay money:::" + money);
log.debug("pay wxid:::" + wxid);
log.debug("pay openid:::" + openid);
Wx_config config = wxConfigService.fetch(wxid);
NutMap payinfo = Json.fromJson(NutMap.class, config.getPayInfo());
WxApi2 wxApi2 = wxConfigService.getWxApi2(wxid);
if (Lang.isEmpty(Globals.memoryJsapiTicketStore.get(wxid))) {
Globals.memoryJsapiTicketStore.put(wxid, new MemoryJsapiTicketStore());
}
MemoryJsapiTicketStore memoryJsapiTicketStore = Globals.memoryJsapiTicketStore.get(wxid);
wxApi2.setJsapiTicketStore(memoryJsapiTicketStore);
String url = "http://" + Globals.AppDomain + Globals.AppBase + "/test/pay/" + Strings.sNull(id);
NutMap jsConfig = wxApi2.genJsSDKConfig(url, "chooseWXPay");
String nonce_str=R.UU32();
WxPayUnifiedOrder order = new WxPayUnifiedOrder();
order.setAppid(config.getAppid());
order.setMch_id(payinfo.getString("wxpay_mchid"));
order.setNonce_str(nonce_str);
order.setBody("Test");//运行环境 -Dfile.encoding=UTF-8
order.setOut_trade_no(DateUtil.format(new Date(), "yyyyMMddHHmmss"));
order.setTotal_fee(money);
order.setSpbill_create_ip(Globals.AppIp);
order.setNotify_url("http://" + Globals.AppDomain + Globals.AppBase + "/test/payback");//支付结果通知回调地址
order.setTrade_type("JSAPI");
order.setOpenid(openid);//JSAPI时openid必填
order.setProduct_id("Test");
order.setAttach("购买套餐");
log.debug("order:::" + Json.toJson(order));
NutMap resp = wxApi2.pay_jsapi(payinfo.getString("wxpay_key"), order);
String return_code = resp.getString("return_code", "");//SUCCESS
log.debug("return_code:::" + return_code);
log.debug("resp:::" + Json.toJson(resp));
req.setAttribute("jsConfig", Json.toJson(jsConfig));
req.setAttribute("money", money);
req.setAttribute("moneys", MoneyUtil.fenToYuan(money));
req.setAttribute("resp", resp);
req.setAttribute("id", id);
}
Globals.memoryJsapiTicketStore报错没有此属性