mirror of https://github.com/Rekoe/rk_svnadmin
add
commit
84eb3a9862
|
@ -0,0 +1,5 @@
|
|||
1)create database platform
|
||||
2)mvn clean
|
||||
3)mvn eclipse:eclipse -Dwtpversion=1.0
|
||||
4)mvn package -Dmaven.test.skip=true
|
||||
5)mvn dependency:tree 可以查看依赖树
|
|
@ -0,0 +1,7 @@
|
|||
{
|
||||
"name": "账号管理平台",
|
||||
"version": "1.0.0",
|
||||
"description": "账号认证平台",
|
||||
"title": "账号认证平台",
|
||||
"url" : "http://warlogin.shanggame.com"
|
||||
}
|
|
@ -0,0 +1,319 @@
|
|||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>com.rekoe</groupId>
|
||||
<artifactId>rk_svnadmin</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<version>3.0</version>
|
||||
<name>rk_svnadmin</name>
|
||||
<url>http://www.rekoe.com</url>
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
<repositories>
|
||||
</repositories>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>javax.servlet</groupId>
|
||||
<artifactId>servlet-api</artifactId>
|
||||
<version>2.5</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>mysql</groupId>
|
||||
<artifactId>mysql-connector-java</artifactId>
|
||||
<version>5.1.28</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>druid</artifactId>
|
||||
<version>1.0.16</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<artifactId>jconsole</artifactId>
|
||||
<groupId>com.alibaba</groupId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<artifactId>tools</artifactId>
|
||||
<groupId>com.alibaba</groupId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.sf.ehcache</groupId>
|
||||
<artifactId>ehcache</artifactId>
|
||||
<version>2.9.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.shiro</groupId>
|
||||
<artifactId>shiro-ehcache</artifactId>
|
||||
<version>1.2.4</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<artifactId>ehcache-core</artifactId>
|
||||
<groupId>net.sf.ehcache</groupId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<artifactId>shiro-core</artifactId>
|
||||
<groupId>org.apache.shiro</groupId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.nutz</groupId>
|
||||
<artifactId>nutz-plugins-views</artifactId>
|
||||
<version>1.r.54.r2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.nutz</groupId>
|
||||
<artifactId>nutz</artifactId>
|
||||
<version>1.r.56.r1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.nutz</groupId>
|
||||
<artifactId>nutz-web</artifactId>
|
||||
<version>1.b.49</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.restfb</groupId>
|
||||
<artifactId>restfb</artifactId>
|
||||
<version>1.6.14</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.codehaus.jackson</groupId>
|
||||
<artifactId>jackson-all</artifactId>
|
||||
<version>1.9.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.oltu.oauth2</groupId>
|
||||
<artifactId>org.apache.oltu.oauth2.authzserver</artifactId>
|
||||
<version>1.0.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.oltu.oauth2</groupId>
|
||||
<artifactId>org.apache.oltu.oauth2.resourceserver</artifactId>
|
||||
<version>1.0.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.oltu.oauth2</groupId>
|
||||
<artifactId>org.apache.oltu.oauth2.common</artifactId>
|
||||
<version>1.0.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.apis</groupId>
|
||||
<artifactId>google-api-services-androidpublisher</artifactId>
|
||||
<version>v2-rev22-1.21.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.http-client</groupId>
|
||||
<artifactId>google-http-client</artifactId>
|
||||
<version>1.21.0</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<artifactId>jsr305</artifactId>
|
||||
<groupId>com.google.code.findbugs</groupId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.apis</groupId>
|
||||
<artifactId>google-api-services-oauth2</artifactId>
|
||||
<version>v2-rev101-1.21.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.api-client</groupId>
|
||||
<artifactId>google-api-client</artifactId>
|
||||
<version>1.21.0</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<artifactId>jsr305</artifactId>
|
||||
<groupId>com.google.code.findbugs</groupId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<artifactId>guava-jdk5</artifactId>
|
||||
<groupId>com.google.guava</groupId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.apis</groupId>
|
||||
<artifactId>google-api-services-plus</artifactId>
|
||||
<version>v1-rev327-1.21.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.freemarker</groupId>
|
||||
<artifactId>freemarker</artifactId>
|
||||
<version>2.3.20</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.quartz-scheduler</groupId>
|
||||
<artifactId>quartz</artifactId>
|
||||
<version>2.2.1</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>c3p0</groupId>
|
||||
<artifactId>c3p0</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.nutz</groupId>
|
||||
<artifactId>nutz-plugins-daocache</artifactId>
|
||||
<version>1.b.53.r2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.nutz</groupId>
|
||||
<artifactId>nutz-integration-quartz</artifactId>
|
||||
<version>1.b.53</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>c3p0</groupId>
|
||||
<artifactId>c3p0</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.cloopen</groupId>
|
||||
<artifactId>ccp_rest_sdk</artifactId>
|
||||
<version>2.7.r</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.json</groupId>
|
||||
<artifactId>json</artifactId>
|
||||
<version>20090211</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-email</groupId>
|
||||
<artifactId>commons-email</artifactId>
|
||||
<version>1.1</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<artifactId>activation</artifactId>
|
||||
<groupId>javax.activation</groupId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.nutz</groupId>
|
||||
<artifactId>nutz-integration-shiro</artifactId>
|
||||
<version>1.b.53</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.shiro</groupId>
|
||||
<artifactId>shiro-all</artifactId>
|
||||
<version>1.2.3</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>org.apache.shiro</groupId>
|
||||
<artifactId>shiro-guice</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-beanutils</groupId>
|
||||
<artifactId>commons-beanutils-core</artifactId>
|
||||
<version>1.8.3</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-lang3</artifactId>
|
||||
<version>3.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-logging</groupId>
|
||||
<artifactId>commons-logging</artifactId>
|
||||
<version>1.1.3</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>log4j</groupId>
|
||||
<artifactId>log4j</artifactId>
|
||||
<version>1.2.17</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-api</artifactId>
|
||||
<version>1.7.5</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-log4j12</artifactId>
|
||||
<version>1.7.5</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-vfs2</artifactId>
|
||||
<version>2.0</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<artifactId>maven-scm-api</artifactId>
|
||||
<groupId>org.apache.maven.scm</groupId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<artifactId>maven-scm-provider-svnexe</artifactId>
|
||||
<groupId>org.apache.maven.scm</groupId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.brickred</groupId>
|
||||
<artifactId>socialauth</artifactId>
|
||||
<version>4.5</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>org.json</groupId>
|
||||
<artifactId>json</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>org.openid4java</groupId>
|
||||
<artifactId>openid4java-consumer</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.htmlparser</groupId>
|
||||
<artifactId>htmlparser</artifactId>
|
||||
<version>2.1</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<build>
|
||||
<sourceDirectory>src/main/java</sourceDirectory>
|
||||
<resources>
|
||||
<resource>
|
||||
<directory>src/main/resources</directory>
|
||||
<includes>
|
||||
<include>com/rekoe/web/freemarker/*.*</include>
|
||||
</includes>
|
||||
</resource>
|
||||
<resource>
|
||||
<directory>src/main/java</directory>
|
||||
<includes>
|
||||
<include>**/*.properties</include>
|
||||
<include>**/*.js</include>
|
||||
</includes>
|
||||
<filtering>false</filtering>
|
||||
</resource>
|
||||
</resources>
|
||||
<finalName>rk_svnadmin</finalName>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>2.5.1</version>
|
||||
<configuration>
|
||||
<source>1.7</source>
|
||||
<target>1.7</target>
|
||||
<encoding>UTF-8</encoding>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<version>2.17</version>
|
||||
<configuration>
|
||||
<forkMode>once</forkMode>
|
||||
<argLine>-Dfile.encoding=UTF-8</argLine>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
|
@ -0,0 +1,21 @@
|
|||
package com.rekoe.annotation;
|
||||
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target({ ElementType.METHOD, ElementType.TYPE })
|
||||
@Documented
|
||||
public @interface PermissionTag {
|
||||
|
||||
boolean enable() default true;
|
||||
|
||||
String name();
|
||||
|
||||
String tag();
|
||||
|
||||
String tagId() default "";
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
package com.rekoe.annotation;
|
||||
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target({ ElementType.METHOD, ElementType.TYPE })
|
||||
@Documented
|
||||
public @interface PlatformProvider {
|
||||
|
||||
boolean enable() default true;
|
||||
|
||||
String name();
|
||||
}
|
|
@ -0,0 +1,165 @@
|
|||
package com.rekoe.cms.socialauth;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import org.brickred.socialauth.AbstractProvider;
|
||||
import org.brickred.socialauth.AuthProvider;
|
||||
import org.brickred.socialauth.Contact;
|
||||
import org.brickred.socialauth.Permission;
|
||||
import org.brickred.socialauth.Profile;
|
||||
import org.brickred.socialauth.exception.AccessTokenExpireException;
|
||||
import org.brickred.socialauth.exception.SocialAuthException;
|
||||
import org.brickred.socialauth.exception.UserDeniedPermissionException;
|
||||
import org.brickred.socialauth.oauthstrategy.OAuthStrategyBase;
|
||||
import org.brickred.socialauth.util.AccessGrant;
|
||||
import org.brickred.socialauth.util.OAuthConfig;
|
||||
import org.brickred.socialauth.util.Response;
|
||||
import org.brickred.socialauth.util.SocialAuthUtil;
|
||||
import org.nutz.lang.Lang;
|
||||
import org.nutz.log.Log;
|
||||
import org.nutz.log.Logs;
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
public abstract class AbstractOAuthProvider extends AbstractProvider implements AuthProvider {
|
||||
|
||||
private static final Log log = Logs.get();
|
||||
|
||||
protected Permission scope;
|
||||
protected OAuthConfig config;
|
||||
protected Profile userProfile;
|
||||
protected AccessGrant accessGrant;
|
||||
protected OAuthStrategyBase authenticationStrategy;
|
||||
|
||||
protected static String[] AllPerms;
|
||||
protected static String[] AuthPerms;
|
||||
protected static Map<String, String> ENDPOINTS = new HashMap<String, String>();
|
||||
|
||||
protected abstract String getPlatform();
|
||||
public AbstractOAuthProvider(OAuthConfig providerConfig) throws Exception {
|
||||
this.config = providerConfig;
|
||||
}
|
||||
|
||||
public String getLoginRedirectURL(final String successUrl) throws Exception {
|
||||
return authenticationStrategy.getLoginRedirectURL(successUrl);
|
||||
}
|
||||
|
||||
public Profile verifyResponse(HttpServletRequest httpReq) throws Exception {
|
||||
Map<String, String> params = SocialAuthUtil.getRequestParametersMap(httpReq);
|
||||
return doVerifyResponse(params);
|
||||
}
|
||||
|
||||
public Profile verifyResponse(Map<String, String> params) throws Exception {
|
||||
return doVerifyResponse(params);
|
||||
}
|
||||
|
||||
protected Profile doVerifyResponse(final Map<String, String> requestParams) throws Exception {
|
||||
log.info("Retrieving Access Token in verify response function");
|
||||
if (requestParams.get("error_reason") != null && "user_denied".equals(requestParams.get("error_reason"))) {
|
||||
throw new UserDeniedPermissionException();
|
||||
}
|
||||
accessGrant = authenticationStrategy.verifyResponse(requestParams, verifyResponseMethod());
|
||||
if (accessGrant != null) {
|
||||
log.debug("Obtaining user profile");
|
||||
Profile proFile = authLogin();
|
||||
return proFile;
|
||||
} else {
|
||||
throw new SocialAuthException("Access token not found");
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract Profile authLogin() throws Exception;
|
||||
|
||||
public Response api(final String url, final String methodType, final Map<String, String> params, final Map<String, String> headerParams, final String body) throws Exception {
|
||||
try {
|
||||
return authenticationStrategy.executeFeed(url, methodType, params, headerParams, body);
|
||||
} catch (Exception e) {
|
||||
throw new SocialAuthException("Error while making request to URL : " + url, e);
|
||||
}
|
||||
}
|
||||
|
||||
public List<Contact> getContactList() throws Exception {
|
||||
throw Lang.makeThrow(SocialAuthException.class, "Get contact list is not implemented for %s", getPlatform());
|
||||
}
|
||||
|
||||
public void logout() {
|
||||
accessGrant = null;
|
||||
authenticationStrategy.logout();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPermission(Permission permission) {
|
||||
this.scope = permission;
|
||||
authenticationStrategy.setPermission(this.scope);
|
||||
authenticationStrategy.setScope(getScope());
|
||||
}
|
||||
|
||||
public Profile getUserProfile() throws Exception {
|
||||
return userProfile;
|
||||
}
|
||||
|
||||
public AccessGrant getAccessGrant() {
|
||||
return accessGrant;
|
||||
}
|
||||
|
||||
public String getProviderId() {
|
||||
return config.getId();
|
||||
}
|
||||
|
||||
protected String getScope() {
|
||||
StringBuffer result = new StringBuffer();
|
||||
String arr[] = null;
|
||||
if (Permission.AUTHENTICATE_ONLY.equals(scope)) {
|
||||
arr = AuthPerms;
|
||||
} else if (Permission.CUSTOM.equals(scope) && config.getCustomPermissions() != null) {
|
||||
arr = config.getCustomPermissions().split(",");
|
||||
} else {
|
||||
arr = AllPerms;
|
||||
}
|
||||
if (arr.length > 0)
|
||||
result.append(arr[0]);
|
||||
for (int i = 1; i < arr.length; i++) {
|
||||
result.append(",").append(arr[i]);
|
||||
}
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
protected String verifyResponseMethod() {
|
||||
return "GET";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAccessGrant(AccessGrant accessGrant) throws AccessTokenExpireException, SocialAuthException {
|
||||
this.accessGrant = accessGrant;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Response updateStatus(String arg0) throws Exception {
|
||||
throw Lang.makeThrow(SocialAuthException.class, "Update Status is not implemented for %s", getPlatform());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Response uploadImage(String arg0, String arg1, InputStream arg2) throws Exception {
|
||||
throw Lang.makeThrow(SocialAuthException.class, "Update Image is not implemented for %s", getPlatform());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected OAuthStrategyBase getOauthStrategy() {
|
||||
return authenticationStrategy;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<String> getPluginsList() {
|
||||
List<String> list = new ArrayList<String>();
|
||||
if (config.getRegisteredPlugins() != null && config.getRegisteredPlugins().length > 0) {
|
||||
list.addAll(Arrays.asList(config.getRegisteredPlugins()));
|
||||
}
|
||||
return list;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,92 @@
|
|||
package com.rekoe.cms.socialauth.qq;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.commons.lang3.math.NumberUtils;
|
||||
import org.brickred.socialauth.Profile;
|
||||
import org.brickred.socialauth.exception.SocialAuthException;
|
||||
import org.brickred.socialauth.oauthstrategy.OAuth2;
|
||||
import org.brickred.socialauth.util.Constants;
|
||||
import org.brickred.socialauth.util.OAuthConfig;
|
||||
import org.brickred.socialauth.util.Response;
|
||||
import org.nutz.json.Json;
|
||||
import org.nutz.log.Log;
|
||||
import org.nutz.log.Logs;
|
||||
|
||||
import com.rekoe.cms.socialauth.AbstractOAuthProvider;
|
||||
|
||||
/**
|
||||
* 实现QQ帐号登录,OAuth2
|
||||
*
|
||||
* @author wendal
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
public class QQAuthProvider extends AbstractOAuthProvider {
|
||||
|
||||
private final static Log log = Logs.get();
|
||||
private String PROFILE_URL= "https://graph.qq.com/oauth2.0/me";
|
||||
static {
|
||||
ENDPOINTS.put(Constants.OAUTH_AUTHORIZATION_URL, "https://graph.qq.com/oauth2.0/authorize");
|
||||
ENDPOINTS.put(Constants.OAUTH_ACCESS_TOKEN_URL, "https://graph.qq.com/oauth2.0/token");
|
||||
AllPerms = new String[] { "get_user_info", "get_info" };
|
||||
AuthPerms = new String[] { "get_user_info", "get_info" };
|
||||
}
|
||||
|
||||
public QQAuthProvider(final OAuthConfig providerConfig) throws Exception {
|
||||
super(providerConfig);
|
||||
authenticationStrategy = new OAuth2(config, ENDPOINTS);
|
||||
authenticationStrategy.setPermission(scope);
|
||||
authenticationStrategy.setScope(getScope());
|
||||
}
|
||||
|
||||
protected Profile authLogin() throws Exception {
|
||||
String presp;
|
||||
try {
|
||||
Response response = authenticationStrategy.executeFeed(PROFILE_URL);
|
||||
presp = response.getResponseBodyAsString(Constants.ENCODING);
|
||||
if (presp != null) {
|
||||
presp = presp.trim().intern();
|
||||
if (presp.startsWith("callback(") && presp.endsWith(");")) {
|
||||
presp = presp.substring(presp.indexOf("{"), presp.indexOf("}") + 1);
|
||||
Map<String, String> map = Json.fromJsonAsMap(String.class, presp);
|
||||
if (map.get("openid") != null) {
|
||||
Profile p = new Profile();
|
||||
p.setValidatedId(map.get("openid")); // QQ定义的
|
||||
p.setProviderId(getProviderId());
|
||||
userProfile = p;
|
||||
try {
|
||||
Map<String, String> params = new HashMap<String, String>();
|
||||
params.put("format", "json");
|
||||
params.put("openid", map.get("openid"));
|
||||
params.put("oauth_consumer_key", config.get_consumerKey());
|
||||
response = authenticationStrategy.executeFeed("https://graph.qq.com/user/get_user_info", "GET", params, null, null);
|
||||
presp = response.getResponseBodyAsString(Constants.ENCODING);
|
||||
Map<String, String> user_info = Json.fromJsonAsMap(String.class, presp);
|
||||
boolean isRight = NumberUtils.toInt(user_info.get("ret"), -1) == 0;
|
||||
if (isRight) { // 获取成功
|
||||
if (user_info.get("nickname") != null)
|
||||
p.setDisplayName(user_info.get("nickname"));
|
||||
if (user_info.get("figureurl") != null)
|
||||
p.setProfileImageURL(user_info.get("figureurl"));
|
||||
if (user_info.get("gender") != null)
|
||||
p.setGender(user_info.get("gender"));
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
log.error(e);
|
||||
}
|
||||
return p;
|
||||
}
|
||||
}
|
||||
}
|
||||
throw new SocialAuthException("QQ Error : " + presp);
|
||||
} catch (Exception e) {
|
||||
throw new SocialAuthException("Error while getting profile from " + PROFILE_URL, e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getPlatform() {
|
||||
return "QQ";
|
||||
}
|
||||
}
|
|
@ -0,0 +1,126 @@
|
|||
package com.rekoe.cms.socialauth.qqweibo;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.brickred.socialauth.Profile;
|
||||
import org.brickred.socialauth.exception.ServerDataException;
|
||||
import org.brickred.socialauth.exception.SocialAuthException;
|
||||
import org.brickred.socialauth.exception.UserDeniedPermissionException;
|
||||
import org.brickred.socialauth.oauthstrategy.OAuth1;
|
||||
import org.brickred.socialauth.oauthstrategy.OAuthStrategyBase;
|
||||
import org.brickred.socialauth.util.Constants;
|
||||
import org.brickred.socialauth.util.OAuthConfig;
|
||||
import org.brickred.socialauth.util.Response;
|
||||
import org.nutz.json.Json;
|
||||
import org.nutz.log.Log;
|
||||
import org.nutz.log.Logs;
|
||||
|
||||
import com.rekoe.cms.socialauth.AbstractOAuthProvider;
|
||||
|
||||
/**
|
||||
* 实现腾讯微博帐号登录,OAuth1
|
||||
*
|
||||
* @author wendal
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
public class QQWeiboAuthProvider extends AbstractOAuthProvider {
|
||||
|
||||
private static final Log log = Logs.get();
|
||||
private final String PROFILE_URL = "http://open.t.qq.com/api/user/info?format=json";
|
||||
public QQWeiboAuthProvider(final OAuthConfig providerConfig) throws Exception {
|
||||
super(providerConfig);
|
||||
ENDPOINTS.put(Constants.OAUTH_REQUEST_TOKEN_URL, "https://open.t.qq.com/cgi-bin/request_token");
|
||||
ENDPOINTS.put(Constants.OAUTH_AUTHORIZATION_URL, "https://open.t.qq.com/cgi-bin/authorize");
|
||||
ENDPOINTS.put(Constants.OAUTH_ACCESS_TOKEN_URL, "https://open.t.qq.com/cgi-bin/access_token");
|
||||
AllPerms = new String[] {};
|
||||
AuthPerms = new String[] {};
|
||||
authenticationStrategy = new OAuth1(config, ENDPOINTS);
|
||||
authenticationStrategy.setPermission(scope);
|
||||
authenticationStrategy.setScope(getScope());
|
||||
}
|
||||
|
||||
protected Profile doVerifyResponse(final Map<String, String> requestParams) throws Exception {
|
||||
log.info("Retrieving Access Token in verify response function");
|
||||
if (requestParams.get("error_reason") != null && "user_denied".equals(requestParams.get("error_reason"))) {
|
||||
throw new UserDeniedPermissionException();
|
||||
}
|
||||
accessGrant = authenticationStrategy.verifyResponse(requestParams, verifyResponseMethod());
|
||||
|
||||
if (accessGrant != null) {
|
||||
log.debug("Obtaining user profile");
|
||||
// try {
|
||||
// String presp =
|
||||
// authenticationStrategy.executeFeed(PROFILE_URL).getResponseBodyAsString("utf8");
|
||||
// System.out.println(Json.toJson(Json.fromJson(presp)));
|
||||
// } catch (Throwable e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
Profile p = new Profile();
|
||||
p.setValidatedId(requestParams.get("openid"));
|
||||
p.setProviderId(getProviderId());
|
||||
userProfile = p;
|
||||
return p;
|
||||
} else {
|
||||
throw new SocialAuthException("Access token not found");
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
protected Profile authLogin() throws Exception {
|
||||
String presp;
|
||||
try {
|
||||
Response response = authenticationStrategy.executeFeed(PROFILE_URL);
|
||||
presp = response.getResponseBodyAsString(Constants.ENCODING);
|
||||
} catch (Exception e) {
|
||||
throw new SocialAuthException("Error while getting profile from " + PROFILE_URL, e);
|
||||
}
|
||||
try {
|
||||
// System.out.println("User Profile : " + presp);
|
||||
Map<String, Object> data = Json.fromJson(Map.class, presp);
|
||||
if (!"ok".equals(data.get("msg")))
|
||||
throw new SocialAuthException("Error: " + presp);
|
||||
if (userProfile == null)
|
||||
userProfile = new Profile();
|
||||
data = (Map<String, Object>) data.get("data");
|
||||
userProfile.setValidatedId(data.get("uid").toString());
|
||||
return userProfile;
|
||||
} catch (Exception ex) {
|
||||
throw new ServerDataException("Failed to parse the user profile json : " + presp, ex);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Response updateStatus(String arg0) throws Exception {
|
||||
log.warn("WARNING: Not implemented for QQAuthProvider");
|
||||
throw new SocialAuthException("Update Status is not implemented for QQAuthProvider");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Response uploadImage(String arg0, String arg1, InputStream arg2) throws Exception {
|
||||
log.warn("WARNING: Not implemented for QQAuthProvider");
|
||||
throw new SocialAuthException("Upload Image is not implemented for QQAuthProvider");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected OAuthStrategyBase getOauthStrategy() {
|
||||
return authenticationStrategy;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<String> getPluginsList() {
|
||||
List<String> list = new ArrayList<String>();
|
||||
if (config.getRegisteredPlugins() != null && config.getRegisteredPlugins().length > 0) {
|
||||
list.addAll(Arrays.asList(config.getRegisteredPlugins()));
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getPlatform() {
|
||||
return "qqweibo";
|
||||
}
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
package com.rekoe.common;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
public class AppleVO implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 6286981086440847759L;
|
||||
|
||||
private boolean validate;
|
||||
private List<PackageVO> items;
|
||||
|
||||
public boolean isValidate() {
|
||||
return validate;
|
||||
}
|
||||
|
||||
public void setValidate(boolean validate) {
|
||||
this.validate = validate;
|
||||
}
|
||||
|
||||
public List<PackageVO> getItems() {
|
||||
return items;
|
||||
}
|
||||
|
||||
public void setItems(List<PackageVO> items) {
|
||||
this.items = items;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,37 @@
|
|||
package com.rekoe.common;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
public class GooglePVO implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 6286981086440847759L;
|
||||
|
||||
private boolean validate;
|
||||
private String googlePublicKey;
|
||||
private List<PackageVO> items;
|
||||
|
||||
public boolean isValidate() {
|
||||
return validate;
|
||||
}
|
||||
|
||||
public void setValidate(boolean validate) {
|
||||
this.validate = validate;
|
||||
}
|
||||
|
||||
public String getGooglePublicKey() {
|
||||
return googlePublicKey;
|
||||
}
|
||||
|
||||
public void setGooglePublicKey(String googlePublicKey) {
|
||||
this.googlePublicKey = googlePublicKey;
|
||||
}
|
||||
|
||||
public List<PackageVO> getItems() {
|
||||
return items;
|
||||
}
|
||||
|
||||
public void setItems(List<PackageVO> items) {
|
||||
this.items = items;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,102 @@
|
|||
package com.rekoe.common;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
public class GoogleVO implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 6286981086440847759L;
|
||||
|
||||
private boolean validate;
|
||||
private String refreshToken;
|
||||
private String productName;
|
||||
private String packageName;
|
||||
private String clientId;
|
||||
private String clientSecret;
|
||||
private String redirectUri;
|
||||
private String scope;
|
||||
private String tokenType;
|
||||
|
||||
private List<PackageVO> items;
|
||||
|
||||
public boolean isValidate() {
|
||||
return validate;
|
||||
}
|
||||
|
||||
public void setValidate(boolean validate) {
|
||||
this.validate = validate;
|
||||
}
|
||||
|
||||
public List<PackageVO> getItems() {
|
||||
return items;
|
||||
}
|
||||
|
||||
public void setItems(List<PackageVO> items) {
|
||||
this.items = items;
|
||||
}
|
||||
|
||||
public String getRefreshToken() {
|
||||
return refreshToken;
|
||||
}
|
||||
|
||||
public void setRefreshToken(String refreshToken) {
|
||||
this.refreshToken = refreshToken;
|
||||
}
|
||||
|
||||
public String getProductName() {
|
||||
return productName;
|
||||
}
|
||||
|
||||
public void setProductName(String productName) {
|
||||
this.productName = productName;
|
||||
}
|
||||
|
||||
public String getPackageName() {
|
||||
return packageName;
|
||||
}
|
||||
|
||||
public void setPackageName(String packageName) {
|
||||
this.packageName = packageName;
|
||||
}
|
||||
|
||||
public String getClientId() {
|
||||
return clientId;
|
||||
}
|
||||
|
||||
public void setClientId(String clientId) {
|
||||
this.clientId = clientId;
|
||||
}
|
||||
|
||||
public String getClientSecret() {
|
||||
return clientSecret;
|
||||
}
|
||||
|
||||
public void setClientSecret(String clientSecret) {
|
||||
this.clientSecret = clientSecret;
|
||||
}
|
||||
|
||||
public String getRedirectUri() {
|
||||
return redirectUri;
|
||||
}
|
||||
|
||||
public void setRedirectUri(String redirectUri) {
|
||||
this.redirectUri = redirectUri;
|
||||
}
|
||||
|
||||
public String getScope() {
|
||||
return scope;
|
||||
}
|
||||
|
||||
public void setScope(String scope) {
|
||||
this.scope = scope;
|
||||
}
|
||||
|
||||
public String getTokenType() {
|
||||
return tokenType;
|
||||
}
|
||||
|
||||
public void setTokenType(String tokenType) {
|
||||
this.tokenType = tokenType;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,56 @@
|
|||
package com.rekoe.common;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import org.nutz.mvc.Mvcs;
|
||||
/**
|
||||
* @author 科技㊣²º¹³
|
||||
* 2014年2月3日 下午4:48:45
|
||||
* http://www.rekoe.com
|
||||
* QQ:5382211
|
||||
*/
|
||||
public class Message {
|
||||
|
||||
private Type type;
|
||||
private String content;
|
||||
|
||||
public enum Type {
|
||||
success, warn, error;
|
||||
}
|
||||
|
||||
public Message() {
|
||||
}
|
||||
|
||||
public Message(Message.Type type, String content,HttpServletRequest req) {
|
||||
this.type = type;
|
||||
this.content = Mvcs.getMessage(req, content);
|
||||
}
|
||||
|
||||
public static Message success(String content,HttpServletRequest req) {
|
||||
return new Message(Message.Type.success, content,req);
|
||||
}
|
||||
|
||||
public static Message warn(String content,HttpServletRequest req) {
|
||||
return new Message(Message.Type.warn, content, req);
|
||||
}
|
||||
|
||||
public static Message error(String content,HttpServletRequest req) {
|
||||
return new Message(Message.Type.error, content, req);
|
||||
}
|
||||
|
||||
public Message.Type getType() {
|
||||
return this.type;
|
||||
}
|
||||
|
||||
public void setType(Message.Type type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public String getContent() {
|
||||
return this.content;
|
||||
}
|
||||
|
||||
public void setContent(String content) {
|
||||
this.content = content;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,34 @@
|
|||
package com.rekoe.common;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
public class PackageVO implements Serializable {
|
||||
private static final long serialVersionUID = 4225042323738026254L;
|
||||
private String productId;
|
||||
private int itemid;
|
||||
private float money;
|
||||
|
||||
public String getProductId() {
|
||||
return productId;
|
||||
}
|
||||
|
||||
public void setProductId(String productId) {
|
||||
this.productId = productId;
|
||||
}
|
||||
|
||||
public int getItemid() {
|
||||
return itemid;
|
||||
}
|
||||
|
||||
public void setItemid(int itemid) {
|
||||
this.itemid = itemid;
|
||||
}
|
||||
|
||||
public float getMoney() {
|
||||
return money;
|
||||
}
|
||||
|
||||
public void setMoney(float money) {
|
||||
this.money = money;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
package com.rekoe.common;
|
||||
|
||||
public class PlatformVO {
|
||||
|
||||
private String type;
|
||||
private String name;
|
||||
|
||||
public PlatformVO(String type, String name) {
|
||||
super();
|
||||
this.type = type;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public PlatformVO() {
|
||||
super();
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,62 @@
|
|||
package com.rekoe.common.page;
|
||||
/**
|
||||
* @author 科技㊣²º¹³
|
||||
* 2014年2月3日 下午4:48:45
|
||||
* http://www.rekoe.com
|
||||
* QQ:5382211
|
||||
*/
|
||||
public interface Paginable {
|
||||
|
||||
/**
|
||||
* 总记录数
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public int getTotalCount();
|
||||
|
||||
/**
|
||||
* 总页数
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public int getTotalPage();
|
||||
|
||||
/**
|
||||
* 每页记录数
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public int getPageSize();
|
||||
|
||||
/**
|
||||
* 当前页号
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public int getPageNo();
|
||||
|
||||
/**
|
||||
* 是否第一页
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public boolean isFirstPage();
|
||||
|
||||
/**
|
||||
* 是否最后一页
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public boolean isLastPage();
|
||||
|
||||
/**
|
||||
* 返回下页的页号
|
||||
*/
|
||||
public int getNextPage();
|
||||
|
||||
/**
|
||||
* 返回上页的页号
|
||||
*/
|
||||
public int getPrePage();
|
||||
|
||||
}
|
|
@ -0,0 +1,80 @@
|
|||
package com.rekoe.common.page;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author 科技㊣²º¹³
|
||||
* 2014年2月3日 下午4:48:45
|
||||
* http://www.rekoe.com
|
||||
* QQ:5382211
|
||||
*/
|
||||
public class Pagination extends SimplePage implements java.io.Serializable {
|
||||
|
||||
private static final long serialVersionUID = -1585539529849523194L;
|
||||
|
||||
public Pagination() {
|
||||
}
|
||||
|
||||
/**
|
||||
* 构造器
|
||||
*
|
||||
* @param pageNo
|
||||
* 页码
|
||||
* @param pageSize
|
||||
* 每页几条数据
|
||||
* @param totalCount
|
||||
* 总共几条数据
|
||||
*/
|
||||
public Pagination(int pageNo, int pageSize, int totalCount) {
|
||||
super(pageNo, pageSize, totalCount);
|
||||
}
|
||||
|
||||
/**
|
||||
* 构造器
|
||||
*
|
||||
* @param pageNo
|
||||
* 页码
|
||||
* @param pageSize
|
||||
* 每页几条数据
|
||||
* @param totalCount
|
||||
* 总共几条数据
|
||||
* @param list
|
||||
* 分页内容
|
||||
*/
|
||||
public Pagination(int pageNo, int pageSize, int totalCount, List<?> list) {
|
||||
super(pageNo, pageSize, totalCount);
|
||||
this.list = list;
|
||||
}
|
||||
|
||||
/**
|
||||
* 第一条数据位置
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public int getFirstResult() {
|
||||
return (pageNo - 1) * pageSize;
|
||||
}
|
||||
|
||||
/**
|
||||
* 当前页的数据
|
||||
*/
|
||||
private List<?> list;
|
||||
|
||||
/**
|
||||
* 获得分页内容
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public List<?> getList() {
|
||||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置分页内容
|
||||
*
|
||||
* @param list
|
||||
*/
|
||||
public void setList(List<?> list) {
|
||||
this.list = list;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,181 @@
|
|||
package com.rekoe.common.page;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
/**
|
||||
* @author 科技㊣²º¹³
|
||||
* 2014年2月3日 下午4:48:45
|
||||
* http://www.rekoe.com
|
||||
* QQ:5382211
|
||||
*/
|
||||
public class SimplePage implements Paginable {
|
||||
|
||||
public static final int DEF_COUNT = 20;
|
||||
private List<Integer> localArrayList = new ArrayList<Integer>();
|
||||
|
||||
public List<Integer> getSegment() {
|
||||
return localArrayList;
|
||||
}
|
||||
/**
|
||||
* 检查页码 checkPageNo
|
||||
*
|
||||
* @param pageNo
|
||||
* @return if pageNo==null or pageNo<1 then return 1 else return pageNo
|
||||
*/
|
||||
public static int cpn(Integer pageNo) {
|
||||
return (pageNo == null || pageNo < 1) ? 1 : pageNo;
|
||||
}
|
||||
|
||||
public SimplePage() {
|
||||
}
|
||||
|
||||
/**
|
||||
* 构造器
|
||||
*
|
||||
* @param pageNo
|
||||
* 页码
|
||||
* @param pageSize
|
||||
* 每页几条数据
|
||||
* @param totalCount
|
||||
* 总共几条数据
|
||||
*/
|
||||
public SimplePage(int pageNo, int pageSize, int totalCount) {
|
||||
setTotalCount(totalCount);
|
||||
setPageSize(pageSize);
|
||||
setPageNo(pageNo);
|
||||
adjustPageNo();
|
||||
int totalPages = getTotalPage();
|
||||
minPage = minPage < 1 ? 1 : minPage;
|
||||
maxPage = maxPage > totalPages ? totalPages : maxPage;
|
||||
for (int i = minPage; i <= maxPage; i++) {
|
||||
localArrayList.add(i);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 调整页码,使不超过最大页数
|
||||
*/
|
||||
public void adjustPageNo() {
|
||||
if (pageNo == 1) {
|
||||
return;
|
||||
}
|
||||
int tp = getTotalPage();
|
||||
if (pageNo > tp) {
|
||||
pageNo = tp;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得页码
|
||||
*/
|
||||
public int getPageNo() {
|
||||
return pageNo;
|
||||
}
|
||||
|
||||
/**
|
||||
* 每页几条数据
|
||||
*/
|
||||
public int getPageSize() {
|
||||
return pageSize;
|
||||
}
|
||||
|
||||
/**
|
||||
* 总共几条数据
|
||||
*/
|
||||
public int getTotalCount() {
|
||||
return totalCount;
|
||||
}
|
||||
|
||||
/**
|
||||
* 总共几页
|
||||
*/
|
||||
public int getTotalPage() {
|
||||
int totalPage = totalCount / pageSize;
|
||||
if (totalPage == 0 || totalCount % pageSize != 0) {
|
||||
totalPage++;
|
||||
}
|
||||
return totalPage;
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否第一页
|
||||
*/
|
||||
public boolean isFirstPage() {
|
||||
return pageNo <= 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否最后一页
|
||||
*/
|
||||
public boolean isLastPage() {
|
||||
return pageNo >= getTotalPage();
|
||||
}
|
||||
|
||||
/**
|
||||
* 下一页页码
|
||||
*/
|
||||
public int getNextPage() {
|
||||
if (isLastPage()) {
|
||||
return pageNo;
|
||||
} else {
|
||||
return pageNo + 1;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 上一页页码
|
||||
*/
|
||||
public int getPrePage() {
|
||||
if (isFirstPage()) {
|
||||
return pageNo;
|
||||
} else {
|
||||
return pageNo - 1;
|
||||
}
|
||||
}
|
||||
|
||||
protected int totalCount = 0;
|
||||
protected int pageSize = 20;
|
||||
protected int pageNo = 1;
|
||||
|
||||
/**
|
||||
* if totalCount<0 then totalCount=0
|
||||
*
|
||||
* @param totalCount
|
||||
*/
|
||||
public void setTotalCount(int totalCount) {
|
||||
if (totalCount < 0) {
|
||||
this.totalCount = 0;
|
||||
} else {
|
||||
this.totalCount = totalCount;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* if pageSize< 1 then pageSize=DEF_COUNT
|
||||
*
|
||||
* @param pageSize
|
||||
*/
|
||||
public void setPageSize(int pageSize) {
|
||||
if (pageSize < 1) {
|
||||
this.pageSize = DEF_COUNT;
|
||||
} else {
|
||||
this.pageSize = pageSize;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* if pageNo < 1 then pageNo=1
|
||||
*
|
||||
* @param pageNo
|
||||
*/
|
||||
public void setPageNo(int pageNo) {
|
||||
if (pageNo < 1) {
|
||||
this.pageNo = 1;
|
||||
} else {
|
||||
this.pageNo = pageNo;
|
||||
}
|
||||
}
|
||||
|
||||
int minPage = pageNo - (int) Math.floor((pageSize - 1) / 2.0D);
|
||||
int maxPage = pageNo + (int) Math.ceil((pageSize - 1) / 2.0D);
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
package com.rekoe.domain;
|
||||
|
||||
public enum AuthType {
|
||||
|
||||
DEFAULT("DEFAULT"), TOKEN("TOKEN"), QQ_HTML5("QQ_HTML5");
|
||||
|
||||
public String display;
|
||||
|
||||
AuthType(String display) {
|
||||
this.display = display;
|
||||
}
|
||||
|
||||
public String getDisplay() {
|
||||
return display;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,64 @@
|
|||
package com.rekoe.domain;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import org.nutz.dao.entity.annotation.Column;
|
||||
import org.nutz.dao.entity.annotation.EL;
|
||||
import org.nutz.dao.entity.annotation.Name;
|
||||
import org.nutz.dao.entity.annotation.Prev;
|
||||
import org.nutz.dao.entity.annotation.Table;
|
||||
|
||||
/**
|
||||
* @author 科技㊣²º¹³<br />
|
||||
* 2014年4月19日 上午8:54:23<br />
|
||||
* http://www.rekoe.com<br />
|
||||
* QQ:5382211<br />
|
||||
*/
|
||||
@Table("cdkey_category")
|
||||
public class CdkeyCategory implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 7685127380108984960L;
|
||||
@Name
|
||||
@Prev(els = { @EL("uuid()") })
|
||||
private String id;
|
||||
|
||||
@Column
|
||||
private String name;
|
||||
|
||||
@Column(hump = true)
|
||||
private int cdkeyType;
|
||||
|
||||
public CdkeyCategory() {
|
||||
super();
|
||||
}
|
||||
|
||||
public CdkeyCategory(String name, int cdkeyType) {
|
||||
super();
|
||||
this.name = name;
|
||||
this.cdkeyType = cdkeyType;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public int getCdkeyType() {
|
||||
return cdkeyType;
|
||||
}
|
||||
|
||||
public void setCdkeyType(int cdkeyType) {
|
||||
this.cdkeyType = cdkeyType;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,63 @@
|
|||
package com.rekoe.domain;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import org.nutz.dao.entity.annotation.ColDefine;
|
||||
import org.nutz.dao.entity.annotation.ColType;
|
||||
import org.nutz.dao.entity.annotation.Column;
|
||||
import org.nutz.dao.entity.annotation.Id;
|
||||
import org.nutz.dao.entity.annotation.Index;
|
||||
import org.nutz.dao.entity.annotation.Table;
|
||||
import org.nutz.dao.entity.annotation.TableIndexes;
|
||||
|
||||
@Table("cdkey_${taskid}")
|
||||
@TableIndexes({ @Index(name = "cdk_${taskid}_index", fields = { "cdkey" }, unique = true), @Index(name = "cdk_${taskid}_used_index", fields = { "used" }, unique = false) })
|
||||
public class CdkeyEntity {
|
||||
|
||||
@Id
|
||||
private long id;
|
||||
@Column
|
||||
private String cdkey;
|
||||
|
||||
@Column("is_used")
|
||||
@ColDefine(type = ColType.BOOLEAN)
|
||||
private boolean used;
|
||||
|
||||
@Column(hump = true)
|
||||
@ColDefine(type = ColType.TIMESTAMP)
|
||||
private Date createTime;
|
||||
|
||||
public boolean isUsed() {
|
||||
return used;
|
||||
}
|
||||
|
||||
public void setUsed(boolean used) {
|
||||
this.used = used;
|
||||
}
|
||||
|
||||
public CdkeyEntity() {
|
||||
super();
|
||||
}
|
||||
|
||||
public CdkeyEntity(String cdkey, Date createTime) {
|
||||
super();
|
||||
this.cdkey = cdkey;
|
||||
this.createTime = createTime;
|
||||
}
|
||||
|
||||
public long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public Date getCreateTime() {
|
||||
return createTime;
|
||||
}
|
||||
|
||||
public void setCreateTime(Date createTime) {
|
||||
this.createTime = createTime;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,88 @@
|
|||
package com.rekoe.domain;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
import org.nutz.dao.entity.annotation.ColDefine;
|
||||
import org.nutz.dao.entity.annotation.ColType;
|
||||
import org.nutz.dao.entity.annotation.Column;
|
||||
import org.nutz.dao.entity.annotation.EL;
|
||||
import org.nutz.dao.entity.annotation.Id;
|
||||
import org.nutz.dao.entity.annotation.Prev;
|
||||
import org.nutz.dao.entity.annotation.Table;
|
||||
|
||||
@Table("cdkey_log")
|
||||
public class CdkeyLog implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = -6797252917202955579L;
|
||||
|
||||
@Id
|
||||
private long id;
|
||||
@Column
|
||||
private int pid;
|
||||
@Column(hump = true)
|
||||
private String providerId;
|
||||
@Column
|
||||
private String mac;
|
||||
|
||||
@Column
|
||||
@ColDefine(type = ColType.TIMESTAMP)
|
||||
@Prev(els = @EL("$me.now()"))
|
||||
private Date createTime;
|
||||
|
||||
public CdkeyLog() {
|
||||
super();
|
||||
}
|
||||
|
||||
public CdkeyLog(int pid, String providerId, String mac) {
|
||||
super();
|
||||
this.pid = pid;
|
||||
this.providerId = providerId;
|
||||
this.mac = mac;
|
||||
}
|
||||
|
||||
public Date now() {
|
||||
return new Date();
|
||||
}
|
||||
|
||||
public long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public int getPid() {
|
||||
return pid;
|
||||
}
|
||||
|
||||
public void setPid(int pid) {
|
||||
this.pid = pid;
|
||||
}
|
||||
|
||||
public String getProviderId() {
|
||||
return providerId;
|
||||
}
|
||||
|
||||
public void setProviderId(String providerId) {
|
||||
this.providerId = providerId;
|
||||
}
|
||||
|
||||
public String getMac() {
|
||||
return mac;
|
||||
}
|
||||
|
||||
public void setMac(String mac) {
|
||||
this.mac = mac;
|
||||
}
|
||||
|
||||
public Date getCreateTime() {
|
||||
return createTime;
|
||||
}
|
||||
|
||||
public void setCreateTime(Date createTime) {
|
||||
this.createTime = createTime;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,222 @@
|
|||
package com.rekoe.domain;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.nutz.dao.entity.annotation.ColDefine;
|
||||
import org.nutz.dao.entity.annotation.ColType;
|
||||
import org.nutz.dao.entity.annotation.Column;
|
||||
import org.nutz.dao.entity.annotation.Comment;
|
||||
import org.nutz.dao.entity.annotation.Default;
|
||||
import org.nutz.dao.entity.annotation.Id;
|
||||
import org.nutz.dao.entity.annotation.Index;
|
||||
import org.nutz.dao.entity.annotation.Many;
|
||||
import org.nutz.dao.entity.annotation.ManyMany;
|
||||
import org.nutz.dao.entity.annotation.Table;
|
||||
import org.nutz.dao.entity.annotation.TableIndexes;
|
||||
import org.nutz.lang.util.NutMap;
|
||||
|
||||
import com.rekoe.valueadaptor.NutMapValueAdaptor;
|
||||
import com.rekoe.valueadaptor.StringJsonAdaptor;
|
||||
|
||||
@Table("system_server")
|
||||
@TableIndexes({ @Index(name = "g_pid_index", fields = { "pid" }, unique = true) })
|
||||
public class GameServer implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 4391955362256919755L;
|
||||
|
||||
@Id
|
||||
private int id;
|
||||
|
||||
@Column(hump = true)
|
||||
@Comment("平台名称")
|
||||
private String platformName;
|
||||
|
||||
@Column("platform_id")
|
||||
@Comment("平台编号")
|
||||
private int pid;
|
||||
|
||||
@Column("is_open")
|
||||
@Comment("是否开启")
|
||||
private boolean open;
|
||||
|
||||
@Column(hump = true)
|
||||
@Comment("充值地址")
|
||||
@ColDefine(width = 225)
|
||||
private String payUrl;
|
||||
|
||||
@Column(hump = true)
|
||||
@Comment("登陆服地址")
|
||||
@ColDefine(width = 225)
|
||||
private String loginUrl;
|
||||
|
||||
@ManyMany(target = User.class, relation = "system_user_server", from = "SERVERID", to = "USERID")
|
||||
private List<User> users;
|
||||
|
||||
@Many(target = OfficialServer.class, field = "pid")
|
||||
private List<OfficialServer> officialServers;
|
||||
|
||||
@Column("ver")
|
||||
@Comment("当前版本号")
|
||||
private String version;
|
||||
|
||||
@Column
|
||||
@Comment("是否提审")
|
||||
@ColDefine(type = ColType.BOOLEAN)
|
||||
private boolean verify;
|
||||
|
||||
@Column("is_black_open")
|
||||
@Comment("是否开启白名单")
|
||||
@ColDefine(type = ColType.BOOLEAN)
|
||||
private boolean blackOpen;
|
||||
|
||||
@Column("black_list")
|
||||
@Comment("白名单列表")
|
||||
@ColDefine(type = ColType.TEXT, adaptor = StringJsonAdaptor.class)
|
||||
private List<String> items = new ArrayList<String>();
|
||||
|
||||
@Column(hump = true)
|
||||
private String clientSecret;
|
||||
|
||||
@Column(hump = true)
|
||||
@Comment("认证方式")
|
||||
@Default("DEFAULT")
|
||||
protected AuthType authType;
|
||||
|
||||
@Column(hump = true)
|
||||
@ColDefine(type = ColType.TEXT, adaptor = NutMapValueAdaptor.class)
|
||||
private NutMap mobileAuth;
|
||||
|
||||
public NutMap getMobileAuth() {
|
||||
if (mobileAuth == null) {
|
||||
mobileAuth = NutMap.NEW();
|
||||
}
|
||||
return mobileAuth;
|
||||
}
|
||||
|
||||
public void setMobileAuth(NutMap config) {
|
||||
this.mobileAuth = config;
|
||||
}
|
||||
|
||||
public GameServer addMobileAuth(String id, NutMap config) {
|
||||
this.mobileAuth.addv(id, config);
|
||||
return this;
|
||||
}
|
||||
|
||||
public boolean isBlackOpen() {
|
||||
return blackOpen;
|
||||
}
|
||||
|
||||
public String getClientSecret() {
|
||||
return clientSecret;
|
||||
}
|
||||
|
||||
public void setClientSecret(String clientSecret) {
|
||||
this.clientSecret = clientSecret;
|
||||
}
|
||||
|
||||
public void setBlackOpen(boolean black) {
|
||||
this.blackOpen = black;
|
||||
}
|
||||
|
||||
public List<String> getItems() {
|
||||
return items;
|
||||
}
|
||||
|
||||
public AuthType getAuthType() {
|
||||
return authType;
|
||||
}
|
||||
|
||||
public void setAuthType(AuthType authType) {
|
||||
this.authType = authType;
|
||||
}
|
||||
|
||||
public void setItems(List<String> items) {
|
||||
this.items = items;
|
||||
}
|
||||
|
||||
public String getVersion() {
|
||||
return version;
|
||||
}
|
||||
|
||||
public void setVersion(String version) {
|
||||
this.version = version;
|
||||
}
|
||||
|
||||
public boolean isVerify() {
|
||||
return verify;
|
||||
}
|
||||
|
||||
public void setVerify(boolean verify) {
|
||||
this.verify = verify;
|
||||
}
|
||||
|
||||
public List<OfficialServer> getOfficialServers() {
|
||||
return officialServers;
|
||||
}
|
||||
|
||||
public void setOfficialServers(List<OfficialServer> officialServers) {
|
||||
this.officialServers = officialServers;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getPlatformName() {
|
||||
return platformName;
|
||||
}
|
||||
|
||||
public void setPlatformName(String platformName) {
|
||||
this.platformName = platformName;
|
||||
}
|
||||
|
||||
public boolean isOpen() {
|
||||
return open;
|
||||
}
|
||||
|
||||
public void setOpen(boolean open) {
|
||||
this.open = open;
|
||||
}
|
||||
|
||||
public List<User> getUsers() {
|
||||
return users;
|
||||
}
|
||||
|
||||
public void setUsers(List<User> users) {
|
||||
this.users = users;
|
||||
}
|
||||
|
||||
public int getPid() {
|
||||
return pid;
|
||||
}
|
||||
|
||||
public void setPid(int pid) {
|
||||
this.pid = pid;
|
||||
}
|
||||
|
||||
public String getPayUrl() {
|
||||
return payUrl;
|
||||
}
|
||||
|
||||
public void setPayUrl(String payUrl) {
|
||||
this.payUrl = payUrl;
|
||||
}
|
||||
|
||||
public String getLoginUrl() {
|
||||
return loginUrl;
|
||||
}
|
||||
|
||||
public void setLoginUrl(String loginUrl) {
|
||||
this.loginUrl = loginUrl;
|
||||
}
|
||||
|
||||
public boolean isUseMobileAuth() {
|
||||
return getMobileAuth().getBoolean("mobileAuth", false);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,138 @@
|
|||
package com.rekoe.domain;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
import org.nutz.dao.entity.annotation.ColDefine;
|
||||
import org.nutz.dao.entity.annotation.ColType;
|
||||
import org.nutz.dao.entity.annotation.Column;
|
||||
import org.nutz.dao.entity.annotation.Default;
|
||||
import org.nutz.dao.entity.annotation.Id;
|
||||
import org.nutz.dao.entity.annotation.Table;
|
||||
import org.nutz.json.JsonField;
|
||||
|
||||
/**
|
||||
* @author 科技㊣²º¹³<br/>
|
||||
* 2014年2月3日 下午4:48:45<br/>
|
||||
* http://www.rekoe.com<br/>
|
||||
* QQ:5382211
|
||||
*/
|
||||
@Table("sg_notice")
|
||||
public class Notice implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1566985676414681818L;
|
||||
|
||||
@Id(auto=true)
|
||||
private long id;
|
||||
|
||||
@Column(hump = true)
|
||||
@ColDefine(type = ColType.TIMESTAMP)
|
||||
@JsonField(ignore = true)
|
||||
private Date createDate;
|
||||
|
||||
@Column
|
||||
@Default("#FF0000")
|
||||
private String color;
|
||||
|
||||
@Column(hump = true)
|
||||
@ColDefine(type = ColType.TIMESTAMP)
|
||||
@JsonField(ignore = true)
|
||||
private Date modifyDate;
|
||||
|
||||
@Column
|
||||
@ColDefine(type = ColType.TEXT)
|
||||
@JsonField(ignore = true)
|
||||
private String content;
|
||||
|
||||
@Column("is_publication")
|
||||
@ColDefine(type = ColType.BOOLEAN)
|
||||
@JsonField(ignore = true)
|
||||
private boolean publication;
|
||||
|
||||
@Column("is_top")
|
||||
@ColDefine(type = ColType.BOOLEAN)
|
||||
@JsonField(ignore = true)
|
||||
private boolean top;
|
||||
|
||||
@Column
|
||||
@ColDefine(type = ColType.VARCHAR, width = 255)
|
||||
private String title;
|
||||
|
||||
@Column
|
||||
@Default("1001")
|
||||
@JsonField(ignore = true)
|
||||
private int pid;
|
||||
|
||||
public int getPid() {
|
||||
return pid;
|
||||
}
|
||||
|
||||
public void setPid(int pid) {
|
||||
this.pid = pid;
|
||||
}
|
||||
|
||||
public long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public Date getCreateDate() {
|
||||
return createDate;
|
||||
}
|
||||
|
||||
public void setCreateDate(Date createDate) {
|
||||
this.createDate = createDate;
|
||||
}
|
||||
|
||||
public Date getModifyDate() {
|
||||
return modifyDate;
|
||||
}
|
||||
|
||||
public void setModifyDate(Date modifyDate) {
|
||||
this.modifyDate = modifyDate;
|
||||
}
|
||||
|
||||
public String getContent() {
|
||||
return content;
|
||||
}
|
||||
|
||||
public void setContent(String content) {
|
||||
this.content = content;
|
||||
}
|
||||
|
||||
public boolean isPublication() {
|
||||
return publication;
|
||||
}
|
||||
|
||||
public void setPublication(boolean publication) {
|
||||
this.publication = publication;
|
||||
}
|
||||
|
||||
public boolean isTop() {
|
||||
return top;
|
||||
}
|
||||
|
||||
public void setTop(boolean top) {
|
||||
this.top = top;
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
public void setTitle(String title) {
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
public String getColor() {
|
||||
return color;
|
||||
}
|
||||
|
||||
public void setColor(String color) {
|
||||
this.color = color;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,64 @@
|
|||
package com.rekoe.domain;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import org.nutz.dao.entity.annotation.Column;
|
||||
import org.nutz.dao.entity.annotation.Id;
|
||||
import org.nutz.dao.entity.annotation.Index;
|
||||
import org.nutz.dao.entity.annotation.Table;
|
||||
import org.nutz.dao.entity.annotation.TableIndexes;
|
||||
|
||||
@Table("sg_oauth_client")
|
||||
@TableIndexes({ @Index(name = "sg_oauth_client_index", fields = { "clientName" }, unique = true), @Index(name = "sg_oc_secret_index", fields = { "clientId", "clientSecret" }, unique = false) })
|
||||
public class OAuthClient implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 2345879369118031587L;
|
||||
@Id
|
||||
private long id;
|
||||
|
||||
@Column(hump = true)
|
||||
private String clientName;
|
||||
|
||||
@Column(hump = true)
|
||||
private String clientId;
|
||||
|
||||
@Column(hump = true)
|
||||
private String clientSecret;
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getClientName() {
|
||||
return clientName;
|
||||
}
|
||||
|
||||
public void setClientName(String clientName) {
|
||||
this.clientName = clientName;
|
||||
}
|
||||
|
||||
public String getClientId() {
|
||||
return clientId;
|
||||
}
|
||||
|
||||
public void setClientId(String clientId) {
|
||||
this.clientId = clientId;
|
||||
}
|
||||
|
||||
public String getClientSecret() {
|
||||
return clientSecret;
|
||||
}
|
||||
|
||||
public void setClientSecret(String clientSecret) {
|
||||
this.clientSecret = clientSecret;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Client{" + "id=" + id + ", clientName='" + clientName + '\'' + ", clientId='" + clientId + '\'' + ", clientSecret='" + clientSecret + '\'' + '}';
|
||||
}
|
||||
}
|
|
@ -0,0 +1,135 @@
|
|||
package com.rekoe.domain;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import org.nutz.dao.entity.annotation.ColDefine;
|
||||
import org.nutz.dao.entity.annotation.ColType;
|
||||
import org.nutz.dao.entity.annotation.Column;
|
||||
import org.nutz.dao.entity.annotation.Comment;
|
||||
import org.nutz.dao.entity.annotation.Default;
|
||||
import org.nutz.dao.entity.annotation.EL;
|
||||
import org.nutz.dao.entity.annotation.Index;
|
||||
import org.nutz.dao.entity.annotation.Name;
|
||||
import org.nutz.dao.entity.annotation.Prev;
|
||||
import org.nutz.dao.entity.annotation.Table;
|
||||
import org.nutz.dao.entity.annotation.TableIndexes;
|
||||
import org.nutz.json.JsonField;
|
||||
|
||||
@Table("sg_oauth_user")
|
||||
@TableIndexes({ @Index(name = "sg_user_data_index", fields = { "userName" }, unique = true), @Index(name = "sg_user_phone_index", fields = { "userName", "phoneCode" }, unique = false) })
|
||||
public class OAuthUser implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = -2879607754801933480L;
|
||||
|
||||
@Name
|
||||
@Prev(els = @EL("uuid()"))
|
||||
@JsonField(ignore = true)
|
||||
private String id;
|
||||
|
||||
@Column(hump = true)
|
||||
@JsonField(value = "name")
|
||||
private String userName;
|
||||
|
||||
@Column
|
||||
@JsonField(ignore = true)
|
||||
private String password;
|
||||
|
||||
@Column
|
||||
@JsonField(ignore = true)
|
||||
private String salt;
|
||||
|
||||
@Column(hump = true)
|
||||
@ColDefine(type = ColType.INT, width = 16)
|
||||
@JsonField(ignore = true)
|
||||
private long phoneCode;
|
||||
|
||||
@Column(hump = true)
|
||||
@ColDefine(type = ColType.INT, width = 16)
|
||||
@JsonField(value = "uid")
|
||||
private long userId;
|
||||
|
||||
@Column("is_locked")
|
||||
@JsonField(value = "locked")
|
||||
private boolean locked;
|
||||
|
||||
@Column("is_bind")
|
||||
@JsonField(ignore = true)
|
||||
@Default("0")
|
||||
private boolean bind;
|
||||
|
||||
@Column(hump = true)
|
||||
@Comment("绑定前的渠道")
|
||||
private String bindProviderId;
|
||||
|
||||
public String getBindProviderId() {
|
||||
return bindProviderId;
|
||||
}
|
||||
|
||||
public void setBindProviderId(String bindProviderId) {
|
||||
this.bindProviderId = bindProviderId;
|
||||
}
|
||||
|
||||
public boolean isBind() {
|
||||
return bind;
|
||||
}
|
||||
|
||||
public void setBind(boolean bind) {
|
||||
this.bind = bind;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getUserName() {
|
||||
return userName;
|
||||
}
|
||||
|
||||
public void setUserName(String userName) {
|
||||
this.userName = userName;
|
||||
}
|
||||
|
||||
public String getPassword() {
|
||||
return password;
|
||||
}
|
||||
|
||||
public void setPassword(String password) {
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
public String getSalt() {
|
||||
return salt;
|
||||
}
|
||||
|
||||
public void setSalt(String salt) {
|
||||
this.salt = salt;
|
||||
}
|
||||
|
||||
public long getPhoneCode() {
|
||||
return phoneCode;
|
||||
}
|
||||
|
||||
public void setPhoneCode(long phoneCode) {
|
||||
this.phoneCode = phoneCode;
|
||||
}
|
||||
|
||||
public long getUserId() {
|
||||
return userId;
|
||||
}
|
||||
|
||||
public void setUserId(long userId) {
|
||||
this.userId = userId;
|
||||
}
|
||||
|
||||
public boolean isLocked() {
|
||||
return locked;
|
||||
}
|
||||
|
||||
public void setLocked(boolean locked) {
|
||||
this.locked = locked;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,120 @@
|
|||
package com.rekoe.domain;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import org.nutz.dao.entity.annotation.ColDefine;
|
||||
import org.nutz.dao.entity.annotation.ColType;
|
||||
import org.nutz.dao.entity.annotation.Column;
|
||||
import org.nutz.dao.entity.annotation.Comment;
|
||||
import org.nutz.dao.entity.annotation.Default;
|
||||
import org.nutz.dao.entity.annotation.Id;
|
||||
import org.nutz.dao.entity.annotation.Index;
|
||||
import org.nutz.dao.entity.annotation.One;
|
||||
import org.nutz.dao.entity.annotation.Table;
|
||||
import org.nutz.dao.entity.annotation.TableIndexes;
|
||||
|
||||
/**
|
||||
* 正式服
|
||||
*
|
||||
* @author kouxian
|
||||
*
|
||||
*/
|
||||
@Table("official_server")
|
||||
@TableIndexes({ @Index(name = "g_sid_pid_index", fields = { "pid", "sid" }, unique = true) })
|
||||
public class OfficialServer implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 6978032147399501026L;
|
||||
|
||||
@Id
|
||||
private long id;
|
||||
|
||||
@Column
|
||||
private int sid;
|
||||
|
||||
@Column
|
||||
@ColDefine(width = 225)
|
||||
private String url;
|
||||
|
||||
@Column
|
||||
private String name;
|
||||
|
||||
@Column
|
||||
private short status;
|
||||
|
||||
@Column("pid")
|
||||
private int pid;
|
||||
|
||||
@One(target = GameServer.class, field = "pid")
|
||||
private GameServer gameServer;
|
||||
|
||||
@Column(hump = true)
|
||||
@Default("0")
|
||||
@ColDefine(type = ColType.BOOLEAN)
|
||||
@Comment("是否开启白名单")
|
||||
private boolean openWhiteList;
|
||||
|
||||
public int getPid() {
|
||||
return pid;
|
||||
}
|
||||
|
||||
public void setPid(int pid) {
|
||||
this.pid = pid;
|
||||
}
|
||||
|
||||
public GameServer getGameServer() {
|
||||
return gameServer;
|
||||
}
|
||||
|
||||
public void setGameServer(GameServer gameServer) {
|
||||
this.gameServer = gameServer;
|
||||
}
|
||||
|
||||
public long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public int getSid() {
|
||||
return sid;
|
||||
}
|
||||
|
||||
public void setSid(int sid) {
|
||||
this.sid = sid;
|
||||
}
|
||||
|
||||
public String getUrl() {
|
||||
return url;
|
||||
}
|
||||
|
||||
public void setUrl(String url) {
|
||||
this.url = url;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public short getStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
public void setStatus(short status) {
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
public boolean isOpenWhiteList() {
|
||||
return openWhiteList;
|
||||
}
|
||||
|
||||
public void setOpenWhiteList(boolean openWhiteList) {
|
||||
this.openWhiteList = openWhiteList;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,111 @@
|
|||
package com.rekoe.domain;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
import org.nutz.dao.entity.annotation.ColDefine;
|
||||
import org.nutz.dao.entity.annotation.ColType;
|
||||
import org.nutz.dao.entity.annotation.Column;
|
||||
import org.nutz.dao.entity.annotation.Comment;
|
||||
import org.nutz.dao.entity.annotation.EL;
|
||||
import org.nutz.dao.entity.annotation.Index;
|
||||
import org.nutz.dao.entity.annotation.Name;
|
||||
import org.nutz.dao.entity.annotation.Prev;
|
||||
import org.nutz.dao.entity.annotation.Table;
|
||||
import org.nutz.dao.entity.annotation.TableIndexes;
|
||||
|
||||
@Table("pay_refund")
|
||||
@TableIndexes({ @Index(name = "pay_refund_index", fields = { "paymentid" }, unique = false), @Index(name = "pay_status_index", fields = { "status" }, unique = false) })
|
||||
public class PayRefund implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = -6311504223475095588L;
|
||||
@Name
|
||||
@Comment("ID主键")
|
||||
@Prev(els = { @EL("uuid()") })
|
||||
private String id;
|
||||
@Column
|
||||
@ColDefine(type = ColType.TIMESTAMP)
|
||||
@Comment("创建时间")
|
||||
private Date createTime;
|
||||
@Column
|
||||
private String passportid;
|
||||
@Column("payment_id")
|
||||
private String paymentid;
|
||||
@Column
|
||||
private String name;
|
||||
@Column(hump = true)
|
||||
private String requestId;
|
||||
|
||||
@Column(hump = true)
|
||||
@ColDefine(type = ColType.TEXT)
|
||||
private String changedFields;
|
||||
|
||||
@Column("do_status")
|
||||
@Comment("订单处理状态")
|
||||
private boolean status;
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public Date getCreateTime() {
|
||||
return createTime;
|
||||
}
|
||||
|
||||
public void setCreateTime(Date createTime) {
|
||||
this.createTime = createTime;
|
||||
}
|
||||
|
||||
public String getPassportid() {
|
||||
return passportid;
|
||||
}
|
||||
|
||||
public void setPassportid(String passportid) {
|
||||
this.passportid = passportid;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getPaymentid() {
|
||||
return paymentid;
|
||||
}
|
||||
|
||||
public void setPaymentid(String paymentid) {
|
||||
this.paymentid = paymentid;
|
||||
}
|
||||
|
||||
public String getRequestId() {
|
||||
return requestId;
|
||||
}
|
||||
|
||||
public void setRequestId(String requestId) {
|
||||
this.requestId = requestId;
|
||||
}
|
||||
|
||||
public boolean isStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
public void setStatus(boolean status) {
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
public String getChangedFields() {
|
||||
return changedFields;
|
||||
}
|
||||
|
||||
public void setChangedFields(String changedFields) {
|
||||
this.changedFields = changedFields;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,124 @@
|
|||
package com.rekoe.domain;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
import org.nutz.dao.entity.annotation.ColDefine;
|
||||
import org.nutz.dao.entity.annotation.ColType;
|
||||
import org.nutz.dao.entity.annotation.Column;
|
||||
import org.nutz.dao.entity.annotation.Id;
|
||||
import org.nutz.dao.entity.annotation.Index;
|
||||
import org.nutz.dao.entity.annotation.ManyMany;
|
||||
import org.nutz.dao.entity.annotation.One;
|
||||
import org.nutz.dao.entity.annotation.Table;
|
||||
import org.nutz.dao.entity.annotation.TableIndexes;
|
||||
|
||||
/**
|
||||
* @author 科技㊣²º¹³<br />
|
||||
* 2014年2月3日 下午4:48:45<br />
|
||||
* http://www.rekoe.com<br />
|
||||
* QQ:5382211
|
||||
*/
|
||||
@Table("system_permission")
|
||||
@TableIndexes({ @Index(name = "permission_name_index", fields = { "name" }, unique = true) })
|
||||
public class Permission implements Serializable {
|
||||
private static final long serialVersionUID = -8140799124476746216L;
|
||||
@Id
|
||||
private Long id;
|
||||
@Column
|
||||
@ColDefine(type = ColType.VARCHAR, width = 200)
|
||||
private String name;
|
||||
@Column
|
||||
@ColDefine(type = ColType.VARCHAR, width = 500)
|
||||
private String description;
|
||||
@ManyMany(target = Role.class, relation = "system_role_permission", from = "permissionid", to = "roleid")
|
||||
private List<Role> roles;
|
||||
@Column(hump = true)
|
||||
private String permissionCategoryId;
|
||||
@One(target = PermissionCategory.class, field = "permissionCategoryId")
|
||||
private PermissionCategory permissionCategory;
|
||||
@Column("is_locked")
|
||||
@ColDefine(type = ColType.BOOLEAN)
|
||||
private boolean locked;
|
||||
|
||||
public String getPermissionCategoryId() {
|
||||
return permissionCategoryId;
|
||||
}
|
||||
|
||||
public boolean isLocked() {
|
||||
return locked;
|
||||
}
|
||||
|
||||
public void setLocked(boolean locked) {
|
||||
this.locked = locked;
|
||||
}
|
||||
|
||||
public void setPermissionCategoryId(String permissionCategoryId) {
|
||||
this.permissionCategoryId = permissionCategoryId;
|
||||
}
|
||||
|
||||
public PermissionCategory getPermissionCategory() {
|
||||
return permissionCategory;
|
||||
}
|
||||
|
||||
public void setPermissionCategory(PermissionCategory permissionCategory) {
|
||||
this.permissionCategory = permissionCategory;
|
||||
}
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public List<Role> getRoles() {
|
||||
return roles;
|
||||
}
|
||||
|
||||
public void setRoles(List<Role> roles) {
|
||||
this.roles = roles;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + ((id == null) ? 0 : id.hashCode());
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (obj == null)
|
||||
return false;
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
Permission other = (Permission) obj;
|
||||
if (id == null) {
|
||||
if (other.id != null)
|
||||
return false;
|
||||
} else if (!id.equals(other.id))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,59 @@
|
|||
package com.rekoe.domain;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
import org.nutz.dao.entity.annotation.ColDefine;
|
||||
import org.nutz.dao.entity.annotation.ColType;
|
||||
import org.nutz.dao.entity.annotation.Column;
|
||||
import org.nutz.dao.entity.annotation.EL;
|
||||
import org.nutz.dao.entity.annotation.Many;
|
||||
import org.nutz.dao.entity.annotation.Name;
|
||||
import org.nutz.dao.entity.annotation.Prev;
|
||||
import org.nutz.dao.entity.annotation.Table;
|
||||
|
||||
/**
|
||||
* @author 科技㊣²º¹³
|
||||
* 2014年4月19日 上午8:54:23
|
||||
* http://www.rekoe.com
|
||||
* QQ:5382211
|
||||
*/
|
||||
@Table("permission_category")
|
||||
public class PermissionCategory implements Serializable{
|
||||
|
||||
private static final long serialVersionUID = 7685127380108984960L;
|
||||
@Name
|
||||
@Prev(els = { @EL("uuid()") })
|
||||
private String id;
|
||||
@Column
|
||||
private String name;
|
||||
@Many(target = Permission.class, field = "permissionCategoryId")
|
||||
private List<Permission> permissions;
|
||||
@Column("is_locked")
|
||||
@ColDefine(type = ColType.BOOLEAN)
|
||||
private boolean locked;
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
public List<Permission> getPermissions() {
|
||||
return permissions;
|
||||
}
|
||||
public void setPermissions(List<Permission> permissions) {
|
||||
this.permissions = permissions;
|
||||
}
|
||||
public boolean isLocked() {
|
||||
return locked;
|
||||
}
|
||||
public void setLocked(boolean locked) {
|
||||
this.locked = locked;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,90 @@
|
|||
package com.rekoe.domain;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import org.nutz.dao.entity.annotation.ColDefine;
|
||||
import org.nutz.dao.entity.annotation.ColType;
|
||||
import org.nutz.dao.entity.annotation.Column;
|
||||
import org.nutz.dao.entity.annotation.Comment;
|
||||
import org.nutz.dao.entity.annotation.EL;
|
||||
import org.nutz.dao.entity.annotation.Index;
|
||||
import org.nutz.dao.entity.annotation.Name;
|
||||
import org.nutz.dao.entity.annotation.Prev;
|
||||
import org.nutz.dao.entity.annotation.Table;
|
||||
import org.nutz.dao.entity.annotation.TableIndexes;
|
||||
import org.nutz.lang.util.NutMap;
|
||||
|
||||
import com.rekoe.valueadaptor.NutMapValueAdaptor;
|
||||
|
||||
@Table("platform_config")
|
||||
@TableIndexes({ @Index(name = "p_pid_index", fields = { "sid", "provider" }, unique = true) })
|
||||
public class PlatformConfig implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = -4694161925835479316L;
|
||||
|
||||
@Name
|
||||
@Prev(els = @EL("uuid()"))
|
||||
private String id;
|
||||
|
||||
@Column
|
||||
private int sid;
|
||||
|
||||
@Column
|
||||
@Comment("平台")
|
||||
private String provider;
|
||||
|
||||
@Column
|
||||
@ColDefine(type = ColType.TEXT, adaptor = NutMapValueAdaptor.class)
|
||||
private NutMap config;
|
||||
|
||||
public PlatformConfig() {
|
||||
super();
|
||||
}
|
||||
|
||||
public PlatformConfig(int sid, NutMap config) {
|
||||
super();
|
||||
this.sid = sid;
|
||||
this.provider = config.getString("provider");
|
||||
this.config = config;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public int getSid() {
|
||||
return sid;
|
||||
}
|
||||
|
||||
public void setSid(int sid) {
|
||||
this.sid = sid;
|
||||
}
|
||||
|
||||
public String getProvider() {
|
||||
return provider;
|
||||
}
|
||||
|
||||
public void setProvider(String provider) {
|
||||
this.provider = provider;
|
||||
}
|
||||
|
||||
public NutMap getConfig() {
|
||||
if (config == null) {
|
||||
config = NutMap.NEW();
|
||||
}
|
||||
return config;
|
||||
}
|
||||
|
||||
public void setConfig(NutMap config) {
|
||||
this.config = config;
|
||||
}
|
||||
|
||||
public PlatformConfig addPlatform(String id, NutMap config) {
|
||||
this.config.addv(id, config);
|
||||
return this;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,138 @@
|
|||
package com.rekoe.domain;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
import org.nutz.dao.entity.annotation.ColDefine;
|
||||
import org.nutz.dao.entity.annotation.ColType;
|
||||
import org.nutz.dao.entity.annotation.Column;
|
||||
import org.nutz.dao.entity.annotation.Comment;
|
||||
import org.nutz.dao.entity.annotation.Default;
|
||||
import org.nutz.dao.entity.annotation.Id;
|
||||
import org.nutz.dao.entity.annotation.Index;
|
||||
import org.nutz.dao.entity.annotation.Table;
|
||||
import org.nutz.dao.entity.annotation.TableIndexes;
|
||||
import org.nutz.lang.Times;
|
||||
|
||||
@Table("platform_user")
|
||||
@TableIndexes({ @Index(name = "passportid_pfid_pid_index", fields = { "passportid", "pfid", "pid" }, unique = true) })
|
||||
public class PlatformUser implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = -2735176124180310964L;
|
||||
|
||||
@Id
|
||||
private long id;
|
||||
|
||||
@Column
|
||||
private String passportid;
|
||||
|
||||
@Column(hump = true)
|
||||
@ColDefine(type = ColType.TIMESTAMP, insert = true)
|
||||
private Date createTime;
|
||||
|
||||
@Column("is_locked")
|
||||
private boolean locked;
|
||||
|
||||
@Column
|
||||
private long openid;
|
||||
|
||||
@Column("pfid")
|
||||
@Comment("渠道号")
|
||||
@ColDefine(type = ColType.VARCHAR, width = 50)
|
||||
private String pfid;
|
||||
|
||||
@Column("pid")
|
||||
@Comment("平台号")
|
||||
private int pid;
|
||||
|
||||
@Column
|
||||
@Comment("IP")
|
||||
@Default("127.0.0.1")
|
||||
private String addr;
|
||||
|
||||
public PlatformUser() {
|
||||
super();
|
||||
}
|
||||
|
||||
public PlatformUser(int pid, String passportid, long openid, String pfid, String addr) {
|
||||
this.pid = pid;
|
||||
this.passportid = passportid;
|
||||
this.createTime = Times.now();
|
||||
this.openid = openid;
|
||||
this.pfid = pfid;
|
||||
this.addr = addr;
|
||||
}
|
||||
|
||||
public PlatformUser(int pid, String passportid, long openid, String pfid) {
|
||||
this.pid = pid;
|
||||
this.passportid = passportid;
|
||||
this.createTime = Times.now();
|
||||
this.openid = openid;
|
||||
this.pfid = pfid;
|
||||
}
|
||||
|
||||
public long getOpenid() {
|
||||
return openid;
|
||||
}
|
||||
|
||||
public String getAddr() {
|
||||
return addr;
|
||||
}
|
||||
|
||||
public void setAddr(String addr) {
|
||||
this.addr = addr;
|
||||
}
|
||||
|
||||
public void setOpenid(long openid) {
|
||||
this.openid = openid;
|
||||
}
|
||||
|
||||
public long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getPassportid() {
|
||||
return passportid;
|
||||
}
|
||||
|
||||
public void setPassportid(String passportid) {
|
||||
this.passportid = passportid;
|
||||
}
|
||||
|
||||
public Date getCreateTime() {
|
||||
return createTime;
|
||||
}
|
||||
|
||||
public void setCreateTime(Date createTime) {
|
||||
this.createTime = createTime;
|
||||
}
|
||||
|
||||
public boolean isLocked() {
|
||||
return locked;
|
||||
}
|
||||
|
||||
public void setLocked(boolean locked) {
|
||||
this.locked = locked;
|
||||
}
|
||||
|
||||
public String getPfid() {
|
||||
return pfid;
|
||||
}
|
||||
|
||||
public void setPfid(String pfid) {
|
||||
this.pfid = pfid;
|
||||
}
|
||||
|
||||
public int getPid() {
|
||||
return pid;
|
||||
}
|
||||
|
||||
public void setPid(int pid) {
|
||||
this.pid = pid;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,104 @@
|
|||
package com.rekoe.domain;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import org.nutz.dao.entity.annotation.ColDefine;
|
||||
import org.nutz.dao.entity.annotation.ColType;
|
||||
import org.nutz.dao.entity.annotation.Column;
|
||||
import org.nutz.dao.entity.annotation.EL;
|
||||
import org.nutz.dao.entity.annotation.Index;
|
||||
import org.nutz.dao.entity.annotation.Name;
|
||||
import org.nutz.dao.entity.annotation.Prev;
|
||||
import org.nutz.dao.entity.annotation.Table;
|
||||
import org.nutz.dao.entity.annotation.TableIndexes;
|
||||
|
||||
@Table("sg_report_ads")
|
||||
@TableIndexes({ @Index(name = "report_ads_index", fields = { "pid", "pfid" }, unique = false) })
|
||||
public class ReportAds implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = -8361228159606140014L;
|
||||
|
||||
@Name
|
||||
@Prev(els = { @EL("uuid()") })
|
||||
private String id;
|
||||
|
||||
@Column
|
||||
private int pid;
|
||||
|
||||
@Column
|
||||
private String pfid;
|
||||
|
||||
@Column
|
||||
@ColDefine(type = ColType.VARCHAR, width = 100)
|
||||
private String idfa;
|
||||
|
||||
@Column
|
||||
@ColDefine(type = ColType.VARCHAR, width = 100)
|
||||
private String idfv;
|
||||
|
||||
@Column(hump = true)
|
||||
@ColDefine(type = ColType.VARCHAR, width = 100)
|
||||
private String talkingDataId;
|
||||
|
||||
public ReportAds() {
|
||||
super();
|
||||
}
|
||||
|
||||
public ReportAds(int pid, String pfid, String idfa, String idfv, String talkingDataId) {
|
||||
super();
|
||||
this.pid = pid;
|
||||
this.pfid = pfid;
|
||||
this.idfa = idfa;
|
||||
this.idfv = idfv;
|
||||
this.talkingDataId = talkingDataId;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public int getPid() {
|
||||
return pid;
|
||||
}
|
||||
|
||||
public void setPid(int pid) {
|
||||
this.pid = pid;
|
||||
}
|
||||
|
||||
public String getPfid() {
|
||||
return pfid;
|
||||
}
|
||||
|
||||
public void setPfid(String pfid) {
|
||||
this.pfid = pfid;
|
||||
}
|
||||
|
||||
public String getIdfa() {
|
||||
return idfa;
|
||||
}
|
||||
|
||||
public void setIdfa(String idfa) {
|
||||
this.idfa = idfa;
|
||||
}
|
||||
|
||||
public String getIdfv() {
|
||||
return idfv;
|
||||
}
|
||||
|
||||
public void setIdfv(String idfv) {
|
||||
this.idfv = idfv;
|
||||
}
|
||||
|
||||
public String getTalkingDataId() {
|
||||
return talkingDataId;
|
||||
}
|
||||
|
||||
public void setTalkingDataId(String talkingDataId) {
|
||||
this.talkingDataId = talkingDataId;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,101 @@
|
|||
package com.rekoe.domain;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
import org.nutz.dao.entity.annotation.ColDefine;
|
||||
import org.nutz.dao.entity.annotation.ColType;
|
||||
import org.nutz.dao.entity.annotation.Column;
|
||||
import org.nutz.dao.entity.annotation.Id;
|
||||
import org.nutz.dao.entity.annotation.Index;
|
||||
import org.nutz.dao.entity.annotation.ManyMany;
|
||||
import org.nutz.dao.entity.annotation.Table;
|
||||
import org.nutz.dao.entity.annotation.TableIndexes;
|
||||
/**
|
||||
* @author 科技㊣²º¹³
|
||||
* 2014年2月3日 下午4:48:45
|
||||
* http://www.rekoe.com
|
||||
* QQ:5382211
|
||||
*/
|
||||
@Table("system_role")
|
||||
@TableIndexes({ @Index(name = "role_name", fields = { "name" }, unique = true) })
|
||||
public class Role implements Serializable{
|
||||
private static final long serialVersionUID = 7928270441533321123L;
|
||||
@Id
|
||||
private Long id;
|
||||
@Column
|
||||
@ColDefine(type = ColType.VARCHAR, width = 200)
|
||||
private String name;
|
||||
@Column
|
||||
@ColDefine(type = ColType.VARCHAR, width = 500)
|
||||
private String description;
|
||||
@ManyMany(target = User.class, relation = "system_user_role", from = "roleid", to = "userid")
|
||||
private List<User> users;
|
||||
@ManyMany(target = Permission.class, relation = "system_role_permission", from = "roleid", to = "permissionid")
|
||||
private List<Permission> permissions;
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public List<User> getUsers() {
|
||||
return users;
|
||||
}
|
||||
|
||||
public void setUsers(List<User> users) {
|
||||
this.users = users;
|
||||
}
|
||||
|
||||
public List<Permission> getPermissions() {
|
||||
return permissions;
|
||||
}
|
||||
|
||||
public void setPermissions(List<Permission> permissions) {
|
||||
this.permissions = permissions;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + ((id == null) ? 0 : id.hashCode());
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (obj == null)
|
||||
return false;
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
Role other = (Role) obj;
|
||||
if (id == null) {
|
||||
if (other.id != null)
|
||||
return false;
|
||||
} else if (!id.equals(other.id))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,102 @@
|
|||
package com.rekoe.domain;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
import org.nutz.dao.entity.annotation.ColDefine;
|
||||
import org.nutz.dao.entity.annotation.ColType;
|
||||
import org.nutz.dao.entity.annotation.Column;
|
||||
import org.nutz.dao.entity.annotation.Id;
|
||||
import org.nutz.dao.entity.annotation.Index;
|
||||
import org.nutz.dao.entity.annotation.Table;
|
||||
import org.nutz.dao.entity.annotation.TableIndexes;
|
||||
import org.nutz.lang.Times;
|
||||
|
||||
@Table("server_history")
|
||||
@TableIndexes({ @Index(name = "passportid_pid_index", fields = { "openid", "pid", "sid" }, unique = false) })
|
||||
public class ServerHistory implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 4746739180924296807L;
|
||||
|
||||
@Id
|
||||
private long id;
|
||||
|
||||
@Column
|
||||
private int pid;
|
||||
|
||||
@Column(hump = true)
|
||||
@ColDefine(type = ColType.TIMESTAMP)
|
||||
private Date createTime;
|
||||
|
||||
@Column(hump = true)
|
||||
@ColDefine(type = ColType.TIMESTAMP)
|
||||
private Date modifyTime;
|
||||
|
||||
@Column
|
||||
private long openid;
|
||||
|
||||
@Column
|
||||
private int sid;
|
||||
|
||||
public ServerHistory(long openid, int pid, int sid) {
|
||||
super();
|
||||
this.pid = pid;
|
||||
this.openid = openid;
|
||||
this.createTime = Times.now();
|
||||
this.modifyTime = this.createTime;
|
||||
this.sid = sid;
|
||||
}
|
||||
|
||||
public ServerHistory() {
|
||||
super();
|
||||
}
|
||||
|
||||
public long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public int getPid() {
|
||||
return pid;
|
||||
}
|
||||
|
||||
public void setPid(int pid) {
|
||||
this.pid = pid;
|
||||
}
|
||||
|
||||
public Date getCreateTime() {
|
||||
return createTime;
|
||||
}
|
||||
|
||||
public void setCreateTime(Date createTime) {
|
||||
this.createTime = createTime;
|
||||
}
|
||||
|
||||
public long getOpenid() {
|
||||
return openid;
|
||||
}
|
||||
|
||||
public void setOpenid(long openid) {
|
||||
this.openid = openid;
|
||||
}
|
||||
|
||||
public Date getModifyTime() {
|
||||
return modifyTime;
|
||||
}
|
||||
|
||||
public void setModifyTime(Date modifyTime) {
|
||||
this.modifyTime = modifyTime;
|
||||
}
|
||||
|
||||
public int getSid() {
|
||||
return sid;
|
||||
}
|
||||
|
||||
public void setSid(int sid) {
|
||||
this.sid = sid;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,172 @@
|
|||
package com.rekoe.domain;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.nutz.dao.entity.annotation.ColDefine;
|
||||
import org.nutz.dao.entity.annotation.ColType;
|
||||
import org.nutz.dao.entity.annotation.Column;
|
||||
import org.nutz.dao.entity.annotation.Id;
|
||||
import org.nutz.dao.entity.annotation.Index;
|
||||
import org.nutz.dao.entity.annotation.ManyMany;
|
||||
import org.nutz.dao.entity.annotation.Table;
|
||||
import org.nutz.dao.entity.annotation.TableIndexes;
|
||||
|
||||
/**
|
||||
* @author 科技㊣²º¹³
|
||||
* 2014年2月3日 下午4:48:45
|
||||
* http://www.rekoe.com
|
||||
* QQ:5382211
|
||||
*/
|
||||
@Table("system_user")
|
||||
@TableIndexes({ @Index(name = "user_name", fields = { "name" }, unique = true), @Index(name = "user_openid", fields = { "openid" }, unique = true) })
|
||||
public class User implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = -965829144356813385L;
|
||||
|
||||
@Id
|
||||
private Long id;
|
||||
@Column
|
||||
@ColDefine(type = ColType.VARCHAR, width = 20)
|
||||
private String name;
|
||||
@Column
|
||||
@ColDefine(type = ColType.CHAR, width = 44)
|
||||
private String password;
|
||||
@Column
|
||||
@ColDefine(type = ColType.CHAR, width = 24)
|
||||
private String salt;
|
||||
@Column
|
||||
@ColDefine(type = ColType.VARCHAR, width = 64)
|
||||
private String openid;
|
||||
@Column
|
||||
@ColDefine(type = ColType.VARCHAR, width = 10)
|
||||
private String providerid;
|
||||
@Column("is_locked")
|
||||
@ColDefine(type = ColType.BOOLEAN)
|
||||
private boolean locked;
|
||||
@Column
|
||||
@ColDefine(type = ColType.VARCHAR, width = 500)
|
||||
private String description;
|
||||
@Column(hump = true)
|
||||
@ColDefine(type = ColType.TIMESTAMP)
|
||||
private Date createDate;
|
||||
@Column(hump = true)
|
||||
@ColDefine(type = ColType.VARCHAR, width = 15)
|
||||
private String registerIp;
|
||||
@ManyMany(target = Role.class, relation = "system_user_role", from = "userid", to = "roleid")
|
||||
private List<Role> roles;
|
||||
|
||||
@Column("is_system")
|
||||
@ColDefine(type = ColType.BOOLEAN)
|
||||
private boolean system;
|
||||
|
||||
@ManyMany(target = GameServer.class, relation = "system_user_server", from = "USERID", to = "SERVERID", key = "id")
|
||||
private Map<Integer, GameServer> servers;
|
||||
|
||||
public String getProviderid() {
|
||||
return providerid;
|
||||
}
|
||||
|
||||
public void setProviderid(String providerid) {
|
||||
this.providerid = providerid;
|
||||
}
|
||||
|
||||
public String getOpenid() {
|
||||
return openid;
|
||||
}
|
||||
|
||||
public void setOpenid(String openid) {
|
||||
this.openid = openid;
|
||||
}
|
||||
|
||||
public boolean isLocked() {
|
||||
return locked;
|
||||
}
|
||||
|
||||
public void setLocked(boolean locked) {
|
||||
this.locked = locked;
|
||||
}
|
||||
|
||||
public Date getCreateDate() {
|
||||
return createDate;
|
||||
}
|
||||
|
||||
public void setCreateDate(Date createDate) {
|
||||
this.createDate = createDate;
|
||||
}
|
||||
|
||||
public String getRegisterIp() {
|
||||
return registerIp;
|
||||
}
|
||||
|
||||
public void setRegisterIp(String registerIp) {
|
||||
this.registerIp = registerIp;
|
||||
}
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getPassword() {
|
||||
return password;
|
||||
}
|
||||
|
||||
public void setPassword(String password) {
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public List<Role> getRoles() {
|
||||
return roles;
|
||||
}
|
||||
|
||||
public void setRoles(List<Role> roles) {
|
||||
this.roles = roles;
|
||||
}
|
||||
|
||||
public String getSalt() {
|
||||
return salt;
|
||||
}
|
||||
|
||||
public void setSalt(String salt) {
|
||||
this.salt = salt;
|
||||
}
|
||||
|
||||
public boolean isSystem() {
|
||||
return system;
|
||||
}
|
||||
|
||||
public void setSystem(boolean system) {
|
||||
this.system = system;
|
||||
}
|
||||
|
||||
public Map<Integer, GameServer> getServers() {
|
||||
return servers;
|
||||
}
|
||||
|
||||
public void setServers(Map<Integer, GameServer> servers) {
|
||||
this.servers = servers;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,111 @@
|
|||
package com.rekoe.domain;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import org.nutz.dao.entity.annotation.ColDefine;
|
||||
import org.nutz.dao.entity.annotation.Column;
|
||||
import org.nutz.dao.entity.annotation.Comment;
|
||||
import org.nutz.dao.entity.annotation.EL;
|
||||
import org.nutz.dao.entity.annotation.Index;
|
||||
import org.nutz.dao.entity.annotation.Name;
|
||||
import org.nutz.dao.entity.annotation.One;
|
||||
import org.nutz.dao.entity.annotation.Prev;
|
||||
import org.nutz.dao.entity.annotation.Table;
|
||||
import org.nutz.dao.entity.annotation.TableIndexes;
|
||||
|
||||
/**
|
||||
* 提审服
|
||||
*
|
||||
* @author kouxian
|
||||
*
|
||||
*/
|
||||
@Table("verify_server")
|
||||
@TableIndexes({ @Index(name = "g_sid_index", fields = { "pid" }, unique = true) })
|
||||
public class VerifyServer implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = -2235259090910419768L;
|
||||
|
||||
@Name
|
||||
@Prev(els = { @EL("uuid()") })
|
||||
private String id;
|
||||
|
||||
@Column
|
||||
@ColDefine(width = 225)
|
||||
private String url;
|
||||
|
||||
@Column
|
||||
private String name;
|
||||
|
||||
@Column(hump = true)
|
||||
@Comment("登陆服地址")
|
||||
@ColDefine(width = 225)
|
||||
private String loginUrl;
|
||||
|
||||
@Column(hump = true)
|
||||
@Comment("充值地址")
|
||||
@ColDefine(width = 225)
|
||||
private String payUrl;
|
||||
|
||||
@Column("pid")
|
||||
private int pid;
|
||||
|
||||
@One(target = GameServer.class, field = "pid")
|
||||
private GameServer gameServer;
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getUrl() {
|
||||
return url;
|
||||
}
|
||||
|
||||
public void setUrl(String url) {
|
||||
this.url = url;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getLoginUrl() {
|
||||
return loginUrl;
|
||||
}
|
||||
|
||||
public void setLoginUrl(String loginUrl) {
|
||||
this.loginUrl = loginUrl;
|
||||
}
|
||||
|
||||
public String getPayUrl() {
|
||||
return payUrl;
|
||||
}
|
||||
|
||||
public void setPayUrl(String payUrl) {
|
||||
this.payUrl = payUrl;
|
||||
}
|
||||
|
||||
public int getPid() {
|
||||
return pid;
|
||||
}
|
||||
|
||||
public void setPid(int pid) {
|
||||
this.pid = pid;
|
||||
}
|
||||
|
||||
public GameServer getGameServer() {
|
||||
return gameServer;
|
||||
}
|
||||
|
||||
public void setGameServer(GameServer gameServer) {
|
||||
this.gameServer = gameServer;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
package com.rekoe.exception;
|
||||
|
||||
import org.apache.shiro.authc.AuthenticationException;
|
||||
/**
|
||||
* @author 科技㊣²º¹³
|
||||
* 2014年2月3日 下午4:48:45
|
||||
* http://www.rekoe.com
|
||||
* QQ:5382211
|
||||
*/
|
||||
public class CreateUserSaltException extends AuthenticationException {
|
||||
|
||||
private static final long serialVersionUID = 3315875923669742156L;
|
||||
|
||||
public CreateUserSaltException() {
|
||||
super();
|
||||
}
|
||||
|
||||
public CreateUserSaltException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
public CreateUserSaltException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public CreateUserSaltException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
package com.rekoe.exception;
|
||||
|
||||
import org.apache.shiro.authc.AuthenticationException;
|
||||
/**
|
||||
* @author 科技㊣²º¹³
|
||||
* 2014年2月3日 下午4:48:45
|
||||
* http://www.rekoe.com
|
||||
* QQ:5382211
|
||||
*/
|
||||
public class IncorrectCaptchaException extends AuthenticationException {
|
||||
|
||||
private static final long serialVersionUID = 3315875923669742156L;
|
||||
|
||||
public IncorrectCaptchaException() {
|
||||
super();
|
||||
}
|
||||
|
||||
public IncorrectCaptchaException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
public IncorrectCaptchaException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public IncorrectCaptchaException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
package com.rekoe.filter;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.nutz.ioc.impl.PropertiesProxy;
|
||||
import org.nutz.ioc.loader.annotation.Inject;
|
||||
import org.nutz.mvc.ActionContext;
|
||||
import org.nutz.mvc.ActionFilter;
|
||||
import org.nutz.mvc.View;
|
||||
|
||||
public abstract class AbstractCrossOriginFilter implements ActionFilter {
|
||||
|
||||
@Inject
|
||||
protected PropertiesProxy conf;
|
||||
|
||||
@Override
|
||||
public View match(ActionContext ac) {
|
||||
if (on()) {
|
||||
HttpServletResponse response = ac.getResponse();
|
||||
addHeader(response);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
protected abstract boolean on();
|
||||
|
||||
protected abstract void addHeader(HttpServletResponse response);
|
||||
}
|
|
@ -0,0 +1,34 @@
|
|||
package com.rekoe.filter;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import org.apache.shiro.authc.AuthenticationToken;
|
||||
import org.apache.shiro.authc.UsernamePasswordToken;
|
||||
import org.apache.shiro.web.filter.authc.FormAuthenticationFilter;
|
||||
import org.nutz.mvc.ActionContext;
|
||||
import org.nutz.mvc.ActionFilter;
|
||||
import org.nutz.mvc.View;
|
||||
/**
|
||||
* @author 科技㊣²º¹³
|
||||
* 2014年2月3日 下午4:48:45
|
||||
* http://www.rekoe.com
|
||||
* QQ:5382211
|
||||
*/
|
||||
public class AuthenticationFilter extends FormAuthenticationFilter implements ActionFilter {
|
||||
|
||||
protected AuthenticationToken createToken(HttpServletRequest request) {
|
||||
String username = getUsername(request);
|
||||
String password = getPassword(request);
|
||||
boolean rememberMe = isRememberMe(request);
|
||||
String host = getHost(request);
|
||||
return new UsernamePasswordToken(username, password, rememberMe, host);
|
||||
}
|
||||
|
||||
@Override
|
||||
public View match(ActionContext actionContext) {
|
||||
HttpServletRequest request = actionContext.getRequest();
|
||||
AuthenticationToken authenticationToken = createToken(request);
|
||||
request.setAttribute("loginToken", authenticationToken);
|
||||
return null;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,57 @@
|
|||
package com.rekoe.filter;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.nutz.dao.Cnd;
|
||||
import org.nutz.integration.shiro.NutShiro;
|
||||
import org.nutz.ioc.loader.annotation.Inject;
|
||||
import org.nutz.ioc.loader.annotation.IocBean;
|
||||
import org.nutz.lang.Lang;
|
||||
import org.nutz.mvc.ActionContext;
|
||||
import org.nutz.mvc.ActionFilter;
|
||||
import org.nutz.mvc.View;
|
||||
import org.nutz.mvc.view.UTF8JsonView;
|
||||
import org.nutz.mvc.view.ViewWrapper;
|
||||
import org.nutz.plugins.view.freemarker.FreeMarkerConfigurer;
|
||||
import org.nutz.plugins.view.freemarker.FreemarkerView;
|
||||
|
||||
import com.rekoe.common.Message;
|
||||
import com.rekoe.domain.GameServer;
|
||||
import com.rekoe.service.GameServerService;
|
||||
|
||||
@IocBean
|
||||
public class ChectServerExitsActionFilter implements ActionFilter {
|
||||
|
||||
@Inject
|
||||
private FreeMarkerConfigurer freeMarkerConfigurer;
|
||||
|
||||
@Inject
|
||||
private GameServerService gameServerService;
|
||||
|
||||
public View match(final ActionContext ctx) {
|
||||
HttpServletRequest req = ctx.getRequest();
|
||||
String pid = req.getParameter("pid");
|
||||
if (StringUtils.isNotBlank(pid)) {
|
||||
GameServer gameServer = gameServerService.fetch(Cnd.where("pid", "=", pid));
|
||||
if (Lang.isEmpty(gameServer)) {
|
||||
if (NutShiro.isAjax(ctx.getRequest())) {
|
||||
ctx.getResponse().setHeader("loginStatus", getResStatus());
|
||||
return new ViewWrapper(UTF8JsonView.COMPACT, getResStatus());
|
||||
}
|
||||
return getErrView(ctx.getRequest());
|
||||
} else {
|
||||
req.getSession().setAttribute("sid", gameServer.getId());
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public String getResStatus() {
|
||||
return "server_not_exits";
|
||||
}
|
||||
|
||||
public View getErrView(HttpServletRequest req) {
|
||||
return new ViewWrapper(new FreemarkerView(freeMarkerConfigurer, "template/admin/common/error"), Message.error("server_not_exits", req));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,120 @@
|
|||
package com.rekoe.filter;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import org.apache.commons.vfs2.FileChangeEvent;
|
||||
import org.apache.commons.vfs2.FileListener;
|
||||
import org.apache.commons.vfs2.FileName;
|
||||
import org.apache.commons.vfs2.FileSystemManager;
|
||||
import org.apache.commons.vfs2.VFS;
|
||||
import org.apache.commons.vfs2.impl.DefaultFileMonitor;
|
||||
import org.nutz.ioc.loader.annotation.IocBean;
|
||||
import org.nutz.lang.Files;
|
||||
import org.nutz.lang.Lang;
|
||||
import org.nutz.lang.util.Callback;
|
||||
import org.nutz.log.Log;
|
||||
import org.nutz.log.Logs;
|
||||
import org.nutz.mvc.ActionContext;
|
||||
import org.nutz.mvc.ActionFilter;
|
||||
import org.nutz.mvc.Mvcs;
|
||||
import org.nutz.mvc.View;
|
||||
import org.nutz.mvc.view.RawView;
|
||||
import org.nutz.mvc.view.ViewWrapper;
|
||||
|
||||
import com.rekoe.utils.CommonUtils;
|
||||
|
||||
@IocBean(create = "init")
|
||||
public class IPFilter implements ActionFilter {
|
||||
|
||||
private final static Log log = Logs.get();
|
||||
protected static final String IP_WHITE_LIST = "ipwhite";
|
||||
protected String configPath = "";
|
||||
protected Set<String> ipWhiteSet = new HashSet<String>();
|
||||
private final View IP_FORBIT_ERROR = new ViewWrapper(new RawView(""), "非法IP");
|
||||
|
||||
/* 初始化 */
|
||||
public void init() throws ServletException {
|
||||
configPath = Mvcs.getNutConfig().getAppRoot() + "/../conf/";
|
||||
refreshIPList();
|
||||
initFileMonitor();
|
||||
}
|
||||
|
||||
private void refreshIPList() {
|
||||
try {
|
||||
File file = Files.findFile(IP_WHITE_LIST);
|
||||
if (Lang.isEmpty(file)) {
|
||||
file = Files.findFile(configPath + IP_WHITE_LIST);
|
||||
}
|
||||
if (Lang.isEmpty(file)) {
|
||||
this.ipWhiteSet = null;
|
||||
return;
|
||||
}
|
||||
final Set<String> ips = new HashSet<String>();
|
||||
Files.readLine(file, new Callback<String>() {
|
||||
@Override
|
||||
public void invoke(String str) {
|
||||
ips.add(str);
|
||||
}
|
||||
});
|
||||
this.ipWhiteSet = ips;
|
||||
} catch (Exception e) {
|
||||
log.error(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public View match(ActionContext actionContext) {
|
||||
HttpServletRequest req = actionContext.getRequest();
|
||||
String remoteIP = Lang.getIP(req);
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug(" ip file pass " + remoteIP);
|
||||
}
|
||||
if (this.ipWhiteSet == null || this.ipWhiteSet.isEmpty())
|
||||
return null;
|
||||
if (this.ipWhiteSet.contains(remoteIP) || CommonUtils.isInnerIP(remoteIP)) {
|
||||
return null;
|
||||
}
|
||||
return IP_FORBIT_ERROR;
|
||||
}
|
||||
|
||||
private void initFileMonitor() {
|
||||
FileSystemManager fsManager = null;
|
||||
org.apache.commons.vfs2.FileObject listendir = null;
|
||||
try {
|
||||
fsManager = VFS.getManager();
|
||||
listendir = fsManager.resolveFile(new File(configPath).getAbsolutePath());
|
||||
} catch (org.apache.commons.vfs2.FileSystemException e) {
|
||||
log.error(e);
|
||||
}
|
||||
|
||||
DefaultFileMonitor fm = new DefaultFileMonitor(new FileListener() {
|
||||
public void fileCreated(FileChangeEvent event) throws Exception {
|
||||
monitor(event);
|
||||
}
|
||||
|
||||
public void fileDeleted(FileChangeEvent event) throws Exception {
|
||||
monitor(event);
|
||||
}
|
||||
|
||||
public void fileChanged(FileChangeEvent event) throws Exception {
|
||||
monitor(event);
|
||||
}
|
||||
|
||||
private void monitor(FileChangeEvent event) {
|
||||
org.apache.commons.vfs2.FileObject fileObject = event.getFile();
|
||||
FileName fileName = fileObject.getName();
|
||||
if (fileName.getBaseName().contains(IP_WHITE_LIST)) {
|
||||
refreshIPList();
|
||||
}
|
||||
}
|
||||
});
|
||||
fm.setRecursive(true);
|
||||
fm.addFile(listendir);
|
||||
fm.start();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
package com.rekoe.filter;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
public class OauthCrossOriginFilter extends AbstractCrossOriginFilter {
|
||||
|
||||
@Override
|
||||
protected boolean on() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void addHeader(HttpServletResponse response) {
|
||||
response.addHeader("Access-Control-Allow-Origin", "*");
|
||||
response.addHeader("Access-Control-Allow-Methods", "get, post, put, delete, options");
|
||||
response.addHeader("Access-Control-Allow-Headers", "origin, content-type, accept");
|
||||
response.addHeader("Access-Control-Allow-Credentials", "true");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,46 @@
|
|||
package com.rekoe.filter;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpSession;
|
||||
|
||||
import org.nutz.integration.shiro.NutShiro;
|
||||
import org.nutz.ioc.loader.annotation.Inject;
|
||||
import org.nutz.ioc.loader.annotation.IocBean;
|
||||
import org.nutz.lang.Lang;
|
||||
import org.nutz.mvc.ActionContext;
|
||||
import org.nutz.mvc.ActionFilter;
|
||||
import org.nutz.mvc.View;
|
||||
import org.nutz.mvc.view.UTF8JsonView;
|
||||
import org.nutz.mvc.view.ViewWrapper;
|
||||
import org.nutz.plugins.view.freemarker.FreeMarkerConfigurer;
|
||||
import org.nutz.plugins.view.freemarker.FreemarkerView;
|
||||
|
||||
import com.rekoe.common.Message;
|
||||
|
||||
@IocBean
|
||||
public class SelectServerActionFilter implements ActionFilter {
|
||||
|
||||
@Inject
|
||||
private FreeMarkerConfigurer freeMarkerConfigurer;
|
||||
|
||||
public View match(final ActionContext ctx) {
|
||||
HttpSession session = ctx.getRequest().getSession();
|
||||
Object sid = session.getAttribute("sid");
|
||||
if (Lang.isEmpty(sid)) {
|
||||
if (NutShiro.isAjax(ctx.getRequest())) {
|
||||
ctx.getResponse().setHeader("loginStatus", getResStatus());
|
||||
return new ViewWrapper(UTF8JsonView.COMPACT, getResStatus());
|
||||
}
|
||||
return getErrView(ctx.getRequest());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public String getResStatus() {
|
||||
return "select_server";
|
||||
}
|
||||
|
||||
public View getErrView(HttpServletRequest req) {
|
||||
return new ViewWrapper(new FreemarkerView(freeMarkerConfigurer, "template/admin/common/error"), Message.error("admin.common.error.no.server", req));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,75 @@
|
|||
package com.rekoe.filter;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.apache.commons.lang3.math.NumberUtils;
|
||||
import org.apache.shiro.SecurityUtils;
|
||||
import org.apache.shiro.subject.Subject;
|
||||
import org.nutz.integration.shiro.NutShiro;
|
||||
import org.nutz.ioc.loader.annotation.Inject;
|
||||
import org.nutz.ioc.loader.annotation.IocBean;
|
||||
import org.nutz.lang.Lang;
|
||||
import org.nutz.mvc.ActionContext;
|
||||
import org.nutz.mvc.ActionFilter;
|
||||
import org.nutz.mvc.View;
|
||||
import org.nutz.mvc.view.UTF8JsonView;
|
||||
import org.nutz.mvc.view.ViewWrapper;
|
||||
import org.nutz.plugins.view.freemarker.FreeMarkerConfigurer;
|
||||
import org.nutz.plugins.view.freemarker.FreemarkerView;
|
||||
|
||||
import com.rekoe.common.Message;
|
||||
import com.rekoe.domain.GameServer;
|
||||
import com.rekoe.domain.User;
|
||||
|
||||
@IocBean
|
||||
public class ServerPermisionActionFilter implements ActionFilter {
|
||||
|
||||
@Inject
|
||||
private FreeMarkerConfigurer freeMarkerConfigurer;
|
||||
|
||||
public View match(final ActionContext ctx) {
|
||||
HttpServletRequest req = ctx.getRequest();
|
||||
Object sid = req.getParameter("platformid");
|
||||
if (Lang.isEmpty(sid)) {
|
||||
return getErrView(req, ctx.getResponse());
|
||||
}
|
||||
boolean isRight = false;
|
||||
Subject subject = SecurityUtils.getSubject();
|
||||
if (subject.getPrincipal() instanceof User) {
|
||||
User user = (User) subject.getPrincipal();
|
||||
Map<Integer, GameServer> servers = user.getServers();
|
||||
if (user.isSystem()) {
|
||||
isRight = true;
|
||||
} else if (!Lang.isEmpty(servers)) {
|
||||
int pid = NumberUtils.toInt(sid.toString());
|
||||
Collection<GameServer> games = servers.values();
|
||||
for (GameServer game : games) {
|
||||
if (game.getPid() == pid) {
|
||||
isRight = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (isRight) {
|
||||
return null;
|
||||
}
|
||||
return getErrView(req, ctx.getResponse());
|
||||
}
|
||||
|
||||
public String getResStatus() {
|
||||
return "unauthorized";
|
||||
}
|
||||
|
||||
public View getErrView(HttpServletRequest req, HttpServletResponse resp) {
|
||||
if (NutShiro.isAjax(req)) {
|
||||
resp.setHeader("loginStatus", getResStatus());
|
||||
return new ViewWrapper(UTF8JsonView.COMPACT, getResStatus());
|
||||
}
|
||||
return new ViewWrapper(new FreemarkerView(freeMarkerConfigurer, "template/admin/common/error"), Message.error(getResStatus(), req));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
package com.rekoe.mobile;
|
||||
|
||||
public abstract class AbstractParam {
|
||||
|
||||
public abstract String getProviderId();
|
||||
|
||||
public abstract int getPid();
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
package com.rekoe.mobile;
|
||||
|
||||
public abstract class AuthProvider<T extends AbstractParam> {
|
||||
|
||||
public abstract String getProviderId();
|
||||
|
||||
public abstract Profile verifyResponse(T param) throws Exception;
|
||||
|
||||
public abstract Class<T> getEntityClass();
|
||||
|
||||
}
|
|
@ -0,0 +1,64 @@
|
|||
package com.rekoe.mobile;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import org.nutz.lang.util.NutMap;
|
||||
|
||||
public class Profile implements Serializable {
|
||||
|
||||
public static final String TOKEN = "token";
|
||||
private static final long serialVersionUID = -3916223452935420808L;
|
||||
|
||||
private String providerId;
|
||||
private String passportid;
|
||||
private int pid;
|
||||
private NutMap pros = NutMap.NEW();
|
||||
|
||||
public Profile(String providerId, String passportid, int pid) {
|
||||
super();
|
||||
this.providerId = providerId;
|
||||
this.passportid = passportid;
|
||||
this.pid = pid;
|
||||
}
|
||||
|
||||
public Profile(String providerId, long passportid, int pid) {
|
||||
super();
|
||||
this.providerId = providerId;
|
||||
this.passportid = String.valueOf(passportid);
|
||||
this.pid = pid;
|
||||
}
|
||||
|
||||
public String getToken() {
|
||||
return pros.getString(TOKEN);
|
||||
}
|
||||
|
||||
public int getPid() {
|
||||
return pid;
|
||||
}
|
||||
|
||||
public String getProviderId() {
|
||||
return providerId;
|
||||
}
|
||||
|
||||
public void setProviderId(String providerId) {
|
||||
this.providerId = providerId;
|
||||
}
|
||||
|
||||
public String getPassportid() {
|
||||
return passportid;
|
||||
}
|
||||
|
||||
public void setPassportid(String passportid) {
|
||||
this.passportid = passportid;
|
||||
}
|
||||
|
||||
public Profile addv(String key, Object obj) {
|
||||
pros.addv(key, obj);
|
||||
return this;
|
||||
}
|
||||
|
||||
public NutMap getPros() {
|
||||
return pros;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,56 @@
|
|||
/*
|
||||
===========================================================================
|
||||
Copyright (c) 2010 BrickRed Technologies Limited
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sub-license, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
===========================================================================
|
||||
|
||||
*/
|
||||
package com.rekoe.mobile.exception;
|
||||
|
||||
public class SignatureException extends Exception {
|
||||
|
||||
private static final long serialVersionUID = -3832456866408848000L;
|
||||
|
||||
public SignatureException() {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param message
|
||||
*/
|
||||
public SignatureException(final String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param cause
|
||||
*/
|
||||
public SignatureException(final Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param message
|
||||
* @param cause
|
||||
*/
|
||||
public SignatureException(final String message, final Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,57 @@
|
|||
/*
|
||||
===========================================================================
|
||||
Copyright (c) 2010 BrickRed Technologies Limited
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sub-license, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
===========================================================================
|
||||
|
||||
*/
|
||||
package com.rekoe.mobile.exception;
|
||||
|
||||
public class SocialAuthConfigurationException extends Exception {
|
||||
|
||||
private static final long serialVersionUID = 477153534655510364L;
|
||||
|
||||
public SocialAuthConfigurationException() {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param message
|
||||
*/
|
||||
public SocialAuthConfigurationException(final String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param cause
|
||||
*/
|
||||
public SocialAuthConfigurationException(final Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param message
|
||||
* @param cause
|
||||
*/
|
||||
public SocialAuthConfigurationException(final String message,
|
||||
final Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,56 @@
|
|||
/*
|
||||
===========================================================================
|
||||
Copyright (c) 2010 BrickRed Technologies Limited
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sub-license, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
===========================================================================
|
||||
|
||||
*/
|
||||
package com.rekoe.mobile.exception;
|
||||
|
||||
public class SocialAuthException extends Exception {
|
||||
|
||||
private static final long serialVersionUID = -1873507695230807487L;
|
||||
|
||||
public SocialAuthException() {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param message
|
||||
*/
|
||||
public SocialAuthException(final String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param cause
|
||||
*/
|
||||
public SocialAuthException(final Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param message
|
||||
* @param cause
|
||||
*/
|
||||
public SocialAuthException(final String message, final Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,41 @@
|
|||
/*
|
||||
===========================================================================
|
||||
Copyright (c) 2010 BrickRed Technologies Limited
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sub-license, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
===========================================================================
|
||||
|
||||
*/
|
||||
package com.rekoe.mobile.exception;
|
||||
|
||||
public class SocialAuthManagerStateException extends Exception {
|
||||
|
||||
private static final long serialVersionUID = -4089035676676970803L;
|
||||
private static final String errorMessage = "This is not the same SocailAuthManager object that was used for login.";
|
||||
private static final String resolution = "Please check if you have called getAuthenticationUrl() method before calling connect()";
|
||||
|
||||
public SocialAuthManagerStateException() {
|
||||
super();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return errorMessage + resolution;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,199 @@
|
|||
package com.rekoe.mobile.provider;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Map;
|
||||
|
||||
import org.nutz.http.Http;
|
||||
import org.nutz.http.Request;
|
||||
import org.nutz.http.Request.METHOD;
|
||||
import org.nutz.http.Response;
|
||||
import org.nutz.http.Sender;
|
||||
import org.nutz.ioc.loader.annotation.Inject;
|
||||
import org.nutz.json.Json;
|
||||
import org.nutz.lang.Lang;
|
||||
import org.nutz.lang.Mirror;
|
||||
import org.nutz.lang.Strings;
|
||||
import org.nutz.log.Log;
|
||||
import org.nutz.log.Logs;
|
||||
|
||||
import com.rekoe.domain.PlatformConfig;
|
||||
import com.rekoe.mobile.AbstractParam;
|
||||
import com.rekoe.mobile.AuthProvider;
|
||||
import com.rekoe.service.PlatformConfigService;
|
||||
|
||||
public abstract class AbstractProvider<T extends AbstractParam> extends AuthProvider<T> implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 3293830764207197084L;
|
||||
|
||||
private Mirror<T> mirror;
|
||||
|
||||
private static final Log log = Logs.get();
|
||||
|
||||
@Inject
|
||||
private PlatformConfigService platformConfigService;
|
||||
|
||||
/**
|
||||
* 本抽象类能提供一些帮助方法,减少重复写实体类型的麻烦
|
||||
*/
|
||||
public AbstractProvider() {
|
||||
try {
|
||||
Class<T> entryClass = Mirror.getTypeParam(getClass(), 0);
|
||||
mirror = Mirror.me(entryClass);
|
||||
if (log.isDebugEnabled())
|
||||
log.debugf("Get TypeParams for self : %s", entryClass.getName());
|
||||
} catch (Throwable e) {
|
||||
if (log.isWarnEnabled())
|
||||
log.warn("!!!Fail to get TypeParams for self!", e);
|
||||
}
|
||||
}
|
||||
|
||||
public PlatformConfig getPlatformConfig(int pid) {
|
||||
PlatformConfig pc = platformConfigService.getPlatformConfig(pid, getProviderId());
|
||||
if (Lang.isEmpty(pc)) {
|
||||
throw Lang.makeThrow(NullPointerException.class, "Can`t find %s PlatformConfig", getProviderId());
|
||||
}
|
||||
return pc;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取实体类型
|
||||
*
|
||||
* @return 实体类型
|
||||
*/
|
||||
public Class<T> getEntityClass() {
|
||||
return mirror.getType();
|
||||
}
|
||||
|
||||
public String HttpGet(String url) {
|
||||
return HttpGet(url, def_num);
|
||||
}
|
||||
|
||||
private String HttpGet(String url, int num) {
|
||||
try {
|
||||
return Http.get(url).getContent();
|
||||
} catch (Exception e) {
|
||||
log.errorf("net Connect Err,url=%s", url);
|
||||
if (num > 0 && num < max) {
|
||||
num--;
|
||||
HttpGet(url, num);
|
||||
}
|
||||
}
|
||||
return "{}";
|
||||
}
|
||||
|
||||
public String httpPost(String url, Map<String, Object> params) {
|
||||
return httpPost(url, params, def_num);
|
||||
}
|
||||
|
||||
private String httpPost(String url, Map<String, Object> params, int num) {
|
||||
try {
|
||||
Response res = Http.post2(url, params, 6000);
|
||||
if (res.isOK()) {
|
||||
return res.getContent();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.errorf("net Connect Err,url=%s", url);
|
||||
if (num > 0 && num < max) {
|
||||
num--;
|
||||
httpPost(url, params, num);
|
||||
}
|
||||
}
|
||||
return "{}";
|
||||
}
|
||||
|
||||
public String HttpsGet(String url) {
|
||||
return HttpsGet(url, def_num);
|
||||
}
|
||||
|
||||
private String HttpsGet(String url, int num) {
|
||||
try {
|
||||
Http.disableJvmHttpsCheck();
|
||||
return Http.get(url).getContent();
|
||||
} catch (Exception e) {
|
||||
log.errorf("net Connect Err,url=%s", url);
|
||||
if (num > 0 && num < max) {
|
||||
num--;
|
||||
HttpsGet(url, num);
|
||||
}
|
||||
}
|
||||
return "{}";
|
||||
}
|
||||
|
||||
public String httpsPost(String url, Map<String, Object> params) {
|
||||
return httpsPost(url, params, def_num);
|
||||
}
|
||||
|
||||
private String httpsPost(String url, Map<String, Object> params, int num) {
|
||||
try {
|
||||
Http.disableJvmHttpsCheck();
|
||||
Response res = Http.post2(url, params, 6000);
|
||||
if (res.isOK()) {
|
||||
return res.getContent();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.errorf("net Connect Err,url=%s", url);
|
||||
if (num > 0 && num < max) {
|
||||
num--;
|
||||
httpsPost(url, params, num);
|
||||
}
|
||||
}
|
||||
return "{}";
|
||||
}
|
||||
|
||||
public String httpsPostBody(String url, String data) {
|
||||
return httpsPostBody(url, data, def_num);
|
||||
}
|
||||
|
||||
public String httpPostBody(String url, String data) {
|
||||
return httpPostBody(url, data, def_num);
|
||||
}
|
||||
|
||||
private String httpPostBody(String url, String data, int num) {
|
||||
Request req = Request.create(url, METHOD.POST);
|
||||
req.getHeader().set("Content-Type", "application/json:charset=utf-8 ");
|
||||
req.setData(data);
|
||||
try {
|
||||
Response resp = Sender.create(req).send();
|
||||
return resp.getContent();
|
||||
} catch (Exception e) {
|
||||
log.errorf("net Connect Err,url=%s", url);
|
||||
if (num > 0 && num < max) {
|
||||
num--;
|
||||
httpPostBody(url, data, num);
|
||||
}
|
||||
}
|
||||
return "{}";
|
||||
}
|
||||
|
||||
private String httpsPostBody(String url, String data, int num) {
|
||||
Http.disableJvmHttpsCheck();
|
||||
Request req = Request.create(url, METHOD.POST);
|
||||
req.getHeader().set("Content-Type", "application/json:charset=utf-8 ");
|
||||
req.setData(data);
|
||||
try {
|
||||
Response resp = Sender.create(req).send();
|
||||
return resp.getContent();
|
||||
} catch (Exception e) {
|
||||
log.errorf("net Connect Err,url=%s", url);
|
||||
if (num > 0 && num < max) {
|
||||
num--;
|
||||
httpsPostBody(url, data, num);
|
||||
}
|
||||
}
|
||||
return "{}";
|
||||
}
|
||||
|
||||
public <B> Map<String, B> result2Json(String jsonStr, Class<B> eleType) throws Exception {
|
||||
if (Strings.isBlank(jsonStr)) {
|
||||
throw Lang.makeThrow("%s callBack is Blank", getProviderId());
|
||||
}
|
||||
return Json.fromJsonAsMap(eleType, jsonStr);
|
||||
}
|
||||
|
||||
public <B> Map<String, B> result2Json(String jsonStr, Class<B> eleType, String def) throws Exception {
|
||||
return Json.fromJsonAsMap(eleType, Strings.isBlank(jsonStr) ? def : jsonStr);
|
||||
}
|
||||
|
||||
private final int max = 5;
|
||||
private final int def_num = 1;
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
package com.rekoe.mobile.provider;
|
||||
|
||||
public class PlatformProvider {
|
||||
|
||||
private final String providerId;
|
||||
private final String name;
|
||||
private final String pfid;
|
||||
|
||||
public PlatformProvider(final String providerId, final String name, final String pfid) {
|
||||
this.providerId = providerId;
|
||||
this.name = name;
|
||||
this.pfid = pfid;
|
||||
}
|
||||
|
||||
public String getProviderId() {
|
||||
return providerId;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public String getPfid() {
|
||||
return pfid;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,32 @@
|
|||
package com.rekoe.mobile.provider;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.nutz.lang.Lang;
|
||||
|
||||
public class PlatformProviderFactory {
|
||||
|
||||
private Map<String, PlatformProvider> platforms = new HashMap<String, PlatformProvider>();
|
||||
|
||||
public void setPlatformProviders(List<List<String>> platformProviders) {
|
||||
int len = platformProviders.size();
|
||||
for (int i = 0; i < len; i++) {
|
||||
List<String> args = platformProviders.get(i);
|
||||
int j = args.size();
|
||||
if (j != 3) {
|
||||
continue;
|
||||
}
|
||||
platforms.put(args.get(1), new PlatformProvider(args.get(0), args.get(2), args.get(1)));
|
||||
}
|
||||
}
|
||||
|
||||
public PlatformProvider getPlatformProvider(String pfid) {
|
||||
PlatformProvider pf = platforms.get(pfid);
|
||||
if (Lang.isEmpty(pf)) {
|
||||
Lang.makeThrow("Can`t define type[%s]", pfid);
|
||||
}
|
||||
return pf;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,40 @@
|
|||
package com.rekoe.mobile.provider.a91;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import com.rekoe.mobile.AbstractParam;
|
||||
import com.rekoe.utils.Constants;
|
||||
|
||||
public class A91Param extends AbstractParam implements Serializable{
|
||||
|
||||
private static final long serialVersionUID = -4493840542767841651L;
|
||||
private String sessionid;
|
||||
private int pid;
|
||||
|
||||
public void setSessionid(int pid, String sessionid) {
|
||||
this.sessionid = sessionid;
|
||||
this.pid = pid;
|
||||
}
|
||||
|
||||
public String getSessionid() {
|
||||
return sessionid;
|
||||
}
|
||||
|
||||
public void setSessionid(String sessionid) {
|
||||
this.sessionid = sessionid;
|
||||
}
|
||||
|
||||
public int getPid() {
|
||||
return pid;
|
||||
}
|
||||
|
||||
public void setPid(int pid) {
|
||||
this.pid = pid;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getProviderId(){
|
||||
return Constants.A91;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,58 @@
|
|||
package com.rekoe.mobile.provider.a91;
|
||||
|
||||
import java.net.URLDecoder;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.nutz.ioc.loader.annotation.IocBean;
|
||||
import org.nutz.json.Json;
|
||||
import org.nutz.lang.Lang;
|
||||
import org.nutz.log.Log;
|
||||
import org.nutz.log.Logs;
|
||||
import org.nutz.repo.Base64;
|
||||
|
||||
import com.rekoe.annotation.PlatformProvider;
|
||||
import com.rekoe.domain.PlatformConfig;
|
||||
import com.rekoe.mobile.Profile;
|
||||
import com.rekoe.mobile.provider.AbstractProvider;
|
||||
import com.rekoe.utils.Constants;
|
||||
|
||||
@IocBean
|
||||
@PlatformProvider(name = Constants.A91)
|
||||
public class A91Provider extends AbstractProvider<A91Param> {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
private final static Log log = Logs.get();
|
||||
private final String VALID_TOKEN_ADDR = "http://querysdkapi.91.com/CpLoginStateQuery.ashx";// 接口地址
|
||||
|
||||
@Override
|
||||
public String getProviderId() {
|
||||
return Constants.A91;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Profile verifyResponse(A91Param param) throws Exception {
|
||||
PlatformConfig platformConfig = getPlatformConfig(param.getPid());
|
||||
String str = platformConfig.getConfig().getString("appid") + param.getSessionid() + platformConfig.getConfig().getString("secret");// 签名
|
||||
String sign = Lang.md5(str);
|
||||
Map<String, Object> params = new HashMap<>();
|
||||
params.put("AppID", platformConfig.getConfig().getString("appid"));
|
||||
params.put("AccessToken", param.getSessionid());
|
||||
params.put("Sign", sign.toLowerCase());
|
||||
String result = httpPost(VALID_TOKEN_ADDR, params);
|
||||
A91ReturnParam ret = Json.fromJson(A91ReturnParam.class, result);
|
||||
if (ret.getResultCode() == 1) {
|
||||
String con = URLDecoder.decode(ret.getContent(), "utf-8");
|
||||
String temp = platformConfig.getConfig().getString("appid") + ret.getResultCode() + con + platformConfig.getConfig().getString("secret");
|
||||
String sign1 = Lang.md5(temp);
|
||||
if (sign1.equalsIgnoreCase(ret.getSign())) {
|
||||
A91UserInfo info = Json.fromJson(A91UserInfo.class, new String(Base64.decode(con)));
|
||||
return new Profile(getProviderId(), info.getUID(), param.getPid());
|
||||
}
|
||||
} else {
|
||||
log.error(result);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,53 @@
|
|||
package com.rekoe.mobile.provider.a91;
|
||||
|
||||
import org.nutz.json.JsonField;
|
||||
|
||||
public class A91ReturnParam {
|
||||
|
||||
@JsonField("AppID")
|
||||
private int appID;
|
||||
@JsonField("ResultCode")
|
||||
private int resultCode;
|
||||
@JsonField("ResultMsg")
|
||||
private String resultMsg;
|
||||
@JsonField("Sign")
|
||||
private String sign;
|
||||
@JsonField("Content")
|
||||
private String content;
|
||||
|
||||
|
||||
|
||||
public int getAppID() {
|
||||
return appID;
|
||||
}
|
||||
public void setAppID(int appID) {
|
||||
this.appID = appID;
|
||||
}
|
||||
public int getResultCode() {
|
||||
return resultCode;
|
||||
}
|
||||
public void setResultCode(int resultCode) {
|
||||
this.resultCode = resultCode;
|
||||
}
|
||||
public String getResultMsg() {
|
||||
return resultMsg;
|
||||
}
|
||||
public void setResultMsg(String resultMsg) {
|
||||
this.resultMsg = resultMsg;
|
||||
}
|
||||
public String getSign() {
|
||||
return sign;
|
||||
}
|
||||
public void setSign(String sign) {
|
||||
this.sign = sign;
|
||||
}
|
||||
public String getContent() {
|
||||
return content;
|
||||
}
|
||||
public void setContent(String content) {
|
||||
this.content = content;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
package com.rekoe.mobile.provider.a91;
|
||||
|
||||
public class A91UserInfo {
|
||||
private String UID;
|
||||
|
||||
public String getUID() {
|
||||
return UID;
|
||||
}
|
||||
|
||||
public void setUID(String uID) {
|
||||
UID = uID;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
package com.rekoe.mobile.provider.google;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import com.rekoe.mobile.provider.googlep.GooglePParam;
|
||||
import com.rekoe.utils.Constants;
|
||||
|
||||
public class GoogleParam extends GooglePParam implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = -1122775243733543089L;
|
||||
|
||||
@Override
|
||||
public String getProviderId() {
|
||||
return Constants.GOOGLE;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
package com.rekoe.mobile.provider.google;
|
||||
|
||||
import org.nutz.ioc.loader.annotation.IocBean;
|
||||
|
||||
import com.rekoe.annotation.PlatformProvider;
|
||||
import com.rekoe.mobile.provider.googlep.GooglePProvider;
|
||||
import com.rekoe.utils.Constants;
|
||||
|
||||
@IocBean
|
||||
@PlatformProvider(name = Constants.GOOGLE)
|
||||
public class GoogleProvider extends GooglePProvider {
|
||||
|
||||
private static final long serialVersionUID = 7944880275608182543L;
|
||||
|
||||
@Override
|
||||
public String getProviderId() {
|
||||
return Constants.GOOGLE;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,41 @@
|
|||
package com.rekoe.mobile.provider.googlep;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import com.rekoe.mobile.AbstractParam;
|
||||
import com.rekoe.utils.Constants;
|
||||
|
||||
public class GooglePParam extends AbstractParam implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = -1122775243733543089L;
|
||||
|
||||
private String token;
|
||||
|
||||
private int pid;
|
||||
|
||||
public GooglePParam() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getProviderId() {
|
||||
return Constants.GOOGLE_PLAY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPid() {
|
||||
return pid;
|
||||
}
|
||||
|
||||
public void setPid(int pid) {
|
||||
this.pid = pid;
|
||||
}
|
||||
|
||||
public String getToken() {
|
||||
return token;
|
||||
}
|
||||
|
||||
public void setToken(String token) {
|
||||
this.token = token;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,141 @@
|
|||
package com.rekoe.mobile.provider.googlep;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.nutz.http.Request;
|
||||
import org.nutz.http.Request.METHOD;
|
||||
import org.nutz.http.Sender;
|
||||
import org.nutz.ioc.loader.annotation.IocBean;
|
||||
import org.nutz.json.Json;
|
||||
import org.nutz.json.JsonFormat;
|
||||
import org.nutz.lang.Lang;
|
||||
import org.nutz.log.Log;
|
||||
import org.nutz.log.Logs;
|
||||
|
||||
import com.google.api.client.googleapis.auth.oauth2.GoogleCredential;
|
||||
import com.google.api.client.http.HttpTransport;
|
||||
import com.google.api.client.http.javanet.NetHttpTransport;
|
||||
import com.google.api.client.json.jackson2.JacksonFactory;
|
||||
import com.google.api.services.oauth2.Oauth2;
|
||||
import com.google.api.services.oauth2.model.Tokeninfo;
|
||||
import com.rekoe.annotation.PlatformProvider;
|
||||
import com.rekoe.domain.PlatformConfig;
|
||||
import com.rekoe.mobile.Profile;
|
||||
import com.rekoe.mobile.provider.AbstractProvider;
|
||||
import com.rekoe.utils.Constants;
|
||||
|
||||
@IocBean
|
||||
@PlatformProvider(name = Constants.GOOGLE_PLAY)
|
||||
public class GooglePProvider extends AbstractProvider<GooglePParam> {
|
||||
|
||||
private static final long serialVersionUID = 7944880275608182543L;
|
||||
private final static Log log = Logs.get();
|
||||
|
||||
private final HttpTransport TRANSPORT = new NetHttpTransport();
|
||||
private final JacksonFactory JSON_FACTORY = new JacksonFactory();
|
||||
|
||||
@Override
|
||||
public String getProviderId() {
|
||||
return Constants.GOOGLE_PLAY;
|
||||
}
|
||||
|
||||
/**
|
||||
* https://developers.google.com/identity/sign-in/android/offline-access
|
||||
*/
|
||||
@Override
|
||||
public Profile verifyResponse(GooglePParam param) throws Exception {
|
||||
TokenStatus info = validToken(param);
|
||||
if (info.isValid()) {
|
||||
Profile profile = new Profile(getProviderId(), info.getGplus_id(), param.getPid());
|
||||
profile.addv(Profile.TOKEN, param.getToken());
|
||||
return profile;
|
||||
}
|
||||
log.errorf("Err message %s", info.getMessage());
|
||||
return null;
|
||||
}
|
||||
|
||||
private TokenStatus validToken(GooglePParam param) throws IOException {
|
||||
PlatformConfig platformConfig = getPlatformConfig(param.getPid());
|
||||
String client_id = platformConfig.getConfig().getString("client_id");
|
||||
String applicationName = platformConfig.getConfig().getString("application_name", "zsdpay-1203");
|
||||
String accessToken = param.getToken();
|
||||
TokenStatus accessStatus = new TokenStatus();
|
||||
if (StringUtils.isNotBlank(accessToken)) {
|
||||
try {
|
||||
GoogleCredential credential = new GoogleCredential().setAccessToken(accessToken);
|
||||
Oauth2 oauth2 = new Oauth2.Builder(TRANSPORT, JSON_FACTORY, credential).setApplicationName(applicationName).build();
|
||||
Tokeninfo tokenInfo = oauth2.tokeninfo().setAccessToken(accessToken).execute();
|
||||
if (tokenInfo.containsKey("error")) {
|
||||
accessStatus.setValid(false);
|
||||
accessStatus.setId("");
|
||||
accessStatus.setMessage("Invalid Access Token.");
|
||||
} else if (!Lang.equals(client_id, tokenInfo.getIssuedTo())) {
|
||||
accessStatus.setValid(false);
|
||||
accessStatus.setId("");
|
||||
accessStatus.setMessage("Access Token not meant for this app.");
|
||||
} else {
|
||||
accessStatus.setValid(true);
|
||||
accessStatus.setId(tokenInfo.getUserId());
|
||||
accessStatus.setMessage("Access Token is valid.");
|
||||
}
|
||||
} catch (IOException e) {
|
||||
accessStatus.setValid(false);
|
||||
accessStatus.setId("");
|
||||
accessStatus.setMessage("Invalid Access Token.");
|
||||
}
|
||||
} else {
|
||||
accessStatus.setMessage("Access Token not provided");
|
||||
}
|
||||
return accessStatus;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
HttpTransport TRANSPORT = new NetHttpTransport();
|
||||
JacksonFactory JSON_FACTORY = new JacksonFactory();
|
||||
String applicationName = "zsdpay-1203";
|
||||
String token = "ya29.fgLVUDBWXuM91LAtvMdBXXWhCmKctjb44SK7Th8BO1yQ3DLfe3n_85Xi7PeLtQFsGEGOpQ";
|
||||
String client_id = "232182541248-8guj6heku6vpgdb7a3shmco33ns69lpm.apps.googleusercontent.com";
|
||||
String accessToken = token;
|
||||
TokenStatus accessStatus = new TokenStatus();
|
||||
if (StringUtils.isNotBlank(accessToken)) {
|
||||
try {
|
||||
GoogleCredential credential = new GoogleCredential().setAccessToken(accessToken);
|
||||
Oauth2 oauth2 = new Oauth2.Builder(TRANSPORT, JSON_FACTORY, credential).setApplicationName(applicationName).build();
|
||||
Tokeninfo tokenInfo = oauth2.tokeninfo().setAccessToken(accessToken).execute();
|
||||
if (tokenInfo.containsKey("error")) {
|
||||
accessStatus.setValid(false);
|
||||
accessStatus.setId("");
|
||||
accessStatus.setMessage("Invalid Access Token.");
|
||||
} else if (!Lang.equals(client_id, tokenInfo.getIssuedTo())) {
|
||||
accessStatus.setValid(false);
|
||||
accessStatus.setId("");
|
||||
accessStatus.setMessage("Access Token not meant for this app.");
|
||||
} else {
|
||||
accessStatus.setValid(true);
|
||||
accessStatus.setId(tokenInfo.getUserId());
|
||||
accessStatus.setMessage("Access Token is valid.");
|
||||
}
|
||||
} catch (IOException e) {
|
||||
accessStatus.setValid(false);
|
||||
accessStatus.setId("");
|
||||
accessStatus.setMessage("Invalid Access Token.");
|
||||
}
|
||||
} else {
|
||||
accessStatus.setMessage("Access Token not provided");
|
||||
}
|
||||
System.out.println(Json.toJson(accessStatus));
|
||||
}
|
||||
|
||||
public static void main1(String[] args) {
|
||||
Request req = Request.create("http://127.0.0.1:8080/api/list?pfid=1006200110011004", METHOD.POST);
|
||||
req.getHeader().set("Content-Type", "application/octet-stream;charset=UTF-8");
|
||||
Map<String, Object> params = new HashMap<String, Object>();
|
||||
params.put("pid", 1001);
|
||||
params.put("token", "ya29.dgJTpUrOQ9g1RHfXKXimjWHNSTKW5OPpb9--W51L_J5_u8anU_je2gAFFa4br_0NsRJY5g");
|
||||
req.setData(Json.toJson(params, JsonFormat.compact()));
|
||||
Sender.create(req).setTimeout(6000).send();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,43 @@
|
|||
package com.rekoe.mobile.provider.googlep;
|
||||
|
||||
public class TokenStatus {
|
||||
|
||||
private boolean valid;
|
||||
private String gplus_id;
|
||||
private String message;
|
||||
|
||||
public TokenStatus() {
|
||||
valid = false;
|
||||
gplus_id = "";
|
||||
message = "";
|
||||
}
|
||||
|
||||
public void setValid(boolean v) {
|
||||
this.valid = v;
|
||||
}
|
||||
|
||||
public void setId(String gplus_id) {
|
||||
this.gplus_id = gplus_id;
|
||||
}
|
||||
|
||||
public void setMessage(String message) {
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
public String getGplus_id() {
|
||||
return gplus_id;
|
||||
}
|
||||
|
||||
public void setGplus_id(String gplus_id) {
|
||||
this.gplus_id = gplus_id;
|
||||
}
|
||||
|
||||
public boolean isValid() {
|
||||
return valid;
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,45 @@
|
|||
package com.rekoe.mobile.provider.guest;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import com.rekoe.mobile.AbstractParam;
|
||||
import com.rekoe.utils.Constants;
|
||||
|
||||
public class GuestParam extends AbstractParam implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1240692439054026809L;
|
||||
private String openid;
|
||||
private int pid;
|
||||
|
||||
public GuestParam() {
|
||||
super();
|
||||
}
|
||||
|
||||
public GuestParam(int pid, String passportid) {
|
||||
super();
|
||||
this.openid = passportid;
|
||||
this.pid = pid;
|
||||
}
|
||||
|
||||
public String getOpenid() {
|
||||
return openid;
|
||||
}
|
||||
|
||||
public void setOpenid(String openid) {
|
||||
this.openid = openid;
|
||||
}
|
||||
|
||||
public void setPid(int pid) {
|
||||
this.pid = pid;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getProviderId() {
|
||||
return Constants.GUEST;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPid() {
|
||||
return this.pid;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
package com.rekoe.mobile.provider.guest;
|
||||
|
||||
import org.nutz.ioc.loader.annotation.IocBean;
|
||||
|
||||
import com.rekoe.annotation.PlatformProvider;
|
||||
import com.rekoe.mobile.Profile;
|
||||
import com.rekoe.mobile.provider.AbstractProvider;
|
||||
import com.rekoe.utils.Constants;
|
||||
|
||||
@IocBean
|
||||
@PlatformProvider(name = Constants.GUEST)
|
||||
public class GuestProvider extends AbstractProvider<GuestParam> {
|
||||
|
||||
private static final long serialVersionUID = 2882126009485835543L;
|
||||
|
||||
@Override
|
||||
public Profile verifyResponse(GuestParam param) throws Exception {
|
||||
return new Profile(getProviderId(), param.getOpenid(), param.getPid());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getProviderId() {
|
||||
return Constants.GUEST;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,39 @@
|
|||
package com.rekoe.mobile.provider.hw;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import com.rekoe.mobile.AbstractParam;
|
||||
import com.rekoe.utils.Constants;
|
||||
|
||||
public class HwParam extends AbstractParam implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = -1122775243733543089L;
|
||||
private String accessToken;
|
||||
private int pid;
|
||||
|
||||
public HwParam() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getProviderId() {
|
||||
return Constants.HW;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPid() {
|
||||
return pid;
|
||||
}
|
||||
|
||||
public String getAccessToken() {
|
||||
return accessToken;
|
||||
}
|
||||
|
||||
public void setAccessToken(String accessToken) {
|
||||
this.accessToken = accessToken;
|
||||
}
|
||||
|
||||
public void setPid(int pid) {
|
||||
this.pid = pid;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,61 @@
|
|||
package com.rekoe.mobile.provider.hw;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.nutz.ioc.loader.annotation.IocBean;
|
||||
import org.nutz.json.Json;
|
||||
import org.nutz.lang.Lang;
|
||||
import org.nutz.lang.Strings;
|
||||
import org.nutz.log.Log;
|
||||
import org.nutz.log.Logs;
|
||||
|
||||
import com.rekoe.annotation.PlatformProvider;
|
||||
import com.rekoe.mobile.Profile;
|
||||
import com.rekoe.mobile.provider.AbstractProvider;
|
||||
import com.rekoe.utils.Constants;
|
||||
|
||||
@IocBean
|
||||
@PlatformProvider(name = Constants.HW)
|
||||
public class HwProvider extends AbstractProvider<HwParam> {
|
||||
|
||||
private static final long serialVersionUID = 7944880275608182543L;
|
||||
private final static Log log = Logs.get();
|
||||
// 验证accessToken地址
|
||||
private static final String VALID_TOKEN_ADDR = "https://api.vmall.com/rest.php";
|
||||
|
||||
@Override
|
||||
public String getProviderId() {
|
||||
return Constants.HW;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Profile verifyResponse(HwParam param) throws Exception {
|
||||
UserInfo info = validToken(param);
|
||||
if (!Lang.isEmpty(info) && !Strings.isBlank(info.getUserID())) {
|
||||
return new Profile(getProviderId(), info.getUserID(), param.getPid());
|
||||
} else {
|
||||
log.errorf("Can`t find user info on platform %s", getProviderId());
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private UserInfo validToken(HwParam param) throws IOException {
|
||||
if (Lang.isEmpty(param)) {
|
||||
log.errorf("Can`t get %s Param", getProviderId());
|
||||
return null;
|
||||
}
|
||||
String accessToken = param.getAccessToken();
|
||||
if (!Strings.isBlank(accessToken)) {
|
||||
String postBody = "nsp_svc=OpenUP.User.getInfo&nsp_ts=";
|
||||
postBody += String.valueOf(System.currentTimeMillis() / 1000);
|
||||
postBody += "&access_token=" + java.net.URLEncoder.encode(accessToken, "utf-8");
|
||||
|
||||
String result = httpsPostBody(VALID_TOKEN_ADDR, postBody);
|
||||
return Json.fromJson(UserInfo.class, result);
|
||||
} else {
|
||||
log.errorf("%s access token is missing %s", getProviderId(), accessToken);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,84 @@
|
|||
package com.rekoe.mobile.provider.hw;
|
||||
|
||||
public class UserInfo {
|
||||
private String userID;
|
||||
|
||||
private String userName;
|
||||
|
||||
private String languageCode;
|
||||
|
||||
private int userState;
|
||||
|
||||
private int userValidStatus;
|
||||
|
||||
/**
|
||||
* @return the userID
|
||||
*/
|
||||
public String getUserID(){
|
||||
return userID;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param userID the userID to set
|
||||
*/
|
||||
public void setUserID(String userID){
|
||||
this.userID = userID;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the userName
|
||||
*/
|
||||
public String getUserName(){
|
||||
return userName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param userName the userName to set
|
||||
*/
|
||||
public void setUserName(String userName){
|
||||
this.userName = userName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the languageCode
|
||||
*/
|
||||
public String getLanguageCode(){
|
||||
return languageCode;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param languageCode the languageCode to set
|
||||
*/
|
||||
public void setLanguageCode(String languageCode){
|
||||
this.languageCode = languageCode;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the userState
|
||||
*/
|
||||
public int getUserState(){
|
||||
return userState;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param userState the userState to set
|
||||
*/
|
||||
public void setUserState(int userState){
|
||||
this.userState = userState;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the userValidStatus
|
||||
*/
|
||||
public int getUserValidStatus(){
|
||||
return userValidStatus;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param userValidStatus the userValidStatus to set
|
||||
*/
|
||||
public void setUserValidStatus(int userValidStatus){
|
||||
this.userValidStatus = userValidStatus;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,45 @@
|
|||
package com.rekoe.mobile.provider.msdk;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import com.rekoe.mobile.AbstractParam;
|
||||
import com.rekoe.utils.Constants;
|
||||
|
||||
public class MSDKParam extends AbstractParam implements Serializable {
|
||||
private static final long serialVersionUID = -8345954529141180606L;
|
||||
private String openid;
|
||||
private String ip;
|
||||
|
||||
public String getIp() {
|
||||
return ip;
|
||||
}
|
||||
|
||||
public void setIp(String ip) {
|
||||
this.ip = ip;
|
||||
}
|
||||
|
||||
private int pid;
|
||||
|
||||
public String getOpenid() {
|
||||
return openid;
|
||||
}
|
||||
|
||||
public void setOpenid(String openid) {
|
||||
this.openid = openid;
|
||||
}
|
||||
|
||||
public void setPid(int pid) {
|
||||
this.pid = pid;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getProviderId() {
|
||||
return Constants.MSDK;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPid() {
|
||||
return pid;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,84 @@
|
|||
package com.rekoe.mobile.provider.msdk;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.nutz.ioc.loader.annotation.IocBean;
|
||||
import org.nutz.json.Json;
|
||||
import org.nutz.json.JsonFormat;
|
||||
import org.nutz.lang.Lang;
|
||||
import org.nutz.lang.util.NutMap;
|
||||
import org.nutz.log.Log;
|
||||
import org.nutz.log.Logs;
|
||||
|
||||
import com.rekoe.annotation.PlatformProvider;
|
||||
import com.rekoe.domain.PlatformConfig;
|
||||
import com.rekoe.mobile.Profile;
|
||||
import com.rekoe.mobile.provider.AbstractProvider;
|
||||
import com.rekoe.utils.Constants;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author kouxian
|
||||
*
|
||||
*/
|
||||
@IocBean
|
||||
@PlatformProvider(name = Constants.MSDK)
|
||||
public class MSDKProvider extends AbstractProvider<MSDKParam> {
|
||||
|
||||
private static final long serialVersionUID = 2882126009485835543L;
|
||||
|
||||
private final static Log log = Logs.get();
|
||||
|
||||
public final static String MSDK_PROFILE = "MSDK_PROFILE";
|
||||
public final static String MSDK_PARAM = "MSDK_PARAM";
|
||||
|
||||
@Override
|
||||
public String getProviderId() {
|
||||
return Constants.MSDK;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Profile verifyResponse(MSDKParam p) throws Exception {
|
||||
PlatformConfig platformConfig = getPlatformConfig(p.getPid());
|
||||
NutMap config = platformConfig.getConfig();
|
||||
String appkey = config.getString("appkey");
|
||||
long appid = config.getAs("appid", Long.class);
|
||||
Map<String, Object> params = new HashMap<String, Object>();
|
||||
params.put("appid", appid);
|
||||
params.put("openid", p.getOpenid());
|
||||
params.put("openkey", appkey);
|
||||
params.put("userip", p.getIp());
|
||||
String uri = makeUri(p.getOpenid(), appid, appkey);
|
||||
String url = config.getString("valid_token_url") + uri;
|
||||
String data = Json.toJson(params, JsonFormat.compact());
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debugf("url >> %s", url);
|
||||
}
|
||||
String res = httpPostBody(url, data);
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debugf("back >> %s", res);
|
||||
}
|
||||
try {
|
||||
MSDKUserInfo userInfo = Json.fromJson(MSDKUserInfo.class, res);
|
||||
if (userInfo.getRet() == 0) {
|
||||
Profile profile = new Profile(getProviderId(), p.getOpenid(), p.getPid());
|
||||
profile.addv(MSDK_PROFILE, p);
|
||||
profile.addv(MSDK_PARAM, userInfo);
|
||||
profile.addv(Profile.TOKEN, p.getOpenid());
|
||||
return profile;
|
||||
} else {
|
||||
log.error(res);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error(e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private String makeUri(String openid, long appid, String appkey) {
|
||||
long timestamp = System.currentTimeMillis();
|
||||
String sig = Lang.md5(appkey + timestamp);
|
||||
return new StringBuilder().append("/?timestamp=").append(timestamp).append("&appid=").append(appid).append("&sig=").append(sig).append("&openid=").append(openid).append("&encode=1").toString();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,204 @@
|
|||
package com.rekoe.mobile.provider.msdk;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import org.nutz.json.JsonField;
|
||||
|
||||
public class MSDKUserInfo implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 580303315270742465L;
|
||||
|
||||
private int ret = -1;
|
||||
@JsonField(value = "is_lost")
|
||||
private int isLost = 1;
|
||||
private String nickname;
|
||||
private String gender;
|
||||
private String country;
|
||||
private String province;
|
||||
private String city;
|
||||
private String figureurl;
|
||||
@JsonField(value = "is_yellow_vip")
|
||||
private int isYellowVip;
|
||||
@JsonField(value = "is_yellow_year_vip")
|
||||
private int isYellowYearVip;
|
||||
@JsonField(value = "yellow_vip_level")
|
||||
private int yellowVipLevel;
|
||||
@JsonField(value = "is_yellow_high_vip")
|
||||
private int isYellowHighVip;
|
||||
@JsonField(value = "is_blue_vip")
|
||||
private boolean isBlueVip;
|
||||
@JsonField(value = "is_blue_year_vip")
|
||||
private boolean isBlueYearVip;
|
||||
@JsonField(value = "is_super_blue_vip")
|
||||
private boolean isSuperBlueVip;
|
||||
@JsonField(value = "blue_vip_level")
|
||||
private int blueVipLevel;
|
||||
@JsonField(value = "a3366_level")
|
||||
private int a3366Level;
|
||||
@JsonField(value = "a3366_level_name")
|
||||
private String a3366LevelName;
|
||||
@JsonField(value = "a3366_grow_level")
|
||||
private int a3366GrowLevel;
|
||||
@JsonField(value = "a3366_grow_value")
|
||||
private int a3366GrowValue;
|
||||
|
||||
public int getRet() {
|
||||
return ret;
|
||||
}
|
||||
|
||||
public void setRet(int ret) {
|
||||
this.ret = ret;
|
||||
}
|
||||
|
||||
public int getIsLost() {
|
||||
return isLost;
|
||||
}
|
||||
|
||||
public void setIsLost(int isLost) {
|
||||
this.isLost = isLost;
|
||||
}
|
||||
|
||||
public String getNickname() {
|
||||
return nickname;
|
||||
}
|
||||
|
||||
public void setNickname(String nickname) {
|
||||
this.nickname = nickname;
|
||||
}
|
||||
|
||||
public String getGender() {
|
||||
return gender;
|
||||
}
|
||||
|
||||
public void setGender(String gender) {
|
||||
this.gender = gender;
|
||||
}
|
||||
|
||||
public String getCountry() {
|
||||
return country;
|
||||
}
|
||||
|
||||
public void setCountry(String country) {
|
||||
this.country = country;
|
||||
}
|
||||
|
||||
public String getProvince() {
|
||||
return province;
|
||||
}
|
||||
|
||||
public void setProvince(String province) {
|
||||
this.province = province;
|
||||
}
|
||||
|
||||
public String getCity() {
|
||||
return city;
|
||||
}
|
||||
|
||||
public void setCity(String city) {
|
||||
this.city = city;
|
||||
}
|
||||
|
||||
public String getFigureurl() {
|
||||
return figureurl;
|
||||
}
|
||||
|
||||
public void setFigureurl(String figureurl) {
|
||||
this.figureurl = figureurl;
|
||||
}
|
||||
|
||||
public int getIsYellowVip() {
|
||||
return isYellowVip;
|
||||
}
|
||||
|
||||
public void setIsYellowVip(int isYellowVip) {
|
||||
this.isYellowVip = isYellowVip;
|
||||
}
|
||||
|
||||
public int getIsYellowYearVip() {
|
||||
return isYellowYearVip;
|
||||
}
|
||||
|
||||
public void setIsYellowYearVip(int isYellowYearVip) {
|
||||
this.isYellowYearVip = isYellowYearVip;
|
||||
}
|
||||
|
||||
public int getYellowVipLevel() {
|
||||
return yellowVipLevel;
|
||||
}
|
||||
|
||||
public void setYellowVipLevel(int yellowVipLevel) {
|
||||
this.yellowVipLevel = yellowVipLevel;
|
||||
}
|
||||
|
||||
public int getIsYellowHighVip() {
|
||||
return isYellowHighVip;
|
||||
}
|
||||
|
||||
public void setIsYellowHighVip(int isYellowHighVip) {
|
||||
this.isYellowHighVip = isYellowHighVip;
|
||||
}
|
||||
|
||||
public boolean isBlueVip() {
|
||||
return isBlueVip;
|
||||
}
|
||||
|
||||
public void setBlueVip(boolean isBlueVip) {
|
||||
this.isBlueVip = isBlueVip;
|
||||
}
|
||||
|
||||
public boolean isBlueYearVip() {
|
||||
return isBlueYearVip;
|
||||
}
|
||||
|
||||
public void setBlueYearVip(boolean isBlueYearVip) {
|
||||
this.isBlueYearVip = isBlueYearVip;
|
||||
}
|
||||
|
||||
public boolean isSuperBlueVip() {
|
||||
return isSuperBlueVip;
|
||||
}
|
||||
|
||||
public void setSuperBlueVip(boolean isSuperBlueVip) {
|
||||
this.isSuperBlueVip = isSuperBlueVip;
|
||||
}
|
||||
|
||||
public int getBlueVipLevel() {
|
||||
return blueVipLevel;
|
||||
}
|
||||
|
||||
public void setBlueVipLevel(int blueVipLevel) {
|
||||
this.blueVipLevel = blueVipLevel;
|
||||
}
|
||||
|
||||
public int getA3366Level() {
|
||||
return a3366Level;
|
||||
}
|
||||
|
||||
public void setA3366Level(int a3366Level) {
|
||||
this.a3366Level = a3366Level;
|
||||
}
|
||||
|
||||
public String getA3366LevelName() {
|
||||
return a3366LevelName;
|
||||
}
|
||||
|
||||
public void setA3366LevelName(String a3366LevelName) {
|
||||
this.a3366LevelName = a3366LevelName;
|
||||
}
|
||||
|
||||
public int getA3366GrowLevel() {
|
||||
return a3366GrowLevel;
|
||||
}
|
||||
|
||||
public void setA3366GrowLevel(int a3366GrowLevel) {
|
||||
this.a3366GrowLevel = a3366GrowLevel;
|
||||
}
|
||||
|
||||
public int getA3366GrowValue() {
|
||||
return a3366GrowValue;
|
||||
}
|
||||
|
||||
public void setA3366GrowValue(int a3366GrowValue) {
|
||||
this.a3366GrowValue = a3366GrowValue;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,40 @@
|
|||
package com.rekoe.mobile.provider.qihu360;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import com.rekoe.mobile.AbstractParam;
|
||||
import com.rekoe.utils.Constants;
|
||||
|
||||
public class QiHu360Param extends AbstractParam implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = -4558333251854028360L;
|
||||
private String sessionid;
|
||||
private int pid;
|
||||
|
||||
public String getSessionid() {
|
||||
return sessionid;
|
||||
}
|
||||
|
||||
public void setSessionid(int pid, String sessionid) {
|
||||
this.sessionid = sessionid;
|
||||
this.pid = pid;
|
||||
}
|
||||
|
||||
public int getPid() {
|
||||
return pid;
|
||||
}
|
||||
|
||||
public void setPid(int pid) {
|
||||
this.pid = pid;
|
||||
}
|
||||
|
||||
public void setSessionid(String sessionid) {
|
||||
this.sessionid = sessionid;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getProviderId() {
|
||||
return Constants.QIHU360;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,44 @@
|
|||
package com.rekoe.mobile.provider.qihu360;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.nutz.ioc.loader.annotation.IocBean;
|
||||
import org.nutz.lang.Strings;
|
||||
|
||||
import com.rekoe.annotation.PlatformProvider;
|
||||
import com.rekoe.mobile.Profile;
|
||||
import com.rekoe.mobile.provider.AbstractProvider;
|
||||
import com.rekoe.utils.Constants;
|
||||
|
||||
@IocBean
|
||||
@PlatformProvider(name = Constants.QIHU360)
|
||||
public class QiHu360Provider extends AbstractProvider<QiHu360Param> {
|
||||
|
||||
private static final long serialVersionUID = 2882126009485835543L;
|
||||
|
||||
private static final Map<String, String> ENDPOINTS;
|
||||
|
||||
static {
|
||||
ENDPOINTS = new HashMap<String, String>();
|
||||
ENDPOINTS.put(Constants.OAUTH_AUTHORIZATION_URL, "https://openapi.360.cn/user/me.json?access_token=");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getProviderId() {
|
||||
return Constants.QIHU360;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Profile verifyResponse(QiHu360Param param) throws Exception {
|
||||
String params = HttpsGet((ENDPOINTS.get(Constants.OAUTH_AUTHORIZATION_URL) + param.getSessionid()));
|
||||
if (!Strings.isBlank(params)) {
|
||||
Map<String, String> result = result2Json(params, String.class);
|
||||
String userId = result.get("id");
|
||||
if (!Strings.isBlank(params)) {
|
||||
return new Profile(getProviderId(), userId, param.getPid());
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,64 @@
|
|||
package com.rekoe.mobile.provider.qq;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import com.rekoe.mobile.AbstractParam;
|
||||
import com.rekoe.utils.Constants;
|
||||
|
||||
public class QQParam extends AbstractParam implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = -4898427425935858898L;
|
||||
private String openid;
|
||||
private String openkey;
|
||||
private String pf;
|
||||
private String platform;
|
||||
|
||||
public String getPlatform() {
|
||||
return platform;
|
||||
}
|
||||
|
||||
public void setPlatform(String platform) {
|
||||
this.platform = platform;
|
||||
}
|
||||
|
||||
public String getPf() {
|
||||
return pf;
|
||||
}
|
||||
|
||||
public void setPf(String pf) {
|
||||
this.pf = pf;
|
||||
}
|
||||
|
||||
private int pid;
|
||||
|
||||
public String getOpenid() {
|
||||
return openid;
|
||||
}
|
||||
|
||||
public void setOpenid(String openid) {
|
||||
this.openid = openid;
|
||||
}
|
||||
|
||||
public String getOpenkey() {
|
||||
return openkey;
|
||||
}
|
||||
|
||||
public void setOpenkey(String openkey) {
|
||||
this.openkey = openkey;
|
||||
}
|
||||
|
||||
public void setPid(int pid) {
|
||||
this.pid = pid;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getProviderId() {
|
||||
return Constants.QQ;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPid() {
|
||||
return pid;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,85 @@
|
|||
package com.rekoe.mobile.provider.qq;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URLEncoder;
|
||||
|
||||
import javax.crypto.Mac;
|
||||
import javax.crypto.spec.SecretKeySpec;
|
||||
|
||||
import org.nutz.ioc.loader.annotation.IocBean;
|
||||
import org.nutz.json.Json;
|
||||
import org.nutz.json.JsonFormat;
|
||||
import org.nutz.lang.Strings;
|
||||
import org.nutz.log.Log;
|
||||
import org.nutz.log.Logs;
|
||||
import org.nutz.repo.Base64;
|
||||
|
||||
import com.rekoe.annotation.PlatformProvider;
|
||||
import com.rekoe.domain.PlatformConfig;
|
||||
import com.rekoe.mobile.Profile;
|
||||
import com.rekoe.mobile.provider.AbstractProvider;
|
||||
import com.rekoe.utils.Constants;
|
||||
|
||||
@IocBean
|
||||
@PlatformProvider(name = Constants.QQ)
|
||||
public class QQProvider extends AbstractProvider<QQParam> {
|
||||
|
||||
private static final long serialVersionUID = 2882126009485835543L;
|
||||
|
||||
private final static Log log = Logs.get();
|
||||
|
||||
public final static String QQPARAM_KEY = "param";
|
||||
public final static String USERINFO_KEY = "userinfo";
|
||||
|
||||
@Override
|
||||
public String getProviderId() {
|
||||
return Constants.QQ;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Profile verifyResponse(QQParam p) throws Exception {
|
||||
PlatformConfig platformConfig = getPlatformConfig(p.getPid());
|
||||
String appkey = platformConfig.getConfig().getString("appkey");
|
||||
String appid = platformConfig.getConfig().getString("appid");
|
||||
String validateUrl = platformConfig.getConfig().getString("validate_url");
|
||||
String uri = paramEncode("/v3/user/get_info");
|
||||
String param = "appid=" + appid + "&format=json&openid=" + p.getOpenid() + "&openkey=" + p.getOpenkey() + "&pf=" + p.getPf();
|
||||
String get = "GET&" + uri + "&" + paramEncode(param);
|
||||
String sig = getSignature(get, appkey);
|
||||
String url = validateUrl + "/v3/user/get_info?openid=" + paramEncode(p.getOpenid()) + "&openkey=" + paramEncode(p.getOpenkey()) + "&appid=" + appid + "&sig=" + paramEncode(sig) + "&pf=" + paramEncode(p.getPf()) + "&format=" + paramEncode("json");
|
||||
String qqRes = HttpGet(url);
|
||||
QQUserInfo userInf = Json.fromJson(QQUserInfo.class, qqRes);
|
||||
if (userInf.getRet() == 0) {// ,
|
||||
Profile profile = new Profile(getProviderId(), p.getOpenid(), p.getPid());
|
||||
profile.addv(USERINFO_KEY, userInf);
|
||||
profile.addv(QQPARAM_KEY, p);
|
||||
return profile;
|
||||
} else {
|
||||
log.errorf("ProviderId >> %s,Param >> %s", getProviderId(), Json.toJson(p, JsonFormat.compact()));
|
||||
log.error(qqRes);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private String paramEncode(String param) throws UnsupportedEncodingException {
|
||||
return URLEncoder.encode(Strings.isBlank(param) ? "" : param, "UTF-8");
|
||||
}
|
||||
|
||||
private final String HMAC_SHA1 = "HmacSHA1";
|
||||
|
||||
public String getSignature(String data, String key) throws Exception {
|
||||
key += "&";
|
||||
data = encodeCompnentURL(data);
|
||||
byte[] keyBytes = key.getBytes();
|
||||
SecretKeySpec signingKey = new SecretKeySpec(keyBytes, HMAC_SHA1);
|
||||
Mac mac = Mac.getInstance(HMAC_SHA1);
|
||||
mac.init(signingKey);
|
||||
byte[] rawHmac = mac.doFinal(data.getBytes());
|
||||
return Base64.encodeToString(rawHmac, false);
|
||||
}
|
||||
|
||||
private String encodeCompnentURL(String url) throws UnsupportedEncodingException {
|
||||
String temp = url.replace("*", "%2A");
|
||||
return temp;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,208 @@
|
|||
package com.rekoe.mobile.provider.qq;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class QQUserInfo implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = -6009549946309845409L;
|
||||
private int ret = -1;
|
||||
private int is_lost = 1;
|
||||
private String nickname;
|
||||
private String gender;
|
||||
private String country;
|
||||
private String province;
|
||||
private String city;
|
||||
private String figureurl;
|
||||
private int is_yellow_vip;
|
||||
private int is_yellow_year_vip;
|
||||
private int yellow_vip_level;
|
||||
private int is_yellow_high_vip;
|
||||
// 是否蓝钻,是返回蓝钻等级,不是返回-1
|
||||
private boolean is_blue_vip;
|
||||
// 是否年费蓝钻
|
||||
private boolean is_blue_year_vip;
|
||||
// 也许是豪华蓝钻
|
||||
private boolean is_super_blue_vip;
|
||||
// 蓝钻等级
|
||||
private int blue_vip_level;
|
||||
private int a3366_level;
|
||||
private String a3366_level_name;
|
||||
private int a3366_grow_level;
|
||||
private int a3366_grow_value;
|
||||
|
||||
public int getA3366_level() {
|
||||
return a3366_level;
|
||||
}
|
||||
|
||||
public void setA3366_level(int a3366_level) {
|
||||
this.a3366_level = a3366_level;
|
||||
}
|
||||
|
||||
public String getA3366_level_name() {
|
||||
return a3366_level_name;
|
||||
}
|
||||
|
||||
public void setA3366_level_name(String a3366_level_name) {
|
||||
this.a3366_level_name = a3366_level_name;
|
||||
}
|
||||
|
||||
public int getA3366_grow_level() {
|
||||
return a3366_grow_level;
|
||||
}
|
||||
|
||||
public void setA3366_grow_level(int a3366_grow_level) {
|
||||
this.a3366_grow_level = a3366_grow_level;
|
||||
}
|
||||
|
||||
public int getA3366_grow_value() {
|
||||
return a3366_grow_value;
|
||||
}
|
||||
|
||||
public void setA3366_grow_value(int a3366_grow_value) {
|
||||
this.a3366_grow_value = a3366_grow_value;
|
||||
}
|
||||
|
||||
public int getRet() {
|
||||
return ret;
|
||||
}
|
||||
|
||||
public void setRet(int ret) {
|
||||
this.ret = ret;
|
||||
}
|
||||
|
||||
public int getIs_lost() {
|
||||
return is_lost;
|
||||
}
|
||||
|
||||
public void setIs_lost(int is_lost) {
|
||||
this.is_lost = is_lost;
|
||||
}
|
||||
|
||||
public String getNickname() {
|
||||
return nickname;
|
||||
}
|
||||
|
||||
public void setNickname(String nickname) {
|
||||
if (!checkName(nickname))
|
||||
this.nickname = nickname;
|
||||
}
|
||||
|
||||
public String getGender() {
|
||||
return gender;
|
||||
}
|
||||
|
||||
public void setGender(String gender) {
|
||||
this.gender = gender;
|
||||
}
|
||||
|
||||
public String getCountry() {
|
||||
return country;
|
||||
}
|
||||
|
||||
public void setCountry(String country) {
|
||||
this.country = country;
|
||||
}
|
||||
|
||||
public String getProvince() {
|
||||
return province;
|
||||
}
|
||||
|
||||
public void setProvince(String province) {
|
||||
this.province = province;
|
||||
}
|
||||
|
||||
public String getCity() {
|
||||
return city;
|
||||
}
|
||||
|
||||
public void setCity(String city) {
|
||||
this.city = city;
|
||||
}
|
||||
|
||||
public String getFigureurl() {
|
||||
return figureurl;
|
||||
}
|
||||
|
||||
public void setFigureurl(String figureurl) {
|
||||
this.figureurl = figureurl;
|
||||
}
|
||||
|
||||
public int getIs_yellow_vip() {
|
||||
return is_yellow_vip;
|
||||
}
|
||||
|
||||
public void setIs_yellow_vip(int is_yellow_vip) {
|
||||
this.is_yellow_vip = is_yellow_vip;
|
||||
}
|
||||
|
||||
public int getIs_yellow_year_vip() {
|
||||
return is_yellow_year_vip;
|
||||
}
|
||||
|
||||
public void setIs_yellow_year_vip(int is_yellow_year_vip) {
|
||||
this.is_yellow_year_vip = is_yellow_year_vip;
|
||||
}
|
||||
|
||||
public int getYellow_vip_level() {
|
||||
return yellow_vip_level;
|
||||
}
|
||||
|
||||
public void setYellow_vip_level(int yellow_vip_level) {
|
||||
this.yellow_vip_level = yellow_vip_level;
|
||||
}
|
||||
|
||||
public int getIs_yellow_high_vip() {
|
||||
return is_yellow_high_vip;
|
||||
}
|
||||
|
||||
public void setIs_yellow_high_vip(int is_yellow_high_vip) {
|
||||
this.is_yellow_high_vip = is_yellow_high_vip;
|
||||
}
|
||||
|
||||
public boolean isIs_blue_vip() {
|
||||
return is_blue_vip;
|
||||
}
|
||||
|
||||
public void setIs_blue_vip(boolean is_blue_vip) {
|
||||
this.is_blue_vip = is_blue_vip;
|
||||
}
|
||||
|
||||
public boolean isIs_blue_year_vip() {
|
||||
return is_blue_year_vip;
|
||||
}
|
||||
|
||||
public void setIs_blue_year_vip(boolean is_blue_year_vip) {
|
||||
this.is_blue_year_vip = is_blue_year_vip;
|
||||
}
|
||||
|
||||
public boolean isIs_super_blue_vip() {
|
||||
return is_super_blue_vip;
|
||||
}
|
||||
|
||||
public void setIs_super_blue_vip(boolean is_super_blue_vip) {
|
||||
this.is_super_blue_vip = is_super_blue_vip;
|
||||
}
|
||||
|
||||
public int getBlue_vip_level() {
|
||||
return blue_vip_level;
|
||||
}
|
||||
|
||||
public void setBlue_vip_level(int blue_vip_level) {
|
||||
this.blue_vip_level = blue_vip_level;
|
||||
}
|
||||
|
||||
public static boolean checkName(String name) {
|
||||
if (isMatches("[\\w]*", name))
|
||||
return false;
|
||||
return isMatches("[\u1F601-\u1F64F]+", name);
|
||||
}
|
||||
|
||||
public static boolean isMatches(String regex, String str) {
|
||||
Pattern p = Pattern.compile(regex);
|
||||
Matcher m = p.matcher(str);
|
||||
boolean b = m.matches();
|
||||
return b;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,40 @@
|
|||
package com.rekoe.mobile.provider.rk;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import com.rekoe.mobile.AbstractParam;
|
||||
import com.rekoe.utils.Constants;
|
||||
|
||||
public class RKParam extends AbstractParam implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1240692439054026809L;
|
||||
private String code;
|
||||
|
||||
private int pid;
|
||||
|
||||
public RKParam() {
|
||||
super();
|
||||
}
|
||||
|
||||
public void setPid(int pid) {
|
||||
this.pid = pid;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getProviderId() {
|
||||
return Constants.RK;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPid() {
|
||||
return this.pid;
|
||||
}
|
||||
|
||||
public String getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public void setCode(String code) {
|
||||
this.code = code;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,73 @@
|
|||
package com.rekoe.mobile.provider.rk;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.nutz.http.Http;
|
||||
import org.nutz.http.Response;
|
||||
import org.nutz.ioc.loader.annotation.IocBean;
|
||||
import org.nutz.json.Json;
|
||||
import org.nutz.lang.util.NutMap;
|
||||
import org.nutz.log.Log;
|
||||
import org.nutz.log.Logs;
|
||||
|
||||
import com.rekoe.annotation.PlatformProvider;
|
||||
import com.rekoe.domain.PlatformConfig;
|
||||
import com.rekoe.mobile.Profile;
|
||||
import com.rekoe.mobile.provider.AbstractProvider;
|
||||
import com.rekoe.utils.Constants;
|
||||
|
||||
@IocBean
|
||||
@PlatformProvider(name = Constants.RK)
|
||||
public class RKProvider extends AbstractProvider<RKParam> {
|
||||
|
||||
private static final long serialVersionUID = 2882126009485835543L;
|
||||
|
||||
private final static Log log = Logs.get();
|
||||
|
||||
private final static String TOKEN_VALIDATE = "/oauth/accessToken";
|
||||
private final static String TOKEN_FOR_USER = "/v1/openapi/userinfo?access_token=";
|
||||
|
||||
@Override
|
||||
public Profile verifyResponse(RKParam param) throws Exception {
|
||||
String code = param.getCode();
|
||||
PlatformConfig platformConfig = getPlatformConfig(param.getPid());
|
||||
String clientId = platformConfig.getConfig().getString("client_id");
|
||||
String grantType = platformConfig.getConfig().getString("grant_type");
|
||||
String clientSecret = platformConfig.getConfig().getString("client_secret");
|
||||
String redirectUri = platformConfig.getConfig().getString("redirect_uri");
|
||||
String validateUrl = platformConfig.getConfig().getString("validate_url");
|
||||
Map<String, Object> params = new HashMap<String, Object>();
|
||||
params.put("client_id", clientId);
|
||||
params.put("grant_type", grantType);
|
||||
params.put("client_secret", clientSecret);
|
||||
params.put("code", code);
|
||||
params.put("redirect_uri", redirectUri);
|
||||
try {
|
||||
Response res = Http.post2(validateUrl + TOKEN_VALIDATE, params, 60);
|
||||
if (res.isOK()) {
|
||||
String resultToken = res.getContent();
|
||||
NutMap map = Json.fromJson(NutMap.class, resultToken);
|
||||
String accessToken = map.getString("access_token");
|
||||
params.clear();
|
||||
if (StringUtils.isNotBlank(accessToken)) {
|
||||
params.put("access_token", accessToken);
|
||||
String resultvValidateToken = Http.get(validateUrl + TOKEN_FOR_USER + accessToken).getContent();
|
||||
NutMap userInfo = Json.fromJson(NutMap.class, resultvValidateToken);
|
||||
return new Profile(getProviderId(), userInfo.getString("uid"), param.getPid());
|
||||
}
|
||||
log.error(resultToken);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.errorf("url:[%s]", validateUrl);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getProviderId() {
|
||||
return Constants.RK;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,45 @@
|
|||
package com.rekoe.mobile.provider.sg;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import com.rekoe.mobile.AbstractParam;
|
||||
import com.rekoe.utils.Constants;
|
||||
|
||||
public class SGParam extends AbstractParam implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1240692439054026809L;
|
||||
private String openid;
|
||||
private int pid;
|
||||
|
||||
public SGParam() {
|
||||
super();
|
||||
}
|
||||
|
||||
public SGParam(int pid, String passportid) {
|
||||
super();
|
||||
this.openid = passportid;
|
||||
this.pid = pid;
|
||||
}
|
||||
|
||||
public String getOpenid() {
|
||||
return openid;
|
||||
}
|
||||
|
||||
public void setOpenid(String openid) {
|
||||
this.openid = openid;
|
||||
}
|
||||
|
||||
public void setPid(int pid) {
|
||||
this.pid = pid;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getProviderId() {
|
||||
return Constants.SG;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPid() {
|
||||
return this.pid;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
package com.rekoe.mobile.provider.sg;
|
||||
|
||||
import org.nutz.ioc.loader.annotation.IocBean;
|
||||
|
||||
import com.rekoe.annotation.PlatformProvider;
|
||||
import com.rekoe.mobile.Profile;
|
||||
import com.rekoe.mobile.provider.AbstractProvider;
|
||||
import com.rekoe.utils.Constants;
|
||||
|
||||
@IocBean
|
||||
@PlatformProvider(name = Constants.SG)
|
||||
public class SGProvider extends AbstractProvider<SGParam> {
|
||||
|
||||
private static final long serialVersionUID = 2882126009485835543L;
|
||||
|
||||
@Override
|
||||
public Profile verifyResponse(SGParam param) throws Exception {
|
||||
return new Profile(getProviderId(), param.getOpenid(), param.getPid());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getProviderId() {
|
||||
return Constants.SG;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
package com.rekoe.mobile.provider.uc;
|
||||
|
||||
public class UCResponse {
|
||||
|
||||
private UCResponseState state;
|
||||
private UCResponseData data;
|
||||
|
||||
public UCResponse(UCResponseState state, UCResponseData data) {
|
||||
this.state = state;
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
public UCResponse(UCResponseState state) {
|
||||
this.state = state;
|
||||
}
|
||||
|
||||
public UCResponseState getState() {
|
||||
return state;
|
||||
}
|
||||
|
||||
public UCResponseData getData() {
|
||||
return data;
|
||||
}
|
||||
|
||||
public void setData(UCResponseData data) {
|
||||
this.data = data;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
package com.rekoe.mobile.provider.uc;
|
||||
|
||||
public class UCResponseData {
|
||||
private String accountId;
|
||||
private String nickName;
|
||||
|
||||
public String getAccountId(){
|
||||
return accountId;
|
||||
}
|
||||
|
||||
public void setAccountId(String accountId){
|
||||
this.accountId = accountId;
|
||||
}
|
||||
|
||||
public String getNickName(){
|
||||
return nickName;
|
||||
}
|
||||
|
||||
public void setNickName(String nickName){
|
||||
this.nickName = nickName;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
package com.rekoe.mobile.provider.uc;
|
||||
|
||||
public class UCResponseState {
|
||||
|
||||
private int code;
|
||||
private String msg;
|
||||
|
||||
public int getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public void setCode(int code) {
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public String getMsg() {
|
||||
return msg;
|
||||
}
|
||||
|
||||
public void setMsg(String msg) {
|
||||
this.msg = msg;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,43 @@
|
|||
package com.rekoe.mobile.provider.uc;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import com.rekoe.mobile.AbstractParam;
|
||||
import com.rekoe.utils.Constants;
|
||||
|
||||
public class UcParam extends AbstractParam implements Serializable{
|
||||
|
||||
private static final long serialVersionUID = -2473883638175694140L;
|
||||
private String sid;
|
||||
private int pid;
|
||||
|
||||
public String getSid() {
|
||||
return sid;
|
||||
}
|
||||
|
||||
public UcParam() {
|
||||
}
|
||||
|
||||
public UcParam(int pid, String sid) {
|
||||
this.sid = sid;
|
||||
this.pid = pid;
|
||||
}
|
||||
|
||||
public int getPid() {
|
||||
return pid;
|
||||
}
|
||||
|
||||
public void setPid(int pid) {
|
||||
this.pid = pid;
|
||||
}
|
||||
|
||||
public void setSid(String sid) {
|
||||
this.sid = sid;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getProviderId() {
|
||||
return Constants.UC;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,108 @@
|
|||
package com.rekoe.mobile.provider.uc;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.nutz.http.Request;
|
||||
import org.nutz.http.Request.METHOD;
|
||||
import org.nutz.http.Response;
|
||||
import org.nutz.http.Sender;
|
||||
import org.nutz.ioc.loader.annotation.IocBean;
|
||||
import org.nutz.json.Json;
|
||||
import org.nutz.json.JsonFormat;
|
||||
import org.nutz.lang.Lang;
|
||||
import org.nutz.log.Log;
|
||||
import org.nutz.log.Logs;
|
||||
|
||||
import com.rekoe.annotation.PlatformProvider;
|
||||
import com.rekoe.domain.PlatformConfig;
|
||||
import com.rekoe.mobile.Profile;
|
||||
import com.rekoe.mobile.provider.AbstractProvider;
|
||||
import com.rekoe.utils.Constants;
|
||||
|
||||
@IocBean
|
||||
@PlatformProvider(name = Constants.UC)
|
||||
public class UcProvider extends AbstractProvider<UcParam> {
|
||||
|
||||
private static final long serialVersionUID = 2882126009485835543L;
|
||||
private final static Log log = Logs.get();
|
||||
|
||||
@Override
|
||||
public String getProviderId() {
|
||||
return Constants.UC;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Profile verifyResponse(UcParam param) throws Exception {
|
||||
PlatformConfig platformConfig = getPlatformConfig(param.getPid());
|
||||
String appkey = platformConfig.getConfig().getString("appkey");
|
||||
int appid = platformConfig.getConfig().getInt("appid");
|
||||
int secret = platformConfig.getConfig().getInt("secret");
|
||||
String validateUrl = platformConfig.getConfig().getString("validate_url");
|
||||
UCResponse response = response2(param.getSid(), appid, appkey, secret, validateUrl);
|
||||
if (response.getState().getCode() == 1) {
|
||||
Profile profile = new Profile(getProviderId(), response.getData().getAccountId(), param.getPid());
|
||||
profile.addv("token", param.getSid());
|
||||
return profile;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public UCResponse response(String sid, int appid, String appKey, String validateUrl) {
|
||||
Map<String, Object> params = new HashMap<>();
|
||||
params.put("id", System.currentTimeMillis());
|
||||
params.put("service", "ucid.bind.create");
|
||||
params.put("sign", Lang.md5("gameUser=" + sid + appKey));
|
||||
Map<String, Integer> gameParams = new HashMap<>();
|
||||
gameParams.put("gameId", appid);
|
||||
params.put("game", gameParams);
|
||||
Map<String, String> dataParams = new HashMap<>();
|
||||
params.put("data", dataParams);
|
||||
dataParams.put("gameUser", sid);
|
||||
String json = httpPostBody(validateUrl, Json.toJson(params, JsonFormat.compact()));
|
||||
Map<String, Object> m = Json.fromJsonAsMap(Object.class, json);
|
||||
Object obj = m.get("state");
|
||||
UCResponseState state = Lang.map2Object((Map<?, ?>) obj, UCResponseState.class);
|
||||
UCResponse res = new UCResponse(state);
|
||||
if (state.getCode() == 1) {
|
||||
res.setData(Lang.map2Object((Map<?, ?>) m.get("data"), UCResponseData.class));
|
||||
} else {
|
||||
log.error(json);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
private UCResponse response2(String sid, int appid, String appKey, int secret, String validateUrl) {
|
||||
Map<String, Object> params = new HashMap<>();
|
||||
params.put("id", System.currentTimeMillis());
|
||||
params.put("service", "ucid.user.sidInfo");
|
||||
params.put("encrypt", "md5");
|
||||
params.put("sign", Lang.md5(secret + "sid=" + sid + appKey));
|
||||
Map<String, Integer> gameParams = new HashMap<>();
|
||||
gameParams.put("cpId", secret);
|
||||
gameParams.put("gameId", appid);
|
||||
gameParams.put("channelId", 2);
|
||||
gameParams.put("serverId", 0);
|
||||
params.put("game", gameParams);
|
||||
Map<String, String> dataParams = new HashMap<>();
|
||||
dataParams.put("sid", sid);
|
||||
params.put("data", dataParams);
|
||||
Request req = Request.create(validateUrl, METHOD.POST);
|
||||
req.getHeader().set("Content-Type", "application/json:charset=utf-8 ");
|
||||
req.setData(Json.toJson(params, JsonFormat.compact()));
|
||||
Response resp = Sender.create(req).send();
|
||||
String json = resp.getContent();
|
||||
Map<String, Object> m = Json.fromJsonAsMap(Object.class, json);
|
||||
Object obj = m.get("state");
|
||||
UCResponseState state = Lang.map2Object((Map<?, ?>) obj, UCResponseState.class);
|
||||
UCResponse res = new UCResponse(state);
|
||||
if (state.getCode() == 1) {
|
||||
res.setData(Lang.map2Object((Map<?, ?>) m.get("data"), UCResponseData.class));
|
||||
} else {
|
||||
log.error(json);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,55 @@
|
|||
package com.rekoe.mobile.provider.xiaomi;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import com.rekoe.mobile.AbstractParam;
|
||||
import com.rekoe.utils.Constants;
|
||||
|
||||
public class XiaoMiParam extends AbstractParam implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = -5138092630114580043L;
|
||||
private String uid;
|
||||
private String token;
|
||||
private int pid;
|
||||
|
||||
public XiaoMiParam() {
|
||||
super();
|
||||
}
|
||||
|
||||
public XiaoMiParam(int pid, String uid, String token) {
|
||||
super();
|
||||
this.uid = uid;
|
||||
this.uid = token;
|
||||
this.pid = pid;
|
||||
}
|
||||
|
||||
public String getUid() {
|
||||
return uid;
|
||||
}
|
||||
|
||||
public void setUid(String uid) {
|
||||
this.uid = uid;
|
||||
}
|
||||
|
||||
public String getToken() {
|
||||
return token;
|
||||
}
|
||||
|
||||
public void setToken(String token) {
|
||||
this.token = token;
|
||||
}
|
||||
|
||||
public int getPid() {
|
||||
return pid;
|
||||
}
|
||||
|
||||
public void setPid(int pid) {
|
||||
this.pid = pid;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getProviderId() {
|
||||
return Constants.XIAOMI;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,59 @@
|
|||
package com.rekoe.mobile.provider.xiaomi;
|
||||
|
||||
import java.text.MessageFormat;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.nutz.ioc.loader.annotation.IocBean;
|
||||
import org.nutz.log.Log;
|
||||
import org.nutz.log.Logs;
|
||||
|
||||
import com.rekoe.annotation.PlatformProvider;
|
||||
import com.rekoe.domain.PlatformConfig;
|
||||
import com.rekoe.mobile.Profile;
|
||||
import com.rekoe.mobile.provider.AbstractProvider;
|
||||
import com.rekoe.utils.Constants;
|
||||
import com.rekoe.utils.HmacSHA1Encryption;
|
||||
|
||||
@IocBean
|
||||
@PlatformProvider(name = Constants.XIAOMI)
|
||||
public class XiaoMiProvider extends AbstractProvider<XiaoMiParam> {
|
||||
|
||||
private static final long serialVersionUID = 2882126009485835543L;
|
||||
|
||||
private final static Log log = Logs.get();
|
||||
|
||||
private final static String PARAM_URL_STR = "appId={0}&session={1}&uid={2}&signature={3}";
|
||||
private final static String ENCRYPT_TEXT = "appId={0}&session={1}&uid={2}";
|
||||
private static final Map<String, String> ENDPOINTS;
|
||||
|
||||
private final String ERROR_CODE = "{\"errcode\":-1}";
|
||||
static {
|
||||
ENDPOINTS = new HashMap<String, String>();
|
||||
ENDPOINTS.put(Constants.OAUTH_AUTHORIZATION_URL, "http://mis.migc.xiaomi.com/api/biz/service/verifySession.do?");
|
||||
}
|
||||
|
||||
public Map<String, Integer> checkUserAndroidMiLogin(String sdkUin, String sdkToken, String appid, String secret) throws Exception {
|
||||
String encryptText = MessageFormat.format(ENCRYPT_TEXT, appid, sdkToken, sdkUin);
|
||||
String signature = HmacSHA1Encryption.HmacSHA1Encrypt(encryptText, secret);
|
||||
String getUrl = ENDPOINTS.get(Constants.OAUTH_AUTHORIZATION_URL) + MessageFormat.format(PARAM_URL_STR, appid, sdkToken, sdkUin, signature);
|
||||
return result2Json(HttpGet(getUrl), Integer.class, ERROR_CODE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getProviderId() {
|
||||
return Constants.XIAOMI;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Profile verifyResponse(XiaoMiParam param) throws Exception {
|
||||
PlatformConfig platformConfig = getPlatformConfig(param.getPid());
|
||||
Map<String, Integer> params = checkUserAndroidMiLogin(param.getUid(), param.getToken(), platformConfig.getConfig().getString("appid"), platformConfig.getConfig().getString("secret"));
|
||||
if (params.get("errcode") == 200) {
|
||||
return new Profile(getProviderId(), param.getUid(), param.getPid());
|
||||
} else {
|
||||
log.errorf("ProviderId:%s,errCode:%s", getProviderId(), params);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,117 @@
|
|||
package com.rekoe.module;
|
||||
|
||||
import java.net.URISyntaxException;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.apache.oltu.oauth2.as.issuer.MD5Generator;
|
||||
import org.apache.oltu.oauth2.as.issuer.OAuthIssuer;
|
||||
import org.apache.oltu.oauth2.as.issuer.OAuthIssuerImpl;
|
||||
import org.apache.oltu.oauth2.as.request.OAuthTokenRequest;
|
||||
import org.apache.oltu.oauth2.as.response.OAuthASResponse;
|
||||
import org.apache.oltu.oauth2.common.OAuth;
|
||||
import org.apache.oltu.oauth2.common.error.OAuthError;
|
||||
import org.apache.oltu.oauth2.common.exception.OAuthProblemException;
|
||||
import org.apache.oltu.oauth2.common.exception.OAuthSystemException;
|
||||
import org.apache.oltu.oauth2.common.message.OAuthResponse;
|
||||
import org.apache.oltu.oauth2.common.message.types.GrantType;
|
||||
import org.nutz.ioc.loader.annotation.Inject;
|
||||
import org.nutz.ioc.loader.annotation.IocBean;
|
||||
import org.nutz.mvc.annotation.At;
|
||||
import org.nutz.mvc.annotation.By;
|
||||
import org.nutz.mvc.annotation.Filters;
|
||||
import org.nutz.mvc.annotation.Ok;
|
||||
import org.nutz.mvc.annotation.POST;
|
||||
import org.nutz.mvc.annotation.Param;
|
||||
|
||||
import com.rekoe.filter.OauthCrossOriginFilter;
|
||||
import com.rekoe.service.OAuthService;
|
||||
import com.rekoe.utils.Constants;
|
||||
|
||||
@IocBean
|
||||
@At("/oauth")
|
||||
public class AccessTokenModule {
|
||||
|
||||
@Inject
|
||||
private OAuthService oAuthService;
|
||||
|
||||
/**
|
||||
* @api {post} /oauth/accessToken 换取accessToken
|
||||
*
|
||||
* @apiGroup User
|
||||
* @apiVersion 1.0.0
|
||||
* @apiSampleRequest http://warlogin.shanggame.com/oauth/accessToken
|
||||
*
|
||||
* @apiParam {String} client_id 应用id
|
||||
* @apiParam {String} client_secret 应用secret
|
||||
*
|
||||
* @apiParam {String} grant_type=authorization_code 用于传递授权码的参数名
|
||||
* @apiParam {String} code 用户登录授权后的授权码
|
||||
* @apiParam {String} [redirect_uri=http://www.rekoe.com] 回调地址
|
||||
*
|
||||
* @apiSuccess {int} expires_in=3600 accessToken过期时间 单位(秒)
|
||||
* @apiSuccess {String} access_token accessToken值
|
||||
*
|
||||
* @apiSuccessExample {json} Success-Response:
|
||||
* {"expires_in":3600,"access_token":"223ae05dfbb0794396fb60a0960c197e"}
|
||||
*/
|
||||
|
||||
@At
|
||||
@Ok("raw:json")
|
||||
@Filters(@By(type = OauthCrossOriginFilter.class))
|
||||
public String accessToken(HttpServletRequest request) throws URISyntaxException, OAuthSystemException {
|
||||
try {
|
||||
// 构建OAuth请求
|
||||
OAuthTokenRequest oauthRequest = new OAuthTokenRequest(request);
|
||||
// 检查提交的客户端id是否正确
|
||||
if (!oAuthService.checkClientId(oauthRequest.getClientId())) {
|
||||
OAuthResponse response = OAuthASResponse.errorResponse(HttpServletResponse.SC_BAD_REQUEST).setError(OAuthError.TokenResponse.INVALID_CLIENT).setErrorDescription(Constants.INVALID_CLIENT_ID).buildJSONMessage();
|
||||
return response.getBody();
|
||||
}
|
||||
// 检查客户端安全KEY是否正确
|
||||
if (!oAuthService.checkClientSecret(oauthRequest.getClientSecret())) {
|
||||
OAuthResponse response = OAuthASResponse.errorResponse(HttpServletResponse.SC_UNAUTHORIZED).setError(OAuthError.TokenResponse.UNAUTHORIZED_CLIENT).setErrorDescription(Constants.INVALID_CLIENT_ID).buildJSONMessage();
|
||||
return response.getBody();
|
||||
}
|
||||
String authCode = oauthRequest.getParam(OAuth.OAUTH_CODE);
|
||||
// 检查验证类型,此处只检查AUTHORIZATION_CODE类型,其他的还有PASSWORD或REFRESH_TOKEN
|
||||
if (oauthRequest.getParam(OAuth.OAUTH_GRANT_TYPE).equals(GrantType.AUTHORIZATION_CODE.toString())) {
|
||||
if (!oAuthService.checkAuthCode(authCode)) {
|
||||
OAuthResponse response = OAuthASResponse.errorResponse(HttpServletResponse.SC_BAD_REQUEST).setError(OAuthError.TokenResponse.INVALID_GRANT).setErrorDescription(Constants.INVALID_AUTH_CODE).buildJSONMessage();
|
||||
return response.getBody();
|
||||
}
|
||||
}
|
||||
// 生成Access Token
|
||||
OAuthIssuer oauthIssuerImpl = new OAuthIssuerImpl(new MD5Generator());
|
||||
final String accessToken = oauthIssuerImpl.accessToken();
|
||||
oAuthService.addAccessToken(accessToken, oAuthService.getUsernameByAuthCode(authCode));
|
||||
// 生成OAuth响应
|
||||
OAuthResponse response = OAuthASResponse.tokenResponse(HttpServletResponse.SC_OK).setAccessToken(accessToken).setExpiresIn(String.valueOf(oAuthService.getExpireIn())).buildJSONMessage();
|
||||
// 根据OAuthResponse生成ResponseEntity
|
||||
return response.getBody();
|
||||
} catch (OAuthProblemException e) {
|
||||
// 构建错误响应
|
||||
OAuthResponse res = OAuthASResponse.errorResponse(HttpServletResponse.SC_BAD_REQUEST).error(e).buildJSONMessage();
|
||||
return res.getBody();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证accessToken
|
||||
*
|
||||
* @param accessToken
|
||||
* @return
|
||||
*/
|
||||
@At
|
||||
@POST
|
||||
public void checkAccessToken(@Param("accessToken") String accessToken, HttpServletResponse res) {
|
||||
boolean b = oAuthService.checkAccessToken(accessToken);
|
||||
if (b) {
|
||||
res.setStatus(HttpServletResponse.SC_OK);
|
||||
} else {
|
||||
res.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,149 @@
|
|||
package com.rekoe.module;
|
||||
|
||||
import java.net.URISyntaxException;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.apache.oltu.oauth2.as.issuer.MD5Generator;
|
||||
import org.apache.oltu.oauth2.as.issuer.OAuthIssuerImpl;
|
||||
import org.apache.oltu.oauth2.as.request.OAuthAuthzRequest;
|
||||
import org.apache.oltu.oauth2.common.OAuth;
|
||||
import org.apache.oltu.oauth2.common.exception.OAuthProblemException;
|
||||
import org.apache.oltu.oauth2.common.exception.OAuthSystemException;
|
||||
import org.apache.oltu.oauth2.common.message.types.ResponseType;
|
||||
import org.nutz.ioc.loader.annotation.Inject;
|
||||
import org.nutz.ioc.loader.annotation.IocBean;
|
||||
import org.nutz.lang.Strings;
|
||||
import org.nutz.lang.util.NutMap;
|
||||
import org.nutz.log.Log;
|
||||
import org.nutz.log.Logs;
|
||||
import org.nutz.mvc.annotation.At;
|
||||
import org.nutz.mvc.annotation.By;
|
||||
import org.nutz.mvc.annotation.Filters;
|
||||
import org.nutz.mvc.annotation.Ok;
|
||||
import org.nutz.mvc.annotation.POST;
|
||||
|
||||
import com.rekoe.domain.OAuthUser;
|
||||
import com.rekoe.filter.OauthCrossOriginFilter;
|
||||
import com.rekoe.utils.CommonUtils;
|
||||
|
||||
/**
|
||||
* @apiDefine TOKEN_ERROR
|
||||
* @apiError 403 The <code>accesstoken</code> is invaild
|
||||
*/
|
||||
/**
|
||||
* @apiDefine TOKEN
|
||||
* @apiParam {String} accesstoken 访问凭证
|
||||
*
|
||||
*/
|
||||
@At("/api/v1/")
|
||||
@IocBean
|
||||
@Filters(@By(type = OauthCrossOriginFilter.class))
|
||||
public class AuthorizeAction {
|
||||
|
||||
private final static Log log = Logs.get();
|
||||
|
||||
@Inject
|
||||
private com.rekoe.service.OAuthService oAuthService;
|
||||
@Inject
|
||||
private com.rekoe.service.OAuthClientService oAuthClientService;
|
||||
@Inject
|
||||
private com.rekoe.service.OAuthUserService oAuthUserService;
|
||||
|
||||
/**
|
||||
* @apiDefine CODE_200
|
||||
* @apiSuccess (Reponse 200) {number} code 200
|
||||
* @apiSuccess (Reponse 200) {json} [data='""'] 如果有数据返回
|
||||
* @apiSuccessExample {json} Response 200
|
||||
* {
|
||||
* "code":200,
|
||||
* "feedback":0,
|
||||
* "msg","Ok"
|
||||
* }
|
||||
*/
|
||||
|
||||
/**
|
||||
* @api {post} /api/v1/authorize 请求授权码
|
||||
* @apiSampleRequest http://warlogin.shanggame.com/api/v1/authorize
|
||||
* @apiDescription 用户输入正确的用户名和密码以POST方式提交后会重定向到用户所填的回调地址并在地址后携带授权码.
|
||||
* @apiGroup User
|
||||
* @apiVersion 1.0.0
|
||||
*
|
||||
* @apiParam {String} username 用户名
|
||||
* @apiParam {String} password 密码
|
||||
* @apiParam {String} client_id 应用id
|
||||
* @apiParam {String} response_type=code 返回授权码的标识
|
||||
*
|
||||
* @apiSuccess (成功返回值) {int} feedback 响应状态 0 为成功
|
||||
* @apiSuccess (成功返回值) {String} msg 错误描述
|
||||
* @apiSuccess (成功返回值) {String} code 授权码
|
||||
* @apiSuccessExample {json} Success-Response:
|
||||
* {
|
||||
* "code":"c1b0a32d71101d00f4c96a134ec6bd42",
|
||||
* "feedback": 0,
|
||||
* "msg": "Ok"
|
||||
* }
|
||||
*/
|
||||
|
||||
@At
|
||||
@Ok("json")
|
||||
@POST
|
||||
public NutMap authorize(HttpServletRequest request, HttpServletResponse res) throws URISyntaxException, OAuthSystemException {
|
||||
try {
|
||||
// 构建OAuth 授权请求
|
||||
OAuthAuthzRequest oauthRequest = new OAuthAuthzRequest(request);
|
||||
// 检查传入的客户端id是否正确
|
||||
if (!oAuthService.checkClientId(oauthRequest.getClientId())) {
|
||||
return NutMap.NEW().addv("feedback", 2);
|
||||
}
|
||||
|
||||
// 如果用户没有登录,跳转到登陆页面
|
||||
if (!login(request)) {// 登录失败时跳转到登陆页面
|
||||
return NutMap.NEW().addv("feedback", 3).addv("msg", "登陆失败");
|
||||
}
|
||||
|
||||
String username = request.getParameter("username"); // 获取用户名
|
||||
// responseType目前仅支持CODE,另外还有TOKEN
|
||||
NutMap map = NutMap.NEW();
|
||||
String responseType = oauthRequest.getParam(OAuth.OAUTH_RESPONSE_TYPE);
|
||||
if (responseType.equals(ResponseType.CODE.toString())) {
|
||||
OAuthIssuerImpl oauthIssuerImpl = new OAuthIssuerImpl(new MD5Generator());
|
||||
String authorizationCode = oauthIssuerImpl.authorizationCode();
|
||||
oAuthService.addAuthCode(authorizationCode, username);
|
||||
map.addv("code", authorizationCode);
|
||||
} else {
|
||||
return map.addv("feedback", 4).addv("msg", "参数错误");
|
||||
}
|
||||
map.addv("feedback", 0).addv("msg", "Ok");
|
||||
return map;
|
||||
} catch (OAuthProblemException e) {
|
||||
log.error(e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private boolean login(HttpServletRequest request) {
|
||||
NutMap parames = CommonUtils.getRequestParametersMap(request);
|
||||
String username = parames.getString("username");
|
||||
String password = parames.getString("password");
|
||||
if (Strings.isEmpty(username) || Strings.isEmpty(password)) {
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
OAuthUser user = oAuthUserService.findByUsername(username);
|
||||
if (user != null) {
|
||||
if (!oAuthUserService.checkUser(username, password, user.getSalt(), user.getPassword())) {
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error(e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,127 @@
|
|||
package com.rekoe.module;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.nutz.dao.Dao;
|
||||
import org.nutz.dao.entity.Record;
|
||||
import org.nutz.dao.util.Daos;
|
||||
import org.nutz.ioc.loader.annotation.Inject;
|
||||
import org.nutz.log.Log;
|
||||
import org.nutz.log.Logs;
|
||||
import org.nutz.web.ajax.AjaxReturn;
|
||||
|
||||
import com.rekoe.common.Message;
|
||||
import com.rekoe.domain.GameServer;
|
||||
import com.rekoe.service.GameServerService;
|
||||
|
||||
public class BaseAction {
|
||||
private final static Log log = Logs.get();
|
||||
|
||||
@Inject
|
||||
public GameServerService gameServerService;
|
||||
|
||||
protected Message responseMessage(AjaxReturn result, HttpServletRequest req) {
|
||||
return result.isOk() ? Message.success("admin.common.ok", req) : Message.error(StringUtils.defaultString(result.getMsg(), "admin.common.resopnse.error"), req);
|
||||
}
|
||||
|
||||
public GameServer getServer(int id) {
|
||||
GameServer server = gameServerService.getServer(id);
|
||||
return server;
|
||||
}
|
||||
|
||||
public List<Integer> getAllServerIDs() {
|
||||
return gameServerService.getAllIds();
|
||||
}
|
||||
|
||||
public int getPage(Integer page) {
|
||||
return page == null ? 1 : page.intValue();
|
||||
}
|
||||
|
||||
public boolean checkTableExist(final Dao dao, final Class<?> classOfT, String time) {
|
||||
return Daos.ext(dao, time).exists(classOfT);
|
||||
}
|
||||
|
||||
public class down {
|
||||
private ByteArrayOutputStream bout = new ByteArrayOutputStream();
|
||||
|
||||
public ByteArrayOutputStream invoke(String[] heads, List<Record> records, DownCallBack callBack) throws IOException {
|
||||
StringBuffer sb = new StringBuffer();
|
||||
for (String head : heads) {
|
||||
sb.append(head).append(",");
|
||||
}
|
||||
sb.delete(sb.length() - 1, sb.length());
|
||||
bout.write(sb.toString().getBytes());
|
||||
bout.write(new byte[] { 13, 10 });
|
||||
for (final Record record : records) {
|
||||
bout.write(download(callBack, record));
|
||||
}
|
||||
bout.close();
|
||||
return bout;
|
||||
}
|
||||
|
||||
public ByteArrayOutputStream invoke(List<Record> records, DownCallBack callBack) throws IOException {
|
||||
for (final Record record : records) {
|
||||
bout.write(download(callBack, record));
|
||||
}
|
||||
bout.close();
|
||||
return bout;
|
||||
}
|
||||
|
||||
private byte[] download(DownCallBack callBack, Record record) {
|
||||
ByteArrayOutputStream bout = new ByteArrayOutputStream();
|
||||
DataOutputStream dout = new DataOutputStream(bout);
|
||||
try {
|
||||
callBack.invoke(dout, record);
|
||||
dout.write(new byte[] { 13, 10 });
|
||||
bout.close();
|
||||
dout.close();
|
||||
} catch (IOException e) {
|
||||
log.error(e.getMessage());
|
||||
}
|
||||
return bout.toByteArray();
|
||||
}
|
||||
}
|
||||
|
||||
public interface DownCallBack {
|
||||
public void invoke(DataOutputStream dout, Record record) throws IOException;
|
||||
}
|
||||
|
||||
public class DefaultDownCallBack implements DownCallBack {
|
||||
|
||||
private String[] heads;
|
||||
|
||||
public DefaultDownCallBack(String[] heads) {
|
||||
this.heads = heads;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void invoke(DataOutputStream dout, org.nutz.dao.entity.Record record) throws IOException {
|
||||
StringBuffer sb = new StringBuffer();
|
||||
for (String str : heads) {
|
||||
sb.append(record.getString(str)).append(",");
|
||||
}
|
||||
dout.write(sb.toString().getBytes());
|
||||
}
|
||||
}
|
||||
|
||||
public ByteArrayOutputStream loadDown(List<Record> records) throws IOException {
|
||||
ByteArrayOutputStream bout = new ByteArrayOutputStream();
|
||||
if (!records.isEmpty()) {
|
||||
Record r = records.get(0);
|
||||
Set<String> set = r.keySet();
|
||||
List<String> keys = new ArrayList<>(set);
|
||||
String[] heads = keys.toArray(new String[keys.size()]);
|
||||
DownCallBack callBack = new DefaultDownCallBack(heads);
|
||||
bout = new down().invoke(heads, records, callBack);
|
||||
}
|
||||
return bout;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,63 @@
|
|||
package com.rekoe.module;
|
||||
|
||||
public class CdkeyBean {
|
||||
|
||||
private String sign;
|
||||
private String cdkey;
|
||||
private String mac;
|
||||
private int pid;
|
||||
private String providerId;
|
||||
|
||||
public CdkeyBean() {
|
||||
super();
|
||||
}
|
||||
|
||||
public CdkeyBean(String sign, String cdkey, String mac, int pid, String providerId) {
|
||||
super();
|
||||
this.sign = sign;
|
||||
this.cdkey = cdkey;
|
||||
this.mac = mac;
|
||||
this.pid = pid;
|
||||
this.providerId = providerId;
|
||||
}
|
||||
|
||||
public String getSign() {
|
||||
return sign;
|
||||
}
|
||||
|
||||
public void setSign(String sign) {
|
||||
this.sign = sign;
|
||||
}
|
||||
|
||||
public String getMac() {
|
||||
return mac;
|
||||
}
|
||||
|
||||
public void setMac(String mac) {
|
||||
this.mac = mac;
|
||||
}
|
||||
|
||||
public int getPid() {
|
||||
return pid;
|
||||
}
|
||||
|
||||
public void setPid(int pid) {
|
||||
this.pid = pid;
|
||||
}
|
||||
|
||||
public String getProviderId() {
|
||||
return providerId;
|
||||
}
|
||||
|
||||
public void setProviderId(String providerId) {
|
||||
this.providerId = providerId;
|
||||
}
|
||||
|
||||
public String getCdkey() {
|
||||
return cdkey;
|
||||
}
|
||||
|
||||
public void setCdkey(String cdkey) {
|
||||
this.cdkey = cdkey;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,70 @@
|
|||
package com.rekoe.module;
|
||||
|
||||
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.util.NutMap;
|
||||
import org.nutz.log.Log;
|
||||
import org.nutz.log.Logs;
|
||||
import org.nutz.mvc.adaptor.JsonAdaptor;
|
||||
import org.nutz.mvc.annotation.AdaptBy;
|
||||
import org.nutz.mvc.annotation.At;
|
||||
import org.nutz.mvc.annotation.Ok;
|
||||
import org.nutz.mvc.annotation.POST;
|
||||
|
||||
import com.rekoe.domain.CdkeyLog;
|
||||
import com.rekoe.service.CdKeyCategoryService;
|
||||
import com.rekoe.service.CdKeyLogService;
|
||||
import com.rekoe.service.CdKeyService;
|
||||
|
||||
@IocBean
|
||||
@At("/excharge")
|
||||
public class ExchargeAction {
|
||||
|
||||
private final static Log log = Logs.get();
|
||||
@Inject
|
||||
private CdKeyService cdKeyService;
|
||||
|
||||
@Inject
|
||||
private CdKeyCategoryService cdKeyCategoryService;
|
||||
|
||||
@Inject
|
||||
private CdKeyLogService cdKeyLogService;
|
||||
|
||||
@Inject
|
||||
private PropertiesProxy conf;
|
||||
|
||||
@At
|
||||
@Ok("json")
|
||||
@POST
|
||||
@AdaptBy(type = JsonAdaptor.class)
|
||||
public NutMap cdk(CdkeyBean bean) {
|
||||
StringBuffer sb = new StringBuffer("cdk.");
|
||||
sb.append(bean.getPid()).append(".secret");
|
||||
String secret = conf.get(sb.toString());
|
||||
String sign = Lang.md5(bean.getCdkey() + "|" + bean.getMac() + "|" + bean.getPid() + "|" + secret);
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debugf("secretKey : %s", sb);
|
||||
log.debugf("secret : %s", secret);
|
||||
log.debugf("Cdkey : %s", bean.getCdkey());
|
||||
log.debugf("Mac : %s", bean.getMac());
|
||||
log.debugf("Pid : %s", bean.getPid());
|
||||
log.debugf("Sign : %s", bean.getSign());
|
||||
log.debugf("P_Sign : %s", sign);
|
||||
}
|
||||
|
||||
if (Lang.equals(sign, bean.getSign())) {
|
||||
int type = cdKeyCategoryService.getType(bean.getCdkey());
|
||||
if (cdKeyCategoryService.isExists(type)) {
|
||||
if (cdKeyService.use(bean.getCdkey(), type)) {
|
||||
cdKeyLogService.insert(new CdkeyLog(bean.getPid(), bean.getProviderId(), bean.getMac()));
|
||||
return NutMap.NEW().addv("feedback", 0).addv("mesage", "ok");
|
||||
}
|
||||
return NutMap.NEW().addv("feedback", 92).addv("mesage", "已失效");
|
||||
}
|
||||
return NutMap.NEW().addv("feedback", 93).addv("mesage", "不存在");
|
||||
}
|
||||
return NutMap.NEW().addv("feedback", 61).addv("mesage", "签名失败");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
package com.rekoe.module;
|
||||
|
||||
import org.nutz.ioc.loader.annotation.IocBean;
|
||||
import org.nutz.mvc.annotation.At;
|
||||
import org.nutz.mvc.annotation.By;
|
||||
import org.nutz.mvc.annotation.Filters;
|
||||
import org.nutz.mvc.annotation.Ok;
|
||||
|
||||
import com.rekoe.filter.IPFilter;
|
||||
|
||||
@IocBean
|
||||
@At("/user")
|
||||
@Filters(@By(type = IPFilter.class, args = { "ioc:iPFilter" }))
|
||||
public class IndexAct {
|
||||
|
||||
@At
|
||||
@Ok("fm:template.login.login")
|
||||
public void login() {
|
||||
/*
|
||||
* try { SecurityUtils.getSubject().logout(); } catch (SessionException
|
||||
* ise) { logger.debug(
|
||||
* "Encountered session exception during logout. This can generally safely be ignored."
|
||||
* , ise); } catch (Exception e) { logger.debug("登出发生错误", e); }
|
||||
*/
|
||||
}
|
||||
|
||||
// /user/login
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
package com.rekoe.module;
|
||||
|
||||
import org.nutz.http.Http;
|
||||
import org.nutz.ioc.loader.annotation.IocBean;
|
||||
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("/api")
|
||||
public class IpSearchAction {
|
||||
|
||||
private final static String API_URL = "http://ip.taobao.com/service/getIpInfo.php?ip=";
|
||||
|
||||
@At("/ip/search")
|
||||
@Ok("raw:json")
|
||||
@POST
|
||||
public String search(@Param("ip") String ip) {
|
||||
return Http.get(API_URL + ip).getContent();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,78 @@
|
|||
package com.rekoe.module;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import org.nutz.dao.Cnd;
|
||||
import org.nutz.ioc.loader.annotation.Inject;
|
||||
import org.nutz.ioc.loader.annotation.IocBean;
|
||||
import org.nutz.lang.Lang;
|
||||
import org.nutz.mvc.annotation.At;
|
||||
import org.nutz.mvc.annotation.By;
|
||||
import org.nutz.mvc.annotation.Filters;
|
||||
import org.nutz.mvc.annotation.Ok;
|
||||
|
||||
import com.rekoe.domain.Notice;
|
||||
import com.rekoe.filter.OauthCrossOriginFilter;
|
||||
import com.rekoe.service.NoticeService;
|
||||
|
||||
@IocBean
|
||||
@At("/notice")
|
||||
@Filters(@By(type = OauthCrossOriginFilter.class))
|
||||
public class NoticeModule {
|
||||
|
||||
@Inject
|
||||
private NoticeService noticeService;
|
||||
|
||||
/**
|
||||
* @api {post} /notice/:pid/list 获得公告列表
|
||||
* @apiParam {Number} pid 申请的游戏编码ID
|
||||
* @apiGroup notice
|
||||
* @apiVersion 1.0.0
|
||||
* @apiSampleRequest http://warlogin.shanggame.com/notice/:pid/list
|
||||
* @apiSuccess {Object[]} notices List of notice.
|
||||
* @apiSuccess {String} notices.color 公告标题颜色.
|
||||
* @apiSuccess {String} notices.title 公告标题.
|
||||
* @apiSuccess {number} notices.id 公告ID.
|
||||
* @apiSuccessExample {json} Success-Response:
|
||||
* [
|
||||
* {
|
||||
* "color": "#FFFFF", "title": "xxxx" ,"id":1
|
||||
* }
|
||||
* ]
|
||||
*/
|
||||
|
||||
@At("/?/list")
|
||||
@Ok("json")
|
||||
public Object list(int pid) {
|
||||
List<Notice> list = noticeService.query(Cnd.where("pid", "=", pid).and("publication", "=", true).desc("top"), null);
|
||||
if (Lang.isEmpty(list)) {
|
||||
return new ArrayList<Notice>();
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
* @api {post} /notice/view/:id 公告内容详细
|
||||
*
|
||||
* @apiParam {Number} id ID.
|
||||
*
|
||||
* @apiGroup notice
|
||||
* @apiVersion 1.0.0
|
||||
* @apiSampleRequest http://warlogin.shanggame.com/notice/view/:id
|
||||
*/
|
||||
|
||||
@At("/view/?")
|
||||
@Ok("raw")
|
||||
public String view(long id,HttpServletRequest req) throws IOException {
|
||||
Notice article =noticeService.fetch(id);
|
||||
if (Lang.isEmpty(article)) {
|
||||
return "empty";
|
||||
}
|
||||
return article.getContent();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,324 @@
|
|||
package com.rekoe.module;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpSession;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.commons.lang3.math.NumberUtils;
|
||||
import org.apache.oltu.oauth2.as.issuer.MD5Generator;
|
||||
import org.apache.oltu.oauth2.as.issuer.OAuthIssuerImpl;
|
||||
import org.apache.oltu.oauth2.common.exception.OAuthSystemException;
|
||||
import org.nutz.castor.Castors;
|
||||
import org.nutz.dao.Chain;
|
||||
import org.nutz.dao.Cnd;
|
||||
import org.nutz.ioc.loader.annotation.Inject;
|
||||
import org.nutz.ioc.loader.annotation.IocBean;
|
||||
import org.nutz.lang.Lang;
|
||||
import org.nutz.lang.util.NutMap;
|
||||
import org.nutz.mvc.annotation.At;
|
||||
import org.nutz.mvc.annotation.By;
|
||||
import org.nutz.mvc.annotation.Filters;
|
||||
import org.nutz.mvc.annotation.Ok;
|
||||
import org.nutz.mvc.annotation.POST;
|
||||
import org.nutz.mvc.annotation.Param;
|
||||
|
||||
import com.rekoe.domain.GameServer;
|
||||
import com.rekoe.domain.OAuthUser;
|
||||
import com.rekoe.domain.PlatformUser;
|
||||
import com.rekoe.filter.OauthCrossOriginFilter;
|
||||
import com.rekoe.mobile.provider.PlatformProviderFactory;
|
||||
import com.rekoe.service.GameServerService;
|
||||
import com.rekoe.service.IdWorkerService;
|
||||
import com.rekoe.service.OAuthService;
|
||||
import com.rekoe.service.OAuthUserService;
|
||||
import com.rekoe.service.PlatformUserService;
|
||||
import com.rekoe.utils.CommonUtils;
|
||||
import com.rekoe.utils.Constants;
|
||||
|
||||
@IocBean
|
||||
@At("/auth")
|
||||
@Filters(@By(type = OauthCrossOriginFilter.class))
|
||||
public class OAuthUserAction {
|
||||
|
||||
private final static String PHONE_KEY = "rk_phone_key";
|
||||
private final static String PHONE_NUMBER = "rk_phone_number";
|
||||
private final static String OAUTH_USER_KEY = "rk_oauth_user_key";
|
||||
|
||||
@Inject
|
||||
private OAuthUserService oAuthUserService;
|
||||
|
||||
@Inject
|
||||
private OAuthService oAuthService;
|
||||
|
||||
@Inject
|
||||
private GameServerService gameServerService;
|
||||
|
||||
/**
|
||||
* @api {post} /auth/user/create 创建账号并获取授权码
|
||||
*
|
||||
* @apiGroup User
|
||||
* @apiVersion 1.0.0
|
||||
* @apiSampleRequest http://warlogin.shanggame.com/auth/user/create
|
||||
* @apiParam {String} name 用户名
|
||||
* @apiParam {String} password 密码
|
||||
* @apiParam {String} captcha 手机收到的验证码
|
||||
* @apiParamExample {String} Request-Example:
|
||||
* user.name=xxx&user.password=xxx&captcha=xxx
|
||||
* @apiSuccess {int} feedback 响应状态 0 为成功 1 账号被占用
|
||||
* @apiSuccess {String} code 授权码
|
||||
*/
|
||||
|
||||
/**
|
||||
* 普通注册
|
||||
*
|
||||
* @param user
|
||||
* @return
|
||||
* @throws OAuthSystemException
|
||||
*/
|
||||
@At("/user/create")
|
||||
@Ok("json")
|
||||
@POST
|
||||
public NutMap create(HttpServletRequest req) throws OAuthSystemException {
|
||||
HttpSession session = req.getSession();
|
||||
Object phoneCodeObj = session.getAttribute(PHONE_KEY);
|
||||
Object phoneObj = session.getAttribute(PHONE_NUMBER);
|
||||
if (Lang.isEmpty(phoneCodeObj) || Lang.isEmpty(phoneObj)) {
|
||||
return NutMap.NEW().addv("feedback", 404);
|
||||
}
|
||||
NutMap parames = CommonUtils.getRequestParametersMap(req);
|
||||
int captcha = parames.getInt("captcha",0);
|
||||
String name = parames.getString("name");
|
||||
String pwd = parames.getString("password");
|
||||
|
||||
int phoneCode = Castors.me().castTo(phoneCodeObj,int.class);
|
||||
if (StringUtils.isBlank(pwd) || StringUtils.isBlank(name) || captcha != phoneCode) {
|
||||
return NutMap.NEW().addv("feedback", 1);
|
||||
}
|
||||
long phone = Castors.me().castTo(phoneObj, long.class);
|
||||
NutMap map = NutMap.NEW();
|
||||
if (checkOauthUser(name)) {
|
||||
OAuthIssuerImpl oauthIssuerImpl = new OAuthIssuerImpl(new MD5Generator());
|
||||
String authorizationCode = oauthIssuerImpl.authorizationCode();
|
||||
oAuthService.addAuthCode(authorizationCode, name);
|
||||
map.addv("code", authorizationCode);
|
||||
OAuthUser user = new OAuthUser();
|
||||
user.setPhoneCode(phone);
|
||||
user.setPassword(pwd);
|
||||
user.setUserName(name);
|
||||
oAuthUserService.createUser(user);
|
||||
session.setAttribute(PHONE_KEY, null);
|
||||
session.setAttribute(PHONE_NUMBER, null);
|
||||
} else {
|
||||
return map.addv("feedback", 1);
|
||||
}
|
||||
return map.addv("feedback", 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @api {post} /auth/rest/pwd 密码重置
|
||||
*
|
||||
* @apiGroup User
|
||||
* @apiVersion 1.0.0
|
||||
* @apiSampleRequest http://warlogin.shanggame.com/auth/rest/pwd
|
||||
*
|
||||
* @apiParam {String} captcha 手机收到的验证码
|
||||
* @apiParam {String} password 需要重置的新密码
|
||||
*
|
||||
* @apiSuccess {int} feedback 响应状态 0 为成功
|
||||
* @apiSuccessExample {json} Success-Response:
|
||||
* { "feedback": 0 }
|
||||
*/
|
||||
|
||||
@At("/rest/pwd")
|
||||
@Ok("json")
|
||||
@POST
|
||||
public NutMap restpwd(HttpServletRequest req) throws OAuthSystemException {
|
||||
HttpSession session = req.getSession();
|
||||
Object phoneCodeObj = session.getAttribute(PHONE_KEY);
|
||||
Object nameObj = session.getAttribute(OAUTH_USER_KEY);
|
||||
if (Lang.isEmpty(phoneCodeObj) || Lang.isEmpty(nameObj)) {
|
||||
return NutMap.NEW().addv("feedback", 404);
|
||||
}
|
||||
NutMap parames = CommonUtils.getRequestParametersMap(req);
|
||||
int captcha = parames.getInt("captcha",0);
|
||||
String pwd = parames.getString("password");
|
||||
String name = Castors.me().castToString(nameObj);
|
||||
int phoneCode = Castors.me().castTo(phoneCodeObj,int.class);
|
||||
if (StringUtils.isBlank(pwd) || captcha!=phoneCode) {
|
||||
return NutMap.NEW().addv("feedback", 1);
|
||||
}
|
||||
|
||||
OAuthIssuerImpl oauthIssuerImpl = new OAuthIssuerImpl(new MD5Generator());
|
||||
String authorizationCode = oauthIssuerImpl.authorizationCode();
|
||||
oAuthService.addAuthCode(authorizationCode, name);
|
||||
oAuthUserService.updateByChain(name, pwd);
|
||||
session.setAttribute(PHONE_KEY, null);
|
||||
session.setAttribute(OAUTH_USER_KEY, null);
|
||||
return NutMap.NEW().addv("feedback", 0).addv("code", authorizationCode);
|
||||
}
|
||||
|
||||
private boolean checkOauthUser(String name) {
|
||||
if (CommonUtils.isUsername(name) && StringUtils.isNotBlank(name) && Lang.isEmpty(oAuthUserService.findByUsername(name))) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @api {post} /auth/phone/captcha 获取手机验证码
|
||||
*
|
||||
* @apiGroup User
|
||||
* @apiVersion 1.0.0
|
||||
* @apiSampleRequest http://warlogin.shanggame.com/auth/phone/captcha
|
||||
*
|
||||
* @apiParam {Number} phone 手机号
|
||||
* @apiParam {Number} pid 引用所属游戏平台编号
|
||||
*
|
||||
* @apiSuccess {int} feedback 响应状态 0 为成功, 100手机号非法, 101未注册的游戏平台
|
||||
* @apiSuccessExample {json} Success-Response:
|
||||
* { "feedback": 0 }
|
||||
*/
|
||||
|
||||
@At("/phone/captcha")
|
||||
@Ok("raw:json")
|
||||
@POST
|
||||
public String regCaptcha(@Param("phone") String phone, @Param("pid") int pid, HttpSession session) {
|
||||
if (!NumberUtils.isNumber(phone) || phone.length() != 11) {
|
||||
return "{\"feedback\":100}";
|
||||
}
|
||||
GameServer gameServer = gameServerService.getByPid(pid);
|
||||
if (Lang.isEmpty(gameServer)) {
|
||||
return "{\"feedback\":101}";
|
||||
}
|
||||
int code = CommonUtils.nextInt(1000, 9999);
|
||||
boolean isRight = gameServerService.sendPhoneMail(gameServer, phone, "29337", code + "", "30");
|
||||
if (isRight) {
|
||||
session.setAttribute(PHONE_KEY, code);
|
||||
session.setAttribute(PHONE_NUMBER, phone);
|
||||
return "{\"feedback\":0,\"session\":\"" + session.getId() + "\"}";
|
||||
}
|
||||
return "{\"feedback\":102}";
|
||||
}
|
||||
|
||||
/**
|
||||
* @api {post} /auth/rest/captcha 获取手机验证码-密码重置
|
||||
*
|
||||
* @apiGroup User
|
||||
* @apiVersion 1.0.0
|
||||
* @apiSampleRequest http://warlogin.shanggame.com/auth/rest/captcha
|
||||
*
|
||||
* @apiParam {String} name 用户名
|
||||
* @apiParam {Number} phone 手机号
|
||||
* @apiParam {Number} pid 引用所属游戏平台编号
|
||||
*
|
||||
* @apiSuccess {int} feedback 响应状态 0 为成功, 100手机号非法, 101未注册的游戏平台
|
||||
* @apiSuccessExample {json} Success-Response:
|
||||
* { "feedback": 0 }
|
||||
*/
|
||||
|
||||
@At("/rest/captcha")
|
||||
@Ok("raw:json")
|
||||
@POST
|
||||
public String restCaptcha(@Param("phone") String phone, @Param("name") String name, @Param("pid") int pid, HttpSession session) {
|
||||
if (!NumberUtils.isNumber(phone) || phone.length() != 11) {
|
||||
return "{\"feedback\":100}";
|
||||
}
|
||||
GameServer gameServer = gameServerService.getByPid(pid);
|
||||
if (Lang.isEmpty(gameServer)) {
|
||||
return "{\"feedback\":101}";
|
||||
}
|
||||
boolean isOk = oAuthUserService.checkRestPwd(name, NumberUtils.toLong(phone));
|
||||
if (isOk) {
|
||||
int code = CommonUtils.nextInt(100000, 999999);
|
||||
boolean isRight = gameServerService.sendPhoneMail(gameServer, phone, "29337", code + "", "30");
|
||||
if (isRight) {
|
||||
session.setAttribute(PHONE_KEY, code);
|
||||
session.setAttribute(OAUTH_USER_KEY, name);
|
||||
return "{\"feedback\":0,\"session\":\"" + session.getId() + "\"}";
|
||||
}
|
||||
}
|
||||
return "{\"feedback\":102}";
|
||||
}
|
||||
|
||||
@Inject
|
||||
private PlatformUserService platformUserService;
|
||||
|
||||
@Inject
|
||||
private PlatformProviderFactory platformProviderFactory;
|
||||
|
||||
@Inject
|
||||
private IdWorkerService idFactory;
|
||||
|
||||
private final Object obj = new Object();
|
||||
|
||||
/**
|
||||
* @api {post} /auth/account/bind 账号绑定
|
||||
*
|
||||
* @apiGroup User
|
||||
* @apiVersion 1.0.0
|
||||
* @apiSampleRequest http://warlogin.shanggame.com/auth/account/bind
|
||||
*
|
||||
* @apiParam {String} name 用户名
|
||||
* @apiParam {String} password 密码
|
||||
* @apiParam {Number} pid 引用所属游戏平台编号
|
||||
* @apiParam {String} captcha 手机收到的验证码
|
||||
* @apiParam {String} guestid 需要绑定的游客ID
|
||||
*
|
||||
* @apiSuccess {int} feedback 响应状态 0 为成功, 100手机号非法, 101未注册的游戏平台
|
||||
* @apiSuccessExample {json} Success-Response:
|
||||
* { "feedback": 0 }
|
||||
*/
|
||||
|
||||
@At("/account/bind")
|
||||
@Ok("json")
|
||||
@POST
|
||||
public NutMap bindAccount(HttpServletRequest req) {
|
||||
HttpSession session = req.getSession();
|
||||
Object phoneCodeObj = session.getAttribute(PHONE_KEY);
|
||||
Object phoneObj = session.getAttribute(PHONE_NUMBER);
|
||||
if (Lang.isEmpty(phoneCodeObj) || Lang.isEmpty(phoneObj)) {
|
||||
return NutMap.NEW().addv("feedback", 404);
|
||||
}
|
||||
NutMap parames = CommonUtils.getRequestParametersMap(req);
|
||||
int pid = parames.getInt("pid", -1);
|
||||
String pwd = parames.getString("password");
|
||||
if (StringUtils.isBlank(pwd)) {
|
||||
return NutMap.NEW().addv("feedback", 501).addv("msg", "密码不可以为空");
|
||||
}
|
||||
int captcha = parames.getInt("captcha", 0);
|
||||
int phoneCode = Castors.me().castTo(phoneCodeObj, int.class);
|
||||
if (captcha != phoneCode) {
|
||||
return NutMap.NEW().addv("feedback", 502).addv("msg", "验证码错误");
|
||||
}
|
||||
String guestid = parames.getString("guestid");
|
||||
if (StringUtils.isBlank(guestid)) {
|
||||
return NutMap.NEW().addv("feedback", 503).addv("msg", "游客ID不可以为空");
|
||||
}
|
||||
PlatformUser platformUser = platformUserService.getPlatformUser(pid, guestid, Constants.GUEST);
|
||||
if (Lang.isEmpty(platformUser)) {
|
||||
return NutMap.NEW().addv("feedback", 405).addv("msg", "未找到此游客记录");
|
||||
}
|
||||
long phone = Castors.me().castTo(phoneObj, long.class);
|
||||
String name = parames.getString("name");
|
||||
if (checkOauthUser(name)) {
|
||||
// 创建账号
|
||||
long newOpenid = idFactory.nextId();
|
||||
synchronized (obj) {
|
||||
OAuthUser user = new OAuthUser();
|
||||
user.setPhoneCode(phone);
|
||||
user.setPassword(pwd);
|
||||
user.setUserName(name);
|
||||
user.setBind(true);
|
||||
user.setBindProviderId(platformUser.getPfid());
|
||||
user = oAuthUserService.createUser(user, platformUser.getOpenid());
|
||||
platformUser.setOpenid(newOpenid);
|
||||
platformUserService.update(Chain.make("openid", newOpenid), Cnd.where("id", "=", platformUser.getId()));
|
||||
session.setAttribute(PHONE_KEY, null);
|
||||
session.setAttribute(PHONE_NUMBER, null);
|
||||
}
|
||||
} else {
|
||||
return NutMap.NEW().addv("feedback", 504).addv("msg", "账号已被占用");
|
||||
}
|
||||
return NutMap.NEW().addv("feedback", 0);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,146 @@
|
|||
package com.rekoe.module;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.net.URLEncoder;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.servlet.http.HttpSession;
|
||||
|
||||
import org.apache.shiro.SecurityUtils;
|
||||
import org.apache.shiro.authc.AuthenticationException;
|
||||
import org.apache.shiro.authc.ExcessiveAttemptsException;
|
||||
import org.apache.shiro.authc.IncorrectCredentialsException;
|
||||
import org.apache.shiro.authc.LockedAccountException;
|
||||
import org.apache.shiro.authc.UnknownAccountException;
|
||||
import org.apache.shiro.authz.annotation.RequiresAuthentication;
|
||||
import org.apache.shiro.subject.Subject;
|
||||
import org.apache.shiro.util.ThreadContext;
|
||||
import org.brickred.socialauth.AuthProvider;
|
||||
import org.brickred.socialauth.Profile;
|
||||
import org.brickred.socialauth.SocialAuthConfig;
|
||||
import org.brickred.socialauth.SocialAuthManager;
|
||||
import org.brickred.socialauth.exception.SocialAuthException;
|
||||
import org.brickred.socialauth.util.SocialAuthUtil;
|
||||
import org.nutz.ioc.loader.annotation.Inject;
|
||||
import org.nutz.ioc.loader.annotation.IocBean;
|
||||
import org.nutz.lang.Encoding;
|
||||
import org.nutz.lang.Files;
|
||||
import org.nutz.lang.Lang;
|
||||
import org.nutz.lang.stream.NullInputStream;
|
||||
import org.nutz.mvc.View;
|
||||
import org.nutz.mvc.annotation.At;
|
||||
import org.nutz.mvc.annotation.By;
|
||||
import org.nutz.mvc.annotation.Filters;
|
||||
import org.nutz.mvc.annotation.Ok;
|
||||
import org.nutz.mvc.view.ForwardView;
|
||||
import org.nutz.mvc.view.ServerRedirectView;
|
||||
import org.nutz.mvc.view.ViewWrapper;
|
||||
import org.nutz.plugins.view.freemarker.FreeMarkerConfigurer;
|
||||
import org.nutz.plugins.view.freemarker.FreemarkerView;
|
||||
|
||||
import com.rekoe.common.Message;
|
||||
import com.rekoe.filter.IPFilter;
|
||||
import com.rekoe.shiro.realm.OAuthToken;
|
||||
|
||||
/**
|
||||
* @author 科技㊣²º¹³ <br />
|
||||
* 2014年2月3日 下午4:48:45<br />
|
||||
* http://www.rekoe.com QQ:5382211
|
||||
*/
|
||||
@IocBean(create = "init")
|
||||
@At("/user")
|
||||
@Filters(@By(type = IPFilter.class, args = { "ioc:iPFilter" }))
|
||||
public class OauthLoginAct {
|
||||
|
||||
@Inject
|
||||
private FreeMarkerConfigurer freeMarkerConfigurer;
|
||||
|
||||
// 需要登录之后才能访问,否则跳转到首页
|
||||
@RequiresAuthentication
|
||||
@At
|
||||
public Object authOnly() {
|
||||
return "You are authed!";
|
||||
}
|
||||
|
||||
/* 提供社会化登录 */
|
||||
@At("/login/?")
|
||||
@Ok("void")
|
||||
public void login(String provider, HttpSession session, HttpServletRequest req, HttpServletResponse res) throws Exception {
|
||||
String returnTo = req.getRequestURL().toString() + "/callback";
|
||||
if (req.getParameterMap().size() > 0) {
|
||||
StringBuilder sb = new StringBuilder().append(returnTo).append("?");
|
||||
for (Object name : req.getParameterMap().keySet()) {
|
||||
sb.append(name).append('=').append(URLEncoder.encode(req.getParameter(name.toString()), Encoding.UTF8)).append("&");
|
||||
}
|
||||
returnTo = sb.toString();
|
||||
}
|
||||
SocialAuthManager manager = new SocialAuthManager(); // 每次都要新建哦
|
||||
manager.setSocialAuthConfig(config);
|
||||
session.setAttribute("openid.manager", manager);
|
||||
String url = manager.getAuthenticationUrl(provider, returnTo);
|
||||
res.setHeader("Location", url);
|
||||
res.setStatus(302);
|
||||
}
|
||||
|
||||
// 没登录就不要登出了
|
||||
@RequiresAuthentication
|
||||
@At("/logout")
|
||||
@Ok(">>:/admin/index.rk")
|
||||
public void logout(HttpSession session) {
|
||||
// session.invalidate(); //销毁会话,啥都米有了
|
||||
SecurityUtils.getSubject().logout();
|
||||
}
|
||||
|
||||
/* 无需做链接,这是OpenID的回调地址 */
|
||||
@At("/login/?/callback")
|
||||
public View returnPoint(String providerId, HttpServletRequest request, HttpSession session) throws Exception {
|
||||
SocialAuthManager manager = (SocialAuthManager) session.getAttribute("openid.manager");
|
||||
if (manager == null)
|
||||
throw new SocialAuthException("Not manager found!");
|
||||
session.removeAttribute("openid.manager"); // 防止重复登录的可能性
|
||||
Map<String, String> paramsMap = SocialAuthUtil.getRequestParametersMap(request);
|
||||
Subject currentUser = SecurityUtils.getSubject();
|
||||
boolean rname = false;
|
||||
try {
|
||||
AuthProvider provider = manager.connect(paramsMap);
|
||||
Profile p = provider.getUserProfile();
|
||||
ThreadContext.bind(currentUser);
|
||||
OAuthToken token = new OAuthToken(p, Lang.getIP(request), session);
|
||||
currentUser.login(token);
|
||||
rname = token.isRname();
|
||||
} catch (UnknownAccountException uae) {
|
||||
return new ViewWrapper(new FreemarkerView(freeMarkerConfigurer, "template/admin/common/error"), Message.error("帐号不存在", request));
|
||||
} catch (IncorrectCredentialsException ice) {
|
||||
return new ViewWrapper(new FreemarkerView(freeMarkerConfigurer, "template/admin/common/error"), Message.error("证书验证失败", request));
|
||||
} catch (LockedAccountException lae) {
|
||||
// "帐号已被锁定"
|
||||
return new ViewWrapper(new FreemarkerView(freeMarkerConfigurer, "template/admin/common/error"), Message.error("帐号未被授权,请联系管理员", request));
|
||||
} catch (ExcessiveAttemptsException eae) {
|
||||
return new ViewWrapper(new FreemarkerView(freeMarkerConfigurer, "template/admin/common/error"), Message.error("尝试的次数太多", request));
|
||||
} catch (AuthenticationException ae) {
|
||||
return new ViewWrapper(new ForwardView("/admin/index"), ae.getMessage());
|
||||
}
|
||||
if (rname) {
|
||||
return new ViewWrapper(new ServerRedirectView("/admin/register.rk"), null);
|
||||
}
|
||||
return new ViewWrapper(new ServerRedirectView("/admin/main.rk"), null);
|
||||
}
|
||||
|
||||
private SocialAuthConfig config;
|
||||
|
||||
public void init() throws Exception {
|
||||
SocialAuthConfig config = new SocialAuthConfig();
|
||||
File devConfig = Files.findFile("oauth_consumer.properties_dev"); // 开发期所使用的配置文件
|
||||
if (devConfig == null)
|
||||
devConfig = Files.findFile("oauth_consumer.properties"); // 真实环境所使用的配置文件
|
||||
if (devConfig == null)
|
||||
config.load(new NullInputStream());
|
||||
else
|
||||
config.load(new FileInputStream(devConfig));
|
||||
this.config = config;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,49 @@
|
|||
package com.rekoe.module;
|
||||
|
||||
import org.nutz.ioc.loader.annotation.Inject;
|
||||
import org.nutz.ioc.loader.annotation.IocBean;
|
||||
import org.nutz.mvc.annotation.At;
|
||||
import org.nutz.mvc.annotation.By;
|
||||
import org.nutz.mvc.annotation.Filters;
|
||||
import org.nutz.mvc.annotation.Ok;
|
||||
import org.nutz.mvc.annotation.POST;
|
||||
import org.nutz.mvc.annotation.Param;
|
||||
|
||||
import com.rekoe.domain.ReportAds;
|
||||
import com.rekoe.filter.OauthCrossOriginFilter;
|
||||
import com.rekoe.service.ReportAdsService;
|
||||
|
||||
@At("/report")
|
||||
@IocBean
|
||||
@Filters(@By(type = OauthCrossOriginFilter.class))
|
||||
public class ReportAdsModule {
|
||||
|
||||
@Inject
|
||||
private ReportAdsService reportAdsService;
|
||||
|
||||
/**
|
||||
* @api {POST} /report/ads 数据汇报
|
||||
* @apiSampleRequest http://warlogin.shanggame.com/report/ads
|
||||
* @apiGroup report
|
||||
* @apiVersion 1.0.0
|
||||
*
|
||||
*
|
||||
* @apiParam {Number} pid 申请的游戏编号
|
||||
* @apiParam {String} pfid 接入的平台编号
|
||||
* @apiParam {String} idfa idfa
|
||||
* @apiParam {String} idfv idfv
|
||||
* @apiParam {String} talkingDataId talkingDataId
|
||||
*
|
||||
* @apiSuccess {json} msg OK
|
||||
*
|
||||
*/
|
||||
|
||||
@At
|
||||
@Ok("raw:json")
|
||||
@POST
|
||||
public String ads(@Param("pid") int pid, @Param("pfid") String pfid, @Param("idfa") String idfa,
|
||||
@Param("idfv") String idfv, @Param("talkingDataId") String talkingDataId) {
|
||||
reportAdsService.add(new ReportAds(pid, pfid, idfa, idfv, talkingDataId));
|
||||
return "{\"msg\":\"ok\"}";
|
||||
}
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
package com.rekoe.module;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
public class Status implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = -7767253096192148313L;
|
||||
private int code;
|
||||
|
||||
private String msg;
|
||||
|
||||
public int getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public void setCode(int code) {
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public String getMsg() {
|
||||
return msg;
|
||||
}
|
||||
|
||||
public void setMsg(String msg) {
|
||||
this.msg = msg;
|
||||
}
|
||||
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue