首页 > 学院 > 开发设计 > 正文

璇磋鏋佸厜鎺ㄩ€侀偅浜涗簨

2019-11-09 18:19:48
字体:
来源:转载
供稿:网友

搴忚█锛氫粖澶╃湅鎵撳紑鑵捐浣撹偛鐨勬椂鍊欙紝杩樻病瀹屽叏鎵撳紑灏辨敹鍒颁簡涓€鏉℃帹閫侊紝鐒跺悗瀵规帹閫佽繖涓笢瑗垮氨浜х敓浜嗗叴瓒o紝鍥犱负涔嬪墠娌℃湁寮勮繃鎺ㄩ€侊紝鎵€浠ュ氨鎯崇潃鍐欎竴绡囧崥瀹㈡潵璁板綍涓€涓嬪涔犳帹閫佺殑杩囩▼銆?/h3>

棣栧厛锛岀櫨搴?strong>android鎺ㄩ€侊紝杩欎釜鏃跺€欎細鍑烘潵涓€鍫嗗叧浜庢帹閫佺殑淇℃伅锛?/p>

1銆?a href="https://www.jiguang.cn/">鏋佸厜鎺ㄩ€?/a>

2銆?a href="http://xg.qq.com/">淇¢附鎺ㄩ€?/a>

3銆?a href="http://www.rongcloud.cn/">铻嶄簯鎺ㄩ€?/a>

4銆?a href="https://aws.amazon.com/cn/?nc2=h_lg">浜氶┈閫夾WS鎺ㄩ€?/a>

绛夌瓑

杩欓噷鎴戦€夋嫨浜嗕竴涓▼搴忕尶浠瘮杈冨父鐢ㄧ殑鏋佸厜鎺ㄩ€侊紝濂斤紝鍏堜笂鏁堟灉鍥撅細

宸﹁竟鏄疛ava鍚庣锛岄泦鎴愪簡JPush锛岀畝鍗曞啓浜嗕竴涓猨sp椤甸潰锛屼緵鎴戜滑鎺ㄩ€佽嚜瀹氫箟娑堟伅锛屽彸杈规槸鎴戜滑鐨勫鎴风锛岀敤鏉ユ帴鏀禞Push鐨勬帹閫併€傚鏋滃java鍚庣涓嶇煡閬撶潃鎵嬪啓鐨勫悓瀛﹁鍙傝€冩垜鐨勫彟澶栦笁绡囧崥瀹細

android寮€鍙戞€庝箞灏戠殑浜嗗悗绔紙涓婏級

android寮€鍙戞€庝箞灏戠殑浜嗗悗绔紙涓級

android寮€鍙戞€庝箞灏戠殑浜嗗悗绔紙涓嬶級

濂戒簡锛屾潵鐪嬫垜浠粖澶╃殑demo锛?/p>

1銆侀鍏堝鎴风灏变竴涓櫥褰曠晫闈㈠拰涓€涓椤碉紝鐧诲綍涔嬪悗鍐嶇粰璇ョ敤鎴锋帹閫?/p>

2銆佹湇鍔$涔熸湁涓€涓晫闈紝鐢ㄦ潵鍙戦€佽嚜瀹氫箟鎺ㄩ€侊紝鑰屼笖鎴戜滑缁欏畠璁惧畾涓€涓瓫閫夋満鍒讹紝杩欎釜绛涢€夋満鍒舵垜浠湪涓嬮潰璁叉暟鎹簱鐨勬椂鍊欏啀璇?/p>

鍏充簬瀹㈡埛绔瀬鍏夋帹閫佺殑闆嗘垚锛屽湪杩欓噷鎴戣鍑犵偣锛?/p>

1銆佺櫥褰曠殑鏃跺€欐垜浠渶瑕佽缃瀬鍏夋帹閫佺殑鍒悕alias鍜屾爣绛総ag锛屼互渚挎垜浠兘鎺ユ敹鍒癑Push鐨勬帹閫侊紝alias鍜?strong>tag鏄瀬鍏夋帹閫侀渶瑕佺殑锛屽埆鍚?strong>alias锛屽畼缃戜笂缁欑殑瑙i噴鏄负瀹夎浜嗗簲鐢ㄧ▼搴忕殑鐢ㄦ埛锛屽彇涓埆鍚嶆潵鏍囪瘑銆備互鍚庣粰璇ョ敤鎴?strong>Push娑堟伅鏃讹紝灏卞彲浠ョ敤姝ゅ埆鍚嶆潵鎸囧畾銆傛瘡涓敤鎴峰彧鑳芥寚瀹氫竴涓埆鍚嶏紱鏍囩tag锛屽畼缃戜笂缁欑殑瑙i噴鏄负瀹夎浜嗗簲鐢ㄧ▼搴忕殑鐢ㄦ埛锛屾墦涓婃爣绛俱€傚叾鐩殑涓昏鏄柟渚垮紑鍙戣€呮牴鎹爣绛撅紝鏉ユ壒閲忎笅鍙?strong>Push娑堟伅銆傚彲涓烘瘡涓敤鎴锋墦澶氫釜鏍囩銆?/p>btnLogin.setOnClickListener(new View.OnClickListener(){ @Override public void onClick(View v) { //1銆佺櫥褰曗€斺€?gt;璇锋眰鏈嶅姟鍣? //2銆佺櫥褰曟垚鍔熶箣鍚庯紝璁剧疆鏋佸厜鎺ㄩ€? setJPush(); }});PRivate void setJPush(){ String alias; String tags; Set<String> tagSet=new HashSet<>(Arrays.asList(tags)); //缁欐瀬鍏夋帹閫佽缃爣绛惧拰鍒悕 JPushInterface.setAliasAndTags(this, alias, tagSet, tagAliasCallback);}

鐒跺悗灏辨槸涓€涓瀬鍏夋帹閫佽缃埆鍚嶅拰鏍囩鐨勫洖璋冿細

//鏋佸厜鏈嶅姟鍣ㄨ缃埆鍚嶆槸鍚︽垚鍔熺殑鍥炶皟private final TagAliasCallback tagAliasCallback = new TagAliasCallback() { @Override public void gotResult(int code, String alias, Set<String> tagSet) { switch (code) { case 0: Log.i("TAG", "璁剧疆鍒悕鎴愬姛"); break; default: Log.i("TAG", "璁剧疆鍒悕澶辫触"); break; } }};

2銆佸洜涓哄埆鍚嶈姹傚敮涓€鎬э紝鎵€浠ュ埆鍚嶄竴鑸槸浣犳墜鏈虹殑UID锛屽鏋滀綘涓嶆兂鍦ㄤ綘涓嬬嚎涔嬪悗杩樿兘鏀跺埌鎺ㄩ€侊紝閭d箞鍐嶄綘涓嬬嚎鐨勬椂鍊欏皢鍒悕璁剧疆涓虹┖ 鍏充簬鍒悕鐨勶紝璇︽儏璇峰弬鑰?a href="https://docs.jiguang.cn/jpush/client/Android/android_api/#api_1">鏋佸厜鎺ㄩ€佸埆鍚嶄笌鏍囩API

瀹㈡埛绔殑闆嗘垚锛屽畼缃戣鐨勫緢璇︾粏锛屽湪杩欓噷鎴戝氨涓嶇粏璇翠簡锛岃鎯呰鍙傝€?a href="https://docs.jiguang.cn/jpush/client/Android/android_sdk/">鏋佸厜鎺ㄩ€?Android SDK 姒傝堪

杩欓噷鎴戜滑鐪嬬湅鏈嶅姟绔殑闆嗘垚锛?/h4>

1銆佹暟鎹簱琛ㄧ殑鍒涘缓锛?/p>

鍦ㄨ繖閲屾垜浠湁6涓瓧娈碉紝鎴戜滑鏉ョ湅鍚庨潰涓変釜瀛楁鐨勫惈涔夛紝鐢变簬鎴戜滑妯℃嫙鐨勬槸鍟嗗満浼氬憳绉垎鎺ㄩ€佺殑鍦烘櫙锛屾墍浠?strong>count琛ㄧず鐢ㄦ埛鐨勭Н鍒嗭紝鎴戜滑鍓嶉潰鐨勬紨绀轰篃鏄牴鎹Н鍒嗘潵鍙戞帹閫侀€氱煡鐨勶紱鐒跺悗alias鍜?strong>tag鏄瀬鍏夋帹閫侀渶瑕佺殑锛屼笂鏂囨垜浠凡缁忚В閲婅繃alias鍜?strong>tag鐨勫惈涔変簡銆?/h4>

鐒跺悗鎴戜滑鏉ョ湅鎺ㄩ€佺殑鏈嶅姟绔紝棣栧厛鏂板缓涓€涓?strong>Servlet锛屼緵鎴戜滑鎺ㄩ€佺敤锛?/p>protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setHeader("Content-Type", "text/html;charset=UTF-8"); request.setCharacterEncoding("UTF-8"); int count = Integer.valueOf(request.getParameter("count")); String message = request.getParameter("message"); MyDBTools myDBTools = new MyDBTools(); ResultSet rs = null; if (count > -1 && !message.isEmpty()) { // 浠庢暟鎹簱涓幏鍙栨墍鏈夌殑绉垎澶т簬count鐨勭敤鎴凤紝浠庤€岃繘琛屾帹閫佹秷鎭? myDBTools.openConnect(); rs = myDBTools.getUserCountInfo(count); try { while (rs.next()) { // 鑾峰彇杩欎釜鐢ㄦ埛鐨勫埆鍚? String alias = rs.getString("alias"); // 鍛婅瘔鏋佸厜鏈嶅姟鍣紝杩欎釜鐢ㄦ埛闇€瑕佹帹閫? PushUtils.sendPushMessage(alias, "鑷畾涔塉Push閫氱煡", message); } } catch (SQLException e) { e.printStackTrace(); } } myDBTools.closeConnect();}

鐒跺悗鏄垜鍐欑殑涓€涓?strong>PushUtil鐨勪竴涓緟鍔╃被锛屾垜浠厛鏉ョ湅sendPushMessage()杩欎釜鏂规硶锛?/p>/** * 鍙戦€佹帹閫? * @param alias 鍒悕 * @param title 鎺ㄩ€佹爣棰? * @param msg 鎺ㄩ€佹秷鎭? * @return */public static PushResult sendPushMessage(String alias, String title, String msg) { JPushClient jClient = new JPushClient(MASTER_SECRET, APP_KEY); // 鏋勫缓鎺ㄩ€佺殑瀵硅薄 PushPayload pushPayload = buildByAlias(alias, title, msg); try { PushResult pr = jClient.sendPush(pushPayload); System.out.println("PushResult===" + pr); return pr; } catch (APIConnectionException | APIRequestException e) { e.printStackTrace(); } return null;}

娉細涓婅堪鐨?strong>MASTER_SECRET鍜?strong>APP_KEY鏄湪鏋佸厜鎺ㄩ€佸悗鍙颁綘鍒涘缓搴旂敤鐨勬椂鍊欎細鐢熸垚鐨勶紝鎴戜滑杩欓噷鏄牴鎹埆鍚嶆潵鎺ㄩ€佺殑锛屼綘杩樺彲浠ユ牴鎹爣绛炬潵鎺ㄩ€併€?/p>

鐒跺悗鎴戜滑鏉ョ湅buildByAlias()杩欎釜鏂规硶锛?/p>/** * 鏋勫缓鎺ㄩ€佺殑瀵硅薄锛氭墍鏈夊璞? * * @param alias 鎺ㄩ€佺洰鏍囷細鍒悕涓篴lias * @param title 鎺ㄩ€佹爣棰? * @param msg 鎺ㄩ€佸唴瀹? * @return */public static PushPayload buildByAlias(String alias, String title, String msg) { Map<String, String> map = new HashMap<>(); map.put("url", "http://www.baidu.com"); return PushPayload.newBuilder().setPlatform(Platform.all()).setAudience(Audience.alias(alias)) .setNotification(Notification.android(title, msg, map)).build();}

娉細涓婅堪涓殑map闆嗗悎鏄綘鎺ㄩ€佹椂鍊欑殑闄勫睘娑堟伅锛屽儚鎴戣繖涓婇潰鐨勯檮灞炴秷鎭氨鏄紶閫掍竴涓猽rl锛岀瓑浣犺幏鍙栭€氱煡鐨勬椂鍊欏彲浠ヨ幏鍙栧埌杩欎釜url锛岀劧鍚庢墦寮€閫氱煡涔嬪悗鍙互鎵撳紑杩欎釜url

濂戒簡锛屾帹閫佺殑瀹㈡埛绔拰鏈嶅姟绔氨璁插埌杩欓噷浜嗭紝璇︾粏鐨勪唬鐮佹垜宸茬粡浼犲埌GitHub涓婁簡,鐢变簬Eclipse涓婁紶GitHub澶辫触浜嗭紙涔嬪墠娌℃湁浼犺繃锛屾噦鐨勬湅鍙嬮夯鐑︽暀鏁欐垜锛夛紝鎵€浠ユ湇鍔$鐨勬垜灏辨斁鍒扮櫨搴︿簯涓婁簡

鐐规垜涓嬭浇瀹㈡埛绔?/a>

鐐规垜涓嬭浇鏈嶅姟绔?/a>

杩欐槸鎴戝缓鐨勪竴涓猘ndroid灏忕櫧鐨勭兢锛屽悇浣嶆湁鍏磋叮鐨勫皬鐧芥杩庡姞缇ゅ叡鍚屽涔狅紝涔熸杩庡悇浣嶅ぇ绁炶繘缇ゆ寚瀵硷紝鍏卞媺銆傜兢鍙凤細541144061


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表