용연운통신---위챗 세션 인터페이스에 들어가 서버를 로컬 데이터베이스에 주동적으로 동기화

7590 단어
위챗에 들어가서 메시지를 보내고 세션 채팅창에 들어가서 Hook팀이 보낸 방송을 수신합니다
package com.godinsec.seland.updatecontacts;

import com.godinsec.seland.immsUtils.LogUtils;
import com.godinsec.seland.sqlite.VChatSipInfoStorage;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Handler;
import android.os.Message;
import android.util.Log;

@SuppressWarnings("deprecation")
public class SipConfigWeiXinSyncServer extends BroadcastReceiver {
	// action --- !!!!!!  
    private final static String SIPCONFIG_WEIXIN_SYNC_SERVER_REQUEST = "com.godinec.seland.vertu.SipConfigWeiXinSyncServer"; 
    private final static String REFRESH_VCHAT_CONTACT_INFO = "com.godinsec.seland.action.ACTION_BIND_THREE_ID";
    private Context context;
    private Handler mHandler = new Handler(){
    	public void handleMessage(android.os.Message msg) {
    		switch (msg.what) {
			case 0:
				String[] weixinArray = (String[]) msg.obj;
	    		if (weixinArray==null) {
	    			return;
				}
	    		ContactController contactController = new ContactController(context);
	    		contactController.doRefreshPullDownListView(weixinArray);
				break;
			case 1:
				String[] vchatIds = VChatSipInfoStorage.getInstance().queryAllVChatIdFromWxInfo();
				if(vchatIds != null){
					ContactController controller = new ContactController(context);
					controller.doRefreshPullDownListView(vchatIds);
				}else{
					LogUtils.d("SipConfigWeiXinSyncServer", "------->vchatIds is null");
				}
				break;
			}
    	};
    };
	@Override
	public void onReceive(Context context, Intent intent) {
		this.context = context;
		if(intent != null){ 
			// , , weixin
			if(SIPCONFIG_WEIXIN_SYNC_SERVER_REQUEST.equals(intent.getAction())){
				String[] weixinArray = intent.getStringArrayExtra("weixinArray");
				Log.e("TAG", "weixinArray getted");
				Log.e("TAG", ""+weixinArray.length+"---"+weixinArray[0]+"---"+weixinArray[1]);
				Message msg = mHandler.obtainMessage();
				msg.what = 0;
				msg.obj = weixinArray;
				mHandler.sendMessage(msg);
			}
        }  
	}

}

구성 파일은 다음과 같습니다.
    <!--  sip_config  -->
        <receiver android:name="com.godinsec.seland.updatecontacts.SipConfigWeiXinSyncServer" >
            <intent-filter>
                <action android:name="com.godinec.seland.vertu.SipConfigWeiXinSyncServer" />
            </intent-filter>
        </receiver>

contactController.doRefreshPullDownListView(weixinArray);방법은 다음과 같다.
	/**
	 *  -- 
	 */
	public void doRefreshPullDownListView(String[] getWeixinIds) {
		if (!ProtocolUtil.isConnected()) {
			mContactUIHandler.sendEmptyMessage(codeConnectFailed);
			return;
		}
		if (Global.IsActive) {
			String[] weixinIds = getWeixinIds;

			ArrayList<String> weixinIdsDB = (ArrayList<String>) VChatSipInfoStorage
					.getInstance().queryAllVChatIdsFromVChatSipConfig();
			if (weixinIdsDB == null) {
				weixinIdsDB = new ArrayList<String>();
			}
			if (weixinIds != null) {
				for (String weixinId : weixinIds) {
					if (weixinIdsDB.contains(weixinId)) {
						continue;
					}
					weixinIdsDB.add(weixinId);
				}
			}

			String[] array = weixinIdsDB.toArray(new String[] {});
			if (array == null || array.length <= 0) {
				mContactUIHandler.sendEmptyMessage(codeNocontactRefreshfailed);
				return;
			}
			Log.e("TAG",
					"===============doRefreshPullDownListView==============");
			for (int i = 0; i < array.length; i++) {
				Log.e("TAG", "contactcontroller array[i]:" + array[i]);
			}
			mContactUIController.doRequestUserWeiXinIdVoIPinfo(array);
		} else {
			mContactUIHandler.sendEmptyMessage(codeNoactiveRefreshfailed);
		}
	}

