标签:sdk接入 unity sdk接入 sdk服务器 sdk登陆认证
@Action("getToken") public void getLoginToken(){ try{ Log.i("The appID is "+this.appID); UGame game = gameManager.queryGame(this.appID); if(game == null){ renderState(StateCode.CODE_GAME_NONE, null); return; } UChannel channel = channelManager.queryChannel(this.channelID); if(channel == null){ renderState(StateCode.CODE_CHANNEL_NONE, null); return; } UChannelMaster master = channel.getMaster(); if(master == null){ renderState(StateCode.CODE_CHANNEL_NONE, null); return; } ISDKVerifier verifier = Class.forName(master.verifyClass) SDKVerifyResult sdkResult = verifier.verify(channel, sid, extension); if(sdkResult.isSuccess()){ UUser user = userManager.getUserByCpID(appID, channelID, sdkResult.getUserID()); if(user == null){ user = userManager.generateUser(channel, sdkResult); }else{ user.setLastLoginTime(new Date()); } user.setToken(UGenerator.generateToken(user)); userManager.saveUser(user); JSONObject data = new JSONObject(); data.put("userID", user.getId()); data.put("token", user.getToken()); renderState(StateCode.CODE_AUTH_SUCCESS, data); }else{ renderState(StateCode.CODE_AUTH_FAILED, null); } }catch (Exception e){ Log.e(e.getMessage()); renderState(StateCode.CODE_AUTH_FAILED, null); } }
@Action("verifyAccount") public void loginVerify(){ try{ UUser user = userManager.getUser(this.userID); if(user == null){ renderState(StateCode.CODE_USER_NONE, null); return; } if(StringUtils.isEmpty(this.token)){ renderState(StateCode.CODE_VERIFY_FAILED, null); return; } long now = System.currentTimeMillis(); if(!this.userManager.isTokenValid(user, token)){ renderState(StateCode.CODE_TOKEN_ERROR, null); return; } JSONObject data = new JSONObject(); data.put("userID", user.getId()); data.put("username", user.getName()); renderState(StateCode.CODE_AUTH_SUCCESS, data); return; }catch (Exception e){ Log.e(e.getMessage()); } renderState(StateCode.CODE_VERIFY_FAILED, null); }
@Action("getOrderID") public void getOrderID(){ try{ UUser user = userManager.getUser(this.userID); if(user == null){ renderState(StateCode.CODE_USER_NONE, null); return; } if(money < 0 ){ renderState(StateCode.CODE_MONEY_ERROR, null); return; } UOrder order = orderManager.generateOrder(user, money, extension); if(order != null){ JSONObject data = new JSONObject(); data.put("orderID", order.getOrderID()); renderState(StateCode.CODE_AUTH_SUCCESS, data); return; } }catch (Exception e){ Log.e(e.getMessage()); } renderState(StateCode.CODE_ORDER_ERROR, null); }
@Controller @Namespace("/uc") public class UCPayCallbackAction extends UActionSupport{ @Autowired private UOrderManager orderManager; @Action("payCallback") public void payCallback(){ try{ //BufferedReader br = new BufferedReader(new InputStreamReader(this.request.getInputStream(), "UTF-8")); BufferedReader br = this.request.getReader(); String line; StringBuilder sb = new StringBuilder(); while((line=br.readLine()) != null){ sb.append(line).append("\r\n"); } Log.d("UC Pay Callback . request params:" + sb.toString()); PayCallbackResponse rsp = (PayCallbackResponse) JsonUtils.decodeJson(sb.toString(), PayCallbackResponse.class); if(rsp == null){ this.renderState(false); return; } long orderID = Long.parseLong(rsp.getData().getCallbackInfo()); UOrder order = orderManager.getOrder(orderID); if(order == null || order.getChannel() == null){ Log.d("The order is null or the channel is null."); this.renderState(false); return; } UCSDK sdk = new UCSDK(); if(!sdk.verifyPay(order.getChannel(), rsp)){ Log.d("The sign is not matched."); this.renderState(false); return; } if("S".equals(rsp.getData().getOrderStatus())){ float money = Float.parseFloat(rsp.getData().getAmount()); int moneyInt = (int)(money * 100); //以分为单位 order.setMoney(moneyInt); order.setChannelOrderID(rsp.getData().getOrderId()); order.setState(PayState.STATE_SUC); orderManager.saveOrder(order); Log.d("The channnel order is ok. sendToServer."); sendToServer(order); }else{ order.setChannelOrderID(rsp.getData().getOrderId()); order.setState(PayState.STATE_FAILED); orderManager.saveOrder(order); } renderState(true); }catch (Exception e){ try{ this.renderState(false); }catch (Exception e2){ Log.e(e2.getMessage()); } Log.e(e.getMessage()); } } private boolean sendToServer(UOrder order){ UGame game = order.getGame(); if(game == null){ return false; } if(StringUtils.isEmpty(game.getPayCallback())){ return false; } JSONObject data = new JSONObject(); data.put("orderID", order.getOrderID()); data.put("userID", order.getUserID()); data.put("gameID", order.getAppID()); data.put("money", order.getMoney()); data.put("currency", order.getCurrency()); data.put("extension", order.getExtension()); JSONObject response = new JSONObject(); response.put("state", StateCode.CODE_AUTH_SUCCESS); response.put("data", data); response.put("sign", UGenerator.generateSign(order)); UHttpAgent httpAgent = new UHttpAgent("text/html"); String serverRes = httpAgent.post(game.getPayCallback(), response.toString()); if(serverRes.equals("SUCCESS")){ order.setState(PayState.STATE_COMPLETE); orderManager.saveOrder(order); return true; } return false; } private void renderState(boolean suc) throws IOException{ String res = "SUCCESS"; if(!suc){ res = "FAILURE"; } this.response.getWriter().write(res); } }
标签:sdk接入 unity sdk接入 sdk服务器 sdk登陆认证
原文地址:http://blog.csdn.net/chenjie19891104/article/details/44134901