• qq 登录 cordova插件


    1.下载open-sdk.jar文件和mta_sdk_x.x.x.jar文件拷贝到libs(或lib)目录下
    这个链接 很容易的把环境配置好
    http://wiki.connect.qq.com/%E5%88%9B%E5%BB%BA%E5%B9%B6%E9%85%8D%E7%BD%AE%E5%B7%A5%E7%A8%8B_android_sdk
    2. 配置AndroidManifest
    我配置错误
    所以我加了Demo中的数据就可以了

     1    <activity android:exported="true" android:label="@string/app_name" android:launchMode="singleTask" android:name="com.tencent.sample.wxapi.WXEntryActivity">
     2             <intent-filter>
     3                 <action android:name="android.intent.action.VIEW" />
     4                 <category android:name="android.intent.category.DEFAULT" />
     5                 <data android:scheme="sdksample" />
     6             </intent-filter>
     7         </activity>
     8         <receiver android:name="com.tencent.sample.AppRegister" android:permission="com.tencent.mm.plugin.permission.SEND">
     9             <intent-filter>
    10                 <action android:name="com.tencent.mm.plugin.openapi.Intent.ACTION_REFRESH_WXAPP" />
    11             </intent-filter>
    12         </receiver>
    13         <activity android:name="com.tencent.connect.avatar.ImageActivity" />
    14         <activity android:name="com.tencent.connect.common.AssistActivity" android:screenOrientation="portrait" android:theme="@android:style/Theme.Translucent.NoTitleBar" />
    15         <activity android:launchMode="singleTask" android:name="com.tencent.tauth.AuthActivity" android:noHistory="true">
    16             <intent-filter>
    17                 <action android:name="android.intent.action.VIEW" />
    18                 <category android:name="android.intent.category.DEFAULT" />
    19                 <category android:name="android.intent.category.BROWSABLE" />
    20                 <data android:scheme="tencent222222" />
    21             </intent-filter>
    22         </activity>

    3.环境配置好了之后

    创建自己的插件

    4.

    package cn.debi.cordova;
    import java.text.SimpleDateFormat;
    
    import org.apache.cordova.CallbackContext;
    import org.apache.cordova.CordovaPlugin;
    import org.json.JSONArray;
    import org.json.JSONException;
    import org.json.JSONObject;
    
    
    
    
    import android.app.Activity;
    import android.content.Context;
    import android.content.Intent;
    import android.os.Bundle;
    import android.util.Log;
    import android.widget.Toast;
    
    import com.tencent.tauth.IUiListener;
    import com.tencent.tauth.UiError;
    
    import com.tencent.tauth.Tencent;
    public class qqlogin extends CordovaPlugin{
        
        public static final String APPID ="222222";
          //private static final String APPID = "100363349";
        private Tencent mTencent = null;
        private CallbackContext  mCallbackContext = null;
        
    
        @Override
        public boolean execute(String action, JSONArray args, CallbackContext callbackContext) {
            mCallbackContext=callbackContext;
    
            if (action.equals("qqlogins")) {
                this.qqLogin();
    
    
            }else if(action.equals("qqLogout")){
                Context context = this.cordova.getActivity().getApplicationContext();
    
                mTencent.logout(context);
                mCallbackContext.success();
    
                
            }
            else {
                return false;
            }
            return true;
        }
        
        
        public void qqLogin(){
            // 创建授权认证信息
            final Activity activity = this.cordova.getActivity();
    
            Context context = this.cordova.getActivity().getApplicationContext();
            mTencent = Tencent.createInstance(APPID, context);
            
            final IUiListener listener = new BaseUiListener() {
                @Override
                protected void doComplete(JSONObject values) {
                    
    
                }
                
                
                
            };
            
            this.cordova.getActivity().runOnUiThread(new Runnable() {
                @Override
                public void run() {
    
                    mTencent.login(activity, "all", listener);
                }
            });
            
            
        }
        
        
    
        private class BaseUiListener implements IUiListener {
    
            @Override
            public void onComplete(Object response) {
                String uid=mTencent.getOpenId();
                String token=mTencent.getAccessToken();
                Log.d("uid111",uid);
    
                JSONObject res=new JSONObject();
                try {
           
                    res.put("uid", uid);
                    res.put("token", token);
                    mCallbackContext.success(res);
    
                } catch (JSONException e) {
                    // TODO Auto-generated catch block
                    mCallbackContext.error(0);
                    e.printStackTrace();
                }
    
            }
    
            protected void doComplete(JSONObject values) {
    
    
            }
    
            @Override
            public void onError(UiError e) {
                mCallbackContext.error(0);
    
    
            }
    
            @Override
            public void onCancel() {
                
                mCallbackContext.error(0);
    
            }
    
            
        }
    
    
    }

    5.qqlogin.js

    1 var exec = require('cordova/exec');
    2 
    3 exports.getqqlogin = function(messege,success, error) {
    4     exec(success, error, "qqlogin", "qqlogins", [messege]);
    5 };
    6 exports.getqqlogout= function(messege,success, error) {
    7     exec(success, error, "qqlogin", "qqlogout", [messege]);
    8 };

    6.plugin.xml

     1 <?xml version="1.0" encoding="utf-8"?>
     2 <plugin id="cn.debi.cordova" version="0.0.1" 
     3         xmlns="http://apache.org/cordova/ns/plugins/1.0"
     4         xmlns:android="http://schemas.android.com/apk/res/android">
     5     <name>qqlogin</name>
     6     <description>Description</description>
     7     <js-module name="qqlogin" src="www/qqlogin.js">
     8         <clobbers target="cordova.plugins.qqlogin"/>
     9     </js-module>
    10     <platform name="android">
    11         <config-file parent="/*" target="res/xml/config.xml">
    12             <feature name="qqlogin">
    13                 <param name="android-package" value="cn.debi.cordova.qqlogin"/>
    14             </feature>
    15         </config-file>
    16         <source-file src="src/android/qqlogin.java" target-dir="src/cn/debi/cordova"/>
    17     </platform>
    18 </plugin>

    7.调用

    1 var extraInfo = cordova.require('cn.debi.cordova.qqlogin');
    2     extraInfo.getqqlogin('cole.log',function(message) {
    3          alert(message);
    4     }, function(message) {
    5          alert(message);
    6     });

     8.添加直接插件

    cordova plugin add Login_QQ

    9.完成

    github 地址

  • 相关阅读:
    qbzt day6 上午
    qbzt day5 下午
    qbzt day5 上午
    【7.24校内交流赛】T3【qbxt】复读警告
    【7.24校内交流赛】T1&T2
    一个一定要好好提溜出来的贪心题
    7.19 讲题
    DP大大大大大赏
    图论经典例题大赏
    数据结构题大赏
  • 原文地址:https://www.cnblogs.com/xieyier/p/4074542.html
Copyright © 2020-2023  润新知