Java xinge message push Android and IOs

xinge message push: for example, like Taobao, when the user finishes placing an order, he will be prompted with a message: order check, etc. What if we want to implement similar functions?

I. import package into pom.xml file

<dependency>
			<groupId>com.github.xingePush</groupId>
			<artifactId>xinge</artifactId>
			<version>1.2.0-SNAPSHOT</version>
		</dependency>
		<repository>
			<id>xingePush</id>
			<url>https://raw.githubusercontent.com/xingePush/maven-repository/snapshot/</url>
		</repository>

2. Configure application.yml to configure push account information (you can apply on xinge official website)

      xinge:
			androidAppid: ########
			androidSecretkey: ################################
			   
			isoAppid: ########
			isoSecretkey: ################################
			

III. entity class of configuration information

@Data
		@Component
		@ConfigurationProperties(prefix = "xinge")
		public class XgAccountConfig {

			/**
			 * android end
			 */
			private String androidAppid;

			private String androidSecretkey;

			
			/**
			 * iso end
			 */
			private String isoAppid;

			private String isoSecretkey;

		}
		

IV. injection configuration

	@Component
		public class XingeConfig {
		@Autowired
		private XgAccountConfig xgAccountConfig;
		@Bean("androidXinge")
		public XingeApp androidXingeUser() {
			return new XingeApp(xgAccountConfig.getAndroidAppid(), xgAccountConfig.getAndroidSecretkey());
		}

		@Bean("isoXinge")
		public XingeApp isoXingeUser() {
			return new XingeApp(xgAccountConfig.getIsoAppid(), xgAccountConfig.getIsoSecretkey());
		}

		}		
		

V. create message push tool class

@Component
		public class XgPushUtil {
			/**
			 * Andrew
			 */
			@Autowired
			private XingeApp androidXinge;
			/**
			 * ios end
			 */
			@Autowired
			private XingeApp isoXinge;

			/**
			 * 
			 * @param platformType
			 *            Equipment type
			 * @param msgTitle
			 *            Message header
			 * @param msgContent
			 *            Message content
			 * @param token
			 *            Device token
			 * @return Whether the message is successfully pushed
			 * @throws JSONException
			 */
			public boolean singlePushMsg(String platformType, String msgTitle, String msgContent,
					ArrayList<String> tokens) throws JSONException {

				PushAppRequest push = new PushAppRequest();

				ArrayList<String> token_list = tokens;
				push.setToken_list(token_list);
				push.setAudience_type(AudienceType.token_list);
				push.setMessage_type(MessageType.notify);
				Message message = new Message();
				message.setTitle(msgTitle);
				message.setContent(msgContent);
				push.setMessage(message);
				JSONObject json = null;
				// Select different operations according to different equipment types
				if ("ios".equals(platformType)) {
					push.setEnvironment(Environment.dev);
					MessageIOS ios = new MessageIOS();
					Aps aps = new Aps();
					Alert alert = new Alert();
					aps.setAlert(alert);
					ios.setAps(aps);
					message.setIos(ios);
					push.setPlatform(Platform.ios);
					json = isoXinge.pushApp(push);// Push messages
				} else if ("android".equals(platformType)) {
					push.setPlatform(Platform.android);
					// Judge the type of user (courier or customer)
					json = androidXinge.pushApp(push);
				}

				if (json != null) {
					Object object = json.get("ret_code");
					if (object != null && object.equals(0)) {
						return true;
					} else {
						return false;
					}
				} else {
					return false;
				}
			}
		}
		

Vi. there will be a lot of device types at that time, just push messages. Every time you log in, you will get the current token again, whether the current device is Android or iOS

Tags: iOS JSON Android snapshot

Posted on Sat, 02 Nov 2019 14:39:54 -0700 by Millar