doRequestUserWeiXinIdVoIPinfo 방법은 다음과 같습니다.
ContactUIController 코드에는 다음과 같은 중전 방법이 있습니다.
@Override
	public void doRequestUserWeiXinIdVoIPinfo(String[] weixinIds) {
		ContactService.getInstance().doRequestUserWeiXinVoIPinfo(this, weixinIds);
	}
	/**
	 *  id 
	 */
	public void doRequestUserWeiXinVoIPinfo(UICallback callback, String... wixinids) {
		Resource res = new Resource(callback);
		String myWeixinId = SQLiteManager.getInstance().queryWeixinIdOfMyself();
		String godinIdByVChatId = SQLiteManager.getInstance().queryGodinId();
		String userid = CasApplication.getInstance().getClientAuthInfo()
				.getUserId();
		res.setRequestKey(Global.RequestKey.KEY_USERVOIP_NET);
		res.setUrl(Global.getRequestUrl(Global.RequestUri.URI_GET_VOIP_USER_INFO, null));
		String requestJson = ProtocolUtil.buildJSONPacketBody(
				new String[] { "useragent", "network", "reqtime" ,"wechat_id","godin_id"},
				new Object[] { Global.getUser_Agent(), ProtocolUtil.getNetworkName() + "", DateUtil.getDefaultFormat() ,myWeixinId,godinIdByVChatId}, 
						
						new String[]{"wechat_id"}, new Object[] {wixinids});
		res.setRequestBody(requestJson);
		
		Log.e("TAG","contactService doRequestUserVoIP inforequestJson+"+requestJson);
		Log.e("TAG","contactService doRequestUserVoIP inforequestJson");
		addTask(res ,Resource.RESOURCE_UPLOAD_MOBILE);
	}

ContactUIController 코드로 돌아가기
else if (RequestKey.KEY_USERVOIP_NET.equals(document.getRequestKey())) {

			Log.e("TAG", "ContactUIController RequestKey.KEY_USERVOIP_NET");
			
			if (document instanceof ContactState) {
				ContactState doc = (ContactState) document;

				final ArrayList<Entry> entryList = doc.getEntryList();

				if (entryList != null && entryList.size() > 0) {
					Log.e("TAG", ""+entryList.size());
					
					// id
					ArrayList<String> list = new ArrayList<String>();
					for (Entry obj : entryList) {
						list.add(obj.getVchatId());
					}
					mWeixinIds = list.toArray(new String[] {});


					VChatSipInfoStorage.getInstance().insertVChatContacts(entryList);
				}
				
			}
			Message msg = mActivityHandler.obtainMessage();
			msg.what = Integer.parseInt(document.getRequestKey());
			Bundle bundle = new Bundle();
			bundle.putStringArray(VoipUtils.WEIXIN,
					mWeixinIds == null ? new String[] {} : mWeixinIds);
			msg.setData(bundle);
			
			mActivityHandler.sendMessage(msg);

		} 

ContactController 코드로 돌아가기
case RequestCode.KEY_USERVOIP_NET:
				// doRefreshOnlinePullDown();
				Log.e("TAG", "ContactController  RequestCode.KEY_USERVOIP_NET");
				/**
				 *  tek
				 */
				Bundle data = msg.getData();
				String[] weixinIds = (String[]) data.get(VoipUtils.WEIXIN);

				String godinIdString = VChatSipInfoStorage.getInstance()
						.queryLocalGodinId();
				if (TextUtils.isEmpty(godinIdString)) {
					Log.e("TAG", "godinIdString==null");
					return;
				}
				for (int i = 0; i < weixinIds.length; i++) {
					String queryGodinIdByWeixinId = VChatSipInfoStorage
							.getInstance().queryGodinIdByVChatId(weixinIds[i]);
					if (TextUtils.isEmpty(godinIdString)
							|| godinIdString.equals(queryGodinIdByWeixinId)) {
						continue;
					}
					//  、 tek
					KeyCheckUtil
							.checkTEK(context, queryGodinIdByWeixinId, null);
					Log.e("TAG", "checkTEK method");
				}

				break;

좋은 웹페이지 즐겨찾기