feat(Android): Add authInfo feature.
This commit is contained in:
@@ -4,6 +4,7 @@ import com.alipay.sdk.app.AuthTask;
|
|||||||
import com.alipay.sdk.app.PayTask;
|
import com.alipay.sdk.app.PayTask;
|
||||||
import com.alipay.sdk.app.EnvUtils;
|
import com.alipay.sdk.app.EnvUtils;
|
||||||
import com.facebook.react.bridge.Arguments;
|
import com.facebook.react.bridge.Arguments;
|
||||||
|
import com.facebook.react.bridge.Promise;
|
||||||
import com.facebook.react.bridge.ReactApplicationContext;
|
import com.facebook.react.bridge.ReactApplicationContext;
|
||||||
import com.facebook.react.bridge.ReactContextBaseJavaModule;
|
import com.facebook.react.bridge.ReactContextBaseJavaModule;
|
||||||
import com.facebook.react.bridge.ReactMethod;
|
import com.facebook.react.bridge.ReactMethod;
|
||||||
@@ -33,6 +34,20 @@ public class AlipayModule extends ReactContextBaseJavaModule {
|
|||||||
// callback.invoke("Received numberArgument: " + numberArgument + " stringArgument: " + stringArgument);
|
// callback.invoke("Received numberArgument: " + numberArgument + " stringArgument: " + stringArgument);
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
@ReactMethod
|
||||||
|
public void authInfo(final String infoStr, final Callback promise) {
|
||||||
|
Runnable runnable = new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
AuthTask alipay = new AuthTask(getCurrentActivity());
|
||||||
|
Map<String, String> map = alipay.authV2(infoStr, true);
|
||||||
|
promise.invoke(getWritableMap(map));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
Thread thread = new Thread(runnable);
|
||||||
|
thread.start();
|
||||||
|
}
|
||||||
|
|
||||||
@ReactMethod
|
@ReactMethod
|
||||||
public void setAlipaySandbox(Boolean isSandbox) {
|
public void setAlipaySandbox(Boolean isSandbox) {
|
||||||
if (isSandbox) {
|
if (isSandbox) {
|
||||||
@@ -48,11 +63,12 @@ public class AlipayModule extends ReactContextBaseJavaModule {
|
|||||||
public void run() {
|
public void run() {
|
||||||
PayTask alipay = new PayTask(getCurrentActivity());
|
PayTask alipay = new PayTask(getCurrentActivity());
|
||||||
Map<String, String> result = alipay.payV2(orderInfo, true);
|
Map<String, String> result = alipay.payV2(orderInfo, true);
|
||||||
WritableMap map = Arguments.createMap();
|
promise.invoke(getWritableMap(result));
|
||||||
map.putString("memo", result.get("memo"));
|
// WritableMap map = Arguments.createMap();
|
||||||
map.putString("result", result.get("result"));
|
// map.putString("memo", result.get("memo"));
|
||||||
map.putString("resultStatus", result.get("resultStatus"));
|
// map.putString("result", result.get("result"));
|
||||||
promise.invoke(map);
|
// map.putString("resultStatus", result.get("resultStatus"));
|
||||||
|
// promise.invoke(map);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
// 必须异步调用
|
// 必须异步调用
|
||||||
@@ -60,4 +76,11 @@ public class AlipayModule extends ReactContextBaseJavaModule {
|
|||||||
payThread.start();
|
payThread.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private WritableMap getWritableMap(Map<String, String> map) {
|
||||||
|
WritableMap writableMap = Arguments.createMap();
|
||||||
|
for (Map.Entry<String, String> entry : map.entrySet()) {
|
||||||
|
writableMap.putString(entry.getKey(), entry.getValue());
|
||||||
|
}
|
||||||
|
return writableMap;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user