Skip to content

Commit

Permalink
Merge pull request #478 from jasonz1987/develop
Browse files Browse the repository at this point in the history
2.5.0
  • Loading branch information
jasonz1987 authored Dec 25, 2018
2 parents c8da4c7 + fd3affb commit 799dfa7
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 19 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Change Log

## 2.5.0 - 2018-12-26
### Fixed
- Android preferences code problem

## 2.4.0 - 2018-07-27
### Added
- Android compress thumb
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

**如果是使用cordova7以上版本,请切换到develop-cordova7分支代码。**

QQ群:190808518

# cordova-plugin-wechat

A cordova plugin, a JS version of Wechat SDK
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cordova-plugin-wechat",
"version": "2.4.0",
"version": "2.5.0",
"description": "A cordova plugin, a JS version of Wechat SDK",
"cordova": {
"id": "cordova-plugin-wechat",
Expand Down
2 changes: 1 addition & 1 deletion plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
xmlns:rim="http://www.blackberry.com/ns/widgets"
xmlns:android="http://schemas.android.com/apk/res/android"
id="cordova-plugin-wechat"
version="2.4.0">
version="2.5.0">

<name>Wechat</name>
<description>A cordova plugin, a JS version of Wechat SDK</description>
Expand Down
4 changes: 2 additions & 2 deletions src/android/EntryActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,10 @@ public void onResp(BaseResp resp) {
}

// restore appid
final String appid = Wechat.getAppId();
final String appid = Wechat.getAppId(null);
final String savedAppId = Wechat.getSavedAppId(this);
if (!savedAppId.equals(appid)) {
Wechat.saveAppId(this, Wechat.getAppId());
Wechat.saveAppId(this, Wechat.getAppId(null));
}

finish();
Expand Down
32 changes: 17 additions & 15 deletions src/android/Wechat.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import java.io.InputStream;
import java.io.ByteArrayOutputStream;
import java.io.ByteArrayInputStream;
import org.apache.cordova.CordovaPreferences;

public class Wechat extends CordovaPlugin {

Expand Down Expand Up @@ -98,13 +99,14 @@ public class Wechat extends CordovaPlugin {
protected static CallbackContext currentCallbackContext;
protected static IWXAPI wxAPI;
protected static String appId;
protected static CordovaPreferences wx_preferences;

@Override
protected void pluginInitialize() {

super.pluginInitialize();

String id = getAppId();
String id = getAppId(preferences);

// save app id
saveAppId(cordova.getActivity(), id);
Expand All @@ -117,9 +119,11 @@ protected void pluginInitialize() {

protected void initWXAPI() {
IWXAPI api = getWxAPI(cordova.getActivity());

if(wx_preferences == null) {
wx_preferences = preferences;
}
if (api != null) {
api.registerApp(getAppId());
api.registerApp(getAppId(preferences));
}
}

Expand Down Expand Up @@ -280,7 +284,7 @@ protected boolean sendPaymentRequest(CordovaArgs args, CallbackContext callbackC

try {
final String appid = params.getString("appid");
final String savedAppid = getAppId(cordova.getActivity());
final String savedAppid = getSavedAppId(cordova.getActivity());
if (!savedAppid.equals(appid)) {
this.saveAppId(cordova.getActivity(), appid);
}
Expand Down Expand Up @@ -332,7 +336,7 @@ protected boolean chooseInvoiceFromWX(CordovaArgs args, CallbackContext callback
ChooseCardFromWXCardPackage.Req req = new ChooseCardFromWXCardPackage.Req();

try {
req.appId = getAppId();
req.appId = getAppId(preferences);
req.cardType = "INVOICE";
req.signType = params.getString("signType");
req.cardSign = params.getString("cardSign");
Expand Down Expand Up @@ -541,10 +545,7 @@ protected Bitmap getBitmap(JSONObject message, String key, int maxSize) {

/**
* compress bitmap by quility
*
* @param url
* @return
*/
*/
protected Bitmap compressImage(Bitmap image,Integer maxSize) {

ByteArrayOutputStream baos = new ByteArrayOutputStream();
Expand All @@ -563,9 +564,6 @@ protected Bitmap compressImage(Bitmap image,Integer maxSize) {

/**
* Get input stream from a url
*
* @param url
* @return
*/
protected InputStream getFileInputStream(String url) {
try {
Expand Down Expand Up @@ -626,9 +624,13 @@ protected InputStream getFileInputStream(String url) {
return null;
}

public static String getAppId() {
public static String getAppId(CordovaPreferences f_preferences) {
if (appId == null) {
appId = preferences.getString(WXAPPID_PROPERTY_KEY, "");
if(f_preferences != null) {
appId = f_preferences.getString(WXAPPID_PROPERTY_KEY, "");
}else if(wx_preferences != null){
appId = wx_preferences.getString(WXAPPID_PROPERTY_KEY, "");
}
}

return appId;
Expand All @@ -650,7 +652,7 @@ public static String getSavedAppId(Context ctx) {
* @param id
*/
public static void saveAppId(Context ctx, String id) {
if (id.isEmpty()) {
if (id!=null && id.isEmpty()) {
return ;
}

Expand Down

0 comments on commit 799dfa7

Please sign in to comment.