repo stringclasses 1k values | file_url stringlengths 96 373 | file_path stringlengths 11 294 | content stringlengths 0 32.8k | language stringclasses 1 value | license stringclasses 6 values | commit_sha stringclasses 1k values | retrieved_at stringdate 2026-01-04 14:45:56 2026-01-04 18:30:23 | truncated bool 2 classes |
|---|---|---|---|---|---|---|---|---|
liveservices/LiveSDK-for-Android | https://github.com/liveservices/LiveSDK-for-Android/blob/7feda438a5492a7544fdad527325b5b05f760cc5/sample/src/com/microsoft/live/sample/identity/ViewProfileActivity.java | sample/src/com/microsoft/live/sample/identity/ViewProfileActivity.java | // ------------------------------------------------------------------------------
// Copyright (c) 2014 Microsoft Corporation
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
// ------------------------------------------------------------------------------
package com.microsoft.live.sample.identity;
import org.json.JSONObject;
import android.app.Activity;
import android.graphics.drawable.BitmapDrawable;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.TextView;
import android.widget.Toast;
import com.microsoft.live.LiveAuthClient;
import com.microsoft.live.LiveAuthException;
import com.microsoft.live.LiveAuthListener;
import com.microsoft.live.LiveConnectClient;
import com.microsoft.live.LiveConnectSession;
import com.microsoft.live.LiveDownloadOperation;
import com.microsoft.live.LiveDownloadOperationListener;
import com.microsoft.live.LiveOperation;
import com.microsoft.live.LiveOperationException;
import com.microsoft.live.LiveOperationListener;
import com.microsoft.live.LiveStatus;
import com.microsoft.live.sample.LiveSdkSampleApplication;
import com.microsoft.live.sample.R;
import com.microsoft.live.sample.util.JsonKeys;
public class ViewProfileActivity extends Activity {
private class DownloadProfilePictureAsyncTask extends AsyncTask<LiveDownloadOperation, Void, BitmapDrawable> {
@Override
protected BitmapDrawable doInBackground(LiveDownloadOperation... params) {
return new BitmapDrawable(getResources(), params[0].getStream());
}
@Override
protected void onPostExecute(BitmapDrawable profilePicture) {
mNameTextView.setCompoundDrawablesWithIntrinsicBounds(profilePicture,
null,
null,
null);
}
}
private TextView mNameTextView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.view_profile);
mNameTextView = (TextView)findViewById(R.id.nameTextView);
final LiveSdkSampleApplication app = (LiveSdkSampleApplication)getApplication();
findViewById(R.id.signOutButton).setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
LiveAuthClient authClient = app.getAuthClient();
authClient.logout(new LiveAuthListener() {
@Override
public void onAuthError(LiveAuthException exception, Object userState) {
showToast(exception.getMessage());
}
@Override
public void onAuthComplete(LiveStatus status,
LiveConnectSession session,
Object userState) {
app.setSession(null);
app.setConnectClient(null);
getParent().finish();
}
});
}
});
final LiveConnectClient connectClient = app.getConnectClient();
connectClient.getAsync("me", new LiveOperationListener() {
@Override
public void onError(LiveOperationException exception, LiveOperation operation) {
showToast(exception.getMessage());
}
@Override
public void onComplete(LiveOperation operation) {
JSONObject result = operation.getResult();
if (result.has(JsonKeys.ERROR)) {
JSONObject error = result.optJSONObject(JsonKeys.ERROR);
String code = error.optString(JsonKeys.CODE);
String message = error.optString(JsonKeys.MESSAGE);
showToast(code + ": " + message);
} else {
User user = new User(result);
mNameTextView.setText("Hello, " + user.getName() + "!");
}
}
});
connectClient.getAsync("me/picture", new LiveOperationListener() {
@Override
public void onError(LiveOperationException exception, LiveOperation operation) {
showToast(exception.getMessage());
}
@Override
public void onComplete(LiveOperation operation) {
JSONObject result = operation.getResult();
if (result.has(JsonKeys.ERROR)) {
JSONObject error = result.optJSONObject(JsonKeys.ERROR);
String code = error.optString(JsonKeys.CODE);
String message = error.optString(JsonKeys.MESSAGE);
showToast(code + ": " + message);
return;
}
String location = result.optString(JsonKeys.LOCATION);
connectClient.downloadAsync(location, new LiveDownloadOperationListener() {
@Override
public void onDownloadProgress(int totalBytes,
int bytesRemaining,
LiveDownloadOperation operation) {
}
@Override
public void onDownloadFailed(LiveOperationException exception,
LiveDownloadOperation operation) {
showToast(exception.getMessage());
}
@Override
public void onDownloadCompleted(LiveDownloadOperation operation) {
DownloadProfilePictureAsyncTask task =
new DownloadProfilePictureAsyncTask();
task.execute(operation);
}
});
}
});
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
// Since this activity is part of a TabView we want to send
// the back button to the TabView activity.
if (keyCode == KeyEvent.KEYCODE_BACK) {
return false;
} else {
return super.onKeyDown(keyCode, event);
}
}
private void showToast(String message) {
Toast.makeText(this, message, Toast.LENGTH_LONG).show();
}
}
| java | MIT | 7feda438a5492a7544fdad527325b5b05f760cc5 | 2026-01-05T02:42:35.605851Z | false |
liveservices/LiveSDK-for-Android | https://github.com/liveservices/LiveSDK-for-Android/blob/7feda438a5492a7544fdad527325b5b05f760cc5/sample/src/com/microsoft/live/sample/skydrive/SkyDriveObject.java | sample/src/com/microsoft/live/sample/skydrive/SkyDriveObject.java | // ------------------------------------------------------------------------------
// Copyright (c) 2014 Microsoft Corporation
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
// ------------------------------------------------------------------------------
package com.microsoft.live.sample.skydrive;
import org.json.JSONObject;
import android.util.Log;
public abstract class SkyDriveObject {
public interface Visitor {
public void visit(SkyDriveAlbum album);
public void visit(SkyDriveAudio audio);
public void visit(SkyDrivePhoto photo);
public void visit(SkyDriveFolder folder);
public void visit(SkyDriveFile file);
public void visit(SkyDriveVideo video);
}
public static class From {
private final JSONObject mFrom;
public From(JSONObject from) {
assert from != null;
mFrom = from;
}
public String getName() {
return mFrom.optString("name");
}
public String getId() {
return mFrom.optString("id");
}
public JSONObject toJson() {
return mFrom;
}
}
public static class SharedWith {
private final JSONObject mSharedWidth;
public SharedWith(JSONObject sharedWith) {
assert sharedWith != null;
mSharedWidth = sharedWith;
}
public String getAccess() {
return mSharedWidth.optString("access");
}
public JSONObject toJson() {
return mSharedWidth;
}
}
public static SkyDriveObject create(JSONObject skyDriveObject) {
String type = skyDriveObject.optString("type");
if (type.equals(SkyDriveFolder.TYPE)) {
return new SkyDriveFolder(skyDriveObject);
} else if (type.equals(SkyDriveFile.TYPE)) {
return new SkyDriveFile(skyDriveObject);
} else if (type.equals(SkyDriveAlbum.TYPE)) {
return new SkyDriveAlbum(skyDriveObject);
} else if (type.equals(SkyDrivePhoto.TYPE)) {
return new SkyDrivePhoto(skyDriveObject);
} else if (type.equals(SkyDriveVideo.TYPE)) {
return new SkyDriveVideo(skyDriveObject);
} else if (type.equals(SkyDriveAudio.TYPE)) {
return new SkyDriveAudio(skyDriveObject);
}
final String name = skyDriveObject.optString("name");
Log.e(SkyDriveObject.class.getName(),
String.format("Unknown SkyDriveObject type. Name: %s, Type %s", name, type));
return null;
}
protected final JSONObject mObject;
public SkyDriveObject(JSONObject object) {
assert object != null;
mObject = object;
}
public abstract void accept(Visitor visitor);
public String getId() {
return mObject.optString("id");
}
public From getFrom() {
return new From(mObject.optJSONObject("from"));
}
public String getName() {
return mObject.optString("name");
}
public String getParentId() {
return mObject.optString("parent_id");
}
public String getDescription() {
return mObject.isNull("description") ? null : mObject.optString("description");
}
public String getType() {
return mObject.optString("type");
}
public String getLink() {
return mObject.optString("link");
}
public String getCreatedTime() {
return mObject.optString("created_time");
}
public String getUpdatedTime() {
return mObject.optString("updated_time");
}
public String getUploadLocation() {
return mObject.optString("upload_location");
}
public SharedWith getSharedWith() {
return new SharedWith(mObject.optJSONObject("shared_with"));
}
public JSONObject toJson() {
return mObject;
}
}
| java | MIT | 7feda438a5492a7544fdad527325b5b05f760cc5 | 2026-01-05T02:42:35.605851Z | false |
liveservices/LiveSDK-for-Android | https://github.com/liveservices/LiveSDK-for-Android/blob/7feda438a5492a7544fdad527325b5b05f760cc5/sample/src/com/microsoft/live/sample/skydrive/SkyDriveAudio.java | sample/src/com/microsoft/live/sample/skydrive/SkyDriveAudio.java | // ------------------------------------------------------------------------------
// Copyright (c) 2014 Microsoft Corporation
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
// ------------------------------------------------------------------------------
package com.microsoft.live.sample.skydrive;
import org.json.JSONObject;
public class SkyDriveAudio extends SkyDriveObject {
public static final String TYPE = "audio";
public SkyDriveAudio(JSONObject object) {
super(object);
}
@Override
public void accept(Visitor visitor) {
visitor.visit(this);
}
public long getSize() {
return mObject.optLong("size");
}
public int getCommentsCount() {
return mObject.optInt("comments_count");
}
public boolean getCommentsEnabled() {
return mObject.optBoolean("comments_enabled");
}
public String getSource() {
return mObject.optString("source");
}
public boolean getIsEmbeddable() {
return mObject.optBoolean("is_embeddable");
}
}
| java | MIT | 7feda438a5492a7544fdad527325b5b05f760cc5 | 2026-01-05T02:42:35.605851Z | false |
liveservices/LiveSDK-for-Android | https://github.com/liveservices/LiveSDK-for-Android/blob/7feda438a5492a7544fdad527325b5b05f760cc5/sample/src/com/microsoft/live/sample/skydrive/SkyDriveFile.java | sample/src/com/microsoft/live/sample/skydrive/SkyDriveFile.java | // ------------------------------------------------------------------------------
// Copyright (c) 2014 Microsoft Corporation
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
// ------------------------------------------------------------------------------
package com.microsoft.live.sample.skydrive;
import org.json.JSONObject;
public class SkyDriveFile extends SkyDriveObject {
public static final String TYPE = "file";
public SkyDriveFile(JSONObject file) {
super(file);
}
@Override
public void accept(Visitor visitor) {
visitor.visit(this);
}
public long getSize() {
return mObject.optLong("size");
}
public int getCommentsCount() {
return mObject.optInt("comments_count");
}
public boolean getCommentsEnabled() {
return mObject.optBoolean("comments_enabled");
}
public String getSource() {
return mObject.optString("source");
}
public boolean getIsEmbeddable() {
return mObject.optBoolean("is_embeddable");
}
}
| java | MIT | 7feda438a5492a7544fdad527325b5b05f760cc5 | 2026-01-05T02:42:35.605851Z | false |
liveservices/LiveSDK-for-Android | https://github.com/liveservices/LiveSDK-for-Android/blob/7feda438a5492a7544fdad527325b5b05f760cc5/sample/src/com/microsoft/live/sample/skydrive/SkyDriveAlbum.java | sample/src/com/microsoft/live/sample/skydrive/SkyDriveAlbum.java | // ------------------------------------------------------------------------------
// Copyright (c) 2014 Microsoft Corporation
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
// ------------------------------------------------------------------------------
package com.microsoft.live.sample.skydrive;
import org.json.JSONObject;
public class SkyDriveAlbum extends SkyDriveObject {
public static final String TYPE = "album";
public SkyDriveAlbum(JSONObject object) {
super(object);
}
@Override
public void accept(Visitor visitor) {
visitor.visit(this);
}
public int getCount() {
return mObject.optInt("count");
}
}
| java | MIT | 7feda438a5492a7544fdad527325b5b05f760cc5 | 2026-01-05T02:42:35.605851Z | false |
liveservices/LiveSDK-for-Android | https://github.com/liveservices/LiveSDK-for-Android/blob/7feda438a5492a7544fdad527325b5b05f760cc5/sample/src/com/microsoft/live/sample/skydrive/SkyDrivePhoto.java | sample/src/com/microsoft/live/sample/skydrive/SkyDrivePhoto.java | // ------------------------------------------------------------------------------
// Copyright (c) 2014 Microsoft Corporation
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
// ------------------------------------------------------------------------------
package com.microsoft.live.sample.skydrive;
import org.json.JSONArray;
import org.json.JSONObject;
public class SkyDrivePhoto extends SkyDriveObject {
public static final String TYPE = "photo";
public static class Image {
private final JSONObject mImage;
public Image(JSONObject image) {
assert image != null;
mImage = image;
}
public int getHeight() {
return mImage.optInt("height");
}
public int getWidth() {
return mImage.optInt("width");
}
public String getSource() {
return mImage.optString("source");
}
public String getType() {
return mImage.optString("type");
}
public JSONObject toJson() {
return mImage;
}
}
public SkyDrivePhoto(JSONObject photo) {
super(photo);
}
@Override
public void accept(Visitor visitor) {
visitor.visit(this);
}
public long getSize() {
return mObject.optLong("size");
}
public int getCommentsCount() {
return mObject.optInt("comments_count");
}
public boolean getCommentsEnabled() {
return mObject.optBoolean("comments_enabled");
}
public String getSource() {
return mObject.optString("source");
}
public int getTagsCount() {
return mObject.optInt("tags_count");
}
public boolean getTagsEnabled() {
return mObject.optBoolean("tags_enabled");
}
public String getPicture() {
return mObject.optString("picture");
}
public Image[] getImages() {
JSONArray images = mObject.optJSONArray("images");
Image[] imgs = new Image[images.length()];
for (int i = 0; i < images.length(); i++) {
imgs[i] = new Image(images.optJSONObject(i));
}
return imgs;
}
public String getWhenTaken() {
return mObject.isNull("when_taken") ? null : mObject.optString("when_taken");
}
public int getHeight() {
return mObject.optInt("height");
}
public int getWidth() {
return mObject.optInt("width");
}
}
| java | MIT | 7feda438a5492a7544fdad527325b5b05f760cc5 | 2026-01-05T02:42:35.605851Z | false |
liveservices/LiveSDK-for-Android | https://github.com/liveservices/LiveSDK-for-Android/blob/7feda438a5492a7544fdad527325b5b05f760cc5/sample/src/com/microsoft/live/sample/skydrive/SkyDriveVideo.java | sample/src/com/microsoft/live/sample/skydrive/SkyDriveVideo.java | // ------------------------------------------------------------------------------
// Copyright (c) 2014 Microsoft Corporation
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
// ------------------------------------------------------------------------------
package com.microsoft.live.sample.skydrive;
import org.json.JSONObject;
public class SkyDriveVideo extends SkyDriveObject {
public static final String TYPE = "video";
public SkyDriveVideo(JSONObject object) {
super(object);
}
@Override
public void accept(Visitor visitor) {
visitor.visit(this);
}
public long getSize() {
return mObject.optLong("size");
}
public int getCommentsCount() {
return mObject.optInt("comments_count");
}
public boolean getCommentsEnabled() {
return mObject.optBoolean("comments_enabled");
}
public String getSource() {
return mObject.optString("source");
}
public int getTagsCount() {
return mObject.optInt("tags_count");
}
public boolean getTagsEnabled() {
return mObject.optBoolean("tags_enabled");
}
public String getPicture() {
return mObject.optString("picture");
}
public int getHeight() {
return mObject.optInt("height");
}
public int getWidth() {
return mObject.optInt("width");
}
public int getDuration() {
return mObject.optInt("duration");
}
public int getBitrate() {
return mObject.optInt("bitrate");
}
}
| java | MIT | 7feda438a5492a7544fdad527325b5b05f760cc5 | 2026-01-05T02:42:35.605851Z | false |
liveservices/LiveSDK-for-Android | https://github.com/liveservices/LiveSDK-for-Android/blob/7feda438a5492a7544fdad527325b5b05f760cc5/sample/src/com/microsoft/live/sample/skydrive/SkyDriveFolder.java | sample/src/com/microsoft/live/sample/skydrive/SkyDriveFolder.java | // ------------------------------------------------------------------------------
// Copyright (c) 2014 Microsoft Corporation
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
// ------------------------------------------------------------------------------
package com.microsoft.live.sample.skydrive;
import org.json.JSONObject;
public class SkyDriveFolder extends SkyDriveObject {
public static final String TYPE = "folder";
public SkyDriveFolder(JSONObject object) {
super(object);
}
@Override
public void accept(Visitor visitor) {
visitor.visit(this);
}
public int getCount() {
return mObject.optInt("count");
}
}
| java | MIT | 7feda438a5492a7544fdad527325b5b05f760cc5 | 2026-01-05T02:42:35.605851Z | false |
liveservices/LiveSDK-for-Android | https://github.com/liveservices/LiveSDK-for-Android/blob/7feda438a5492a7544fdad527325b5b05f760cc5/sample/src/com/microsoft/live/sample/skydrive/SkyDriveActivity.java | sample/src/com/microsoft/live/sample/skydrive/SkyDriveActivity.java | // ------------------------------------------------------------------------------
// Copyright (c) 2014 Microsoft Corporation
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
// ------------------------------------------------------------------------------
package com.microsoft.live.sample.skydrive;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.Stack;
import org.json.JSONArray;
import org.json.JSONObject;
import android.app.AlertDialog;
import android.app.Dialog;
import android.app.ListActivity;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnCancelListener;
import android.content.DialogInterface.OnDismissListener;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Rect;
import android.media.AudioManager;
import android.media.MediaPlayer;
import android.media.MediaPlayer.OnCompletionListener;
import android.media.MediaPlayer.OnPreparedListener;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Environment;
import android.text.TextUtils;
import android.view.Display;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.MediaController;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.VideoView;
import com.microsoft.live.LiveConnectClient;
import com.microsoft.live.LiveDownloadOperation;
import com.microsoft.live.LiveDownloadOperationListener;
import com.microsoft.live.LiveOperation;
import com.microsoft.live.LiveOperationException;
import com.microsoft.live.LiveOperationListener;
import com.microsoft.live.LiveUploadOperationListener;
import com.microsoft.live.sample.LiveSdkSampleApplication;
import com.microsoft.live.sample.R;
import com.microsoft.live.sample.skydrive.SkyDriveObject.Visitor;
import com.microsoft.live.sample.skydrive.SkyDrivePhoto.Image;
import com.microsoft.live.sample.util.FilePicker;
import com.microsoft.live.sample.util.JsonKeys;
public class SkyDriveActivity extends ListActivity {
private class NewFolderDialog extends Dialog {
public NewFolderDialog(Context context) {
super(context);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.create_folder);
setTitle("New Folder");
final EditText name = (EditText) findViewById(R.id.nameEditText);
final EditText description = (EditText) findViewById(R.id.descriptionEditText);
findViewById(R.id.saveButton).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Map<String, String> folder = new HashMap<String, String>();
folder.put(JsonKeys.NAME, name.getText().toString());
folder.put(JsonKeys.DESCRIPTION, description.getText().toString());
final ProgressDialog progressDialog =
showProgressDialog("", "Saving. Please wait...", true);
progressDialog.show();
mClient.postAsync(mCurrentFolderId,
new JSONObject(folder),
new LiveOperationListener() {
@Override
public void onError(LiveOperationException exception, LiveOperation operation) {
progressDialog.dismiss();
showToast(exception.getMessage());
}
@Override
public void onComplete(LiveOperation operation) {
progressDialog.dismiss();
JSONObject result = operation.getResult();
if (result.has(JsonKeys.ERROR)) {
JSONObject error = result.optJSONObject(JsonKeys.ERROR);
String message = error.optString(JsonKeys.MESSAGE);
String code = error.optString(JsonKeys.CODE);
showToast(code + ":" + message);
} else {
dismiss();
loadFolder(mCurrentFolderId);
}
}
});
}
});
findViewById(R.id.cancelButton).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
dismiss();
}
});
}
}
private class PlayAudioDialog extends Dialog {
private final SkyDriveAudio mAudio;
private MediaPlayer mPlayer;
private TextView mPlayerStatus;
public PlayAudioDialog(Context context, SkyDriveAudio audio) {
super(context);
assert audio != null;
mAudio = audio;
mPlayer = new MediaPlayer();
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setTitle(mAudio.getName());
mPlayerStatus = new TextView(getContext());
mPlayerStatus.setText("Buffering...");
addContentView(mPlayerStatus,
new LayoutParams(LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT));
mPlayer.setOnPreparedListener(new OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mp) {
mPlayerStatus.setText("Playing...");
mPlayer.start();
}
});
mPlayer.setOnCompletionListener(new OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mp) {
mPlayerStatus.setText("Finished playing.");
}
});
try {
mPlayer.setDataSource(mAudio.getSource());
mPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
mPlayer.prepareAsync();
} catch (IllegalArgumentException e) {
showToast(e.getMessage());
return;
} catch (IllegalStateException e) {
showToast(e.getMessage());
return;
} catch (IOException e) {
showToast(e.getMessage());
return;
}
}
@Override
protected void onStop() {
super.onStop();
mPlayer.stop();
mPlayer.release();
mPlayer = null;
}
}
/**
* Supported media formats can be found
* <a href="http://developer.android.com/guide/appendix/media-formats.html">here</a>
*/
private class PlayVideoDialog extends Dialog {
private final SkyDriveVideo mVideo;
private VideoView mVideoHolder;
public PlayVideoDialog(Context context, SkyDriveVideo video) {
super(context);
assert video != null;
mVideo = video;
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setTitle(mVideo.getName());
mVideoHolder = new VideoView(getContext());
mVideoHolder.setMediaController(new MediaController(getContext()));
mVideoHolder.setVideoURI(Uri.parse(mVideo.getSource()));
addContentView(mVideoHolder,
new LayoutParams(LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT));
}
@Override
protected void onStart() {
super.onStart();
mVideoHolder.start();
}
}
private class SkyDriveListAdapter extends BaseAdapter {
private final LayoutInflater mInflater;
private final ArrayList<SkyDriveObject> mSkyDriveObjs;
private View mView;
public SkyDriveListAdapter(Context context) {
mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
mSkyDriveObjs = new ArrayList<SkyDriveObject>();
}
/**
* @return The underlying array of the class. If changes are made to this object and you
* want them to be seen, call {@link #notifyDataSetChanged()}.
*/
public ArrayList<SkyDriveObject> getSkyDriveObjs() {
return mSkyDriveObjs;
}
@Override
public int getCount() {
return mSkyDriveObjs.size();
}
@Override
public SkyDriveObject getItem(int position) {
return mSkyDriveObjs.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
// Note: This implementation of the ListAdapter.getView(...) forces a download of thumb-nails when retrieving
// views, this is not a good solution in regards to CPU time and network band-width.
@Override
public View getView(int position, View convertView, final ViewGroup parent) {
SkyDriveObject skyDriveObj = getItem(position);
mView = convertView != null ? convertView : null;
skyDriveObj.accept(new Visitor() {
@Override
public void visit(SkyDriveVideo video) {
if (mView == null) {
mView = inflateNewSkyDriveListItem();
}
setIcon(R.drawable.video_x_generic);
setName(video);
setDescription(video);
}
@Override
public void visit(SkyDriveFile file) {
if (mView == null) {
mView = inflateNewSkyDriveListItem();
}
setIcon(R.drawable.text_x_preview);
setName(file);
setDescription(file);
}
@Override
public void visit(SkyDriveFolder folder) {
if (mView == null) {
mView = inflateNewSkyDriveListItem();
}
setIcon(R.drawable.folder);
setName(folder);
setDescription(folder);
}
@Override
public void visit(SkyDrivePhoto photo) {
if (mView == null) {
mView = inflateNewSkyDriveListItem();
}
setIcon(R.drawable.image_x_generic);
setName(photo);
setDescription(photo);
// Try to find a smaller/thumbnail and use that source
String thumbnailSource = null;
String smallSource = null;
for (Image image : photo.getImages()) {
if (image.getType().equals("small")) {
smallSource = image.getSource();
} else if (image.getType().equals("thumbnail")) {
thumbnailSource = image.getSource();
}
}
String source = thumbnailSource != null ? thumbnailSource :
smallSource != null ? smallSource : null;
// if we do not have a thumbnail or small image, just leave.
if (source == null) {
return;
}
// Since we are doing async calls and mView is constantly changing,
// we need to hold on to this reference.
final View v = mView;
new AsyncTask<String, Long, Bitmap>() {
@Override
protected Bitmap doInBackground(String... params) {
try {
// Download the thumb nail image
LiveDownloadOperation operation = mClient.download(params[0]);
// Make sure we don't burn up memory for all of
// these thumb nails that are transient
BitmapFactory.Options options = new BitmapFactory.Options();
options.inPurgeable = true;
return BitmapFactory.decodeStream(operation.getStream(), (Rect)null, options);
} catch (Exception e) {
showToast(e.getMessage());
return null;
}
}
@Override
protected void onPostExecute(Bitmap result) {
ImageView imgView = (ImageView)v.findViewById(R.id.skyDriveItemIcon);
imgView.setImageBitmap(result);
}
}.execute(source);
}
@Override
public void visit(SkyDriveAlbum album) {
if (mView == null) {
mView = inflateNewSkyDriveListItem();
}
setIcon(R.drawable.folder_image);
setName(album);
setDescription(album);
}
@Override
public void visit(SkyDriveAudio audio) {
if (mView == null) {
mView = inflateNewSkyDriveListItem();
}
setIcon(R.drawable.audio_x_generic);
setName(audio);
setDescription(audio);
}
private void setName(SkyDriveObject skyDriveObj) {
TextView tv = (TextView) mView.findViewById(R.id.nameTextView);
tv.setText(skyDriveObj.getName());
}
private void setDescription(SkyDriveObject skyDriveObj) {
String description = skyDriveObj.getDescription();
if (description == null) {
description = "No description.";
}
TextView tv = (TextView) mView.findViewById(R.id.descriptionTextView);
tv.setText(description);
}
private View inflateNewSkyDriveListItem() {
return mInflater.inflate(R.layout.skydrive_list_item, parent, false);
}
private void setIcon(int iconResId) {
ImageView img = (ImageView) mView.findViewById(R.id.skyDriveItemIcon);
img.setImageResource(iconResId);
}
});
return mView;
}
}
private class ViewPhotoDialog extends Dialog {
private final SkyDrivePhoto mPhoto;
public ViewPhotoDialog(Context context, SkyDrivePhoto photo) {
super(context);
assert photo != null;
mPhoto = photo;
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setTitle(mPhoto.getName());
final ImageView imgView = new ImageView(getContext());
addContentView(imgView,
new LayoutParams(LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT));
mClient.downloadAsync(mPhoto.getSource(), new LiveDownloadOperationListener() {
@Override
public void onDownloadProgress(int totalBytes,
int bytesRemaining,
LiveDownloadOperation operation) {
}
@Override
public void onDownloadFailed(LiveOperationException exception,
LiveDownloadOperation operation) {
showToast(exception.getMessage());
}
@Override
public void onDownloadCompleted(LiveDownloadOperation operation) {
new AsyncTask<LiveDownloadOperation, Long, Bitmap>() {
@Override
protected Bitmap doInBackground(LiveDownloadOperation... params) {
return extractScaledBitmap(mPhoto, params[0].getStream());
}
@Override
protected void onPostExecute(Bitmap result) {
imgView.setImageBitmap(result);
}
}.execute(operation);
}
});
}
}
public static final String EXTRA_PATH = "path";
private static final int DIALOG_DOWNLOAD_ID = 0;
private static final String HOME_FOLDER = "me/skydrive";
private LiveConnectClient mClient;
private SkyDriveListAdapter mPhotoAdapter;
private String mCurrentFolderId;
private Stack<String> mPrevFolderIds;
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == FilePicker.PICK_FILE_REQUEST) {
if (resultCode == RESULT_OK) {
String filePath = data.getStringExtra(FilePicker.EXTRA_FILE_PATH);
if (TextUtils.isEmpty(filePath)) {
showToast("No file was choosen.");
return;
}
File file = new File(filePath);
final ProgressDialog uploadProgressDialog =
new ProgressDialog(SkyDriveActivity.this);
uploadProgressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
uploadProgressDialog.setMessage("Uploading...");
uploadProgressDialog.setCancelable(true);
uploadProgressDialog.show();
final LiveOperation operation =
mClient.uploadAsync(mCurrentFolderId,
file.getName(),
file,
new LiveUploadOperationListener() {
@Override
public void onUploadProgress(int totalBytes,
int bytesRemaining,
LiveOperation operation) {
int percentCompleted = computePrecentCompleted(totalBytes, bytesRemaining);
uploadProgressDialog.setProgress(percentCompleted);
}
@Override
public void onUploadFailed(LiveOperationException exception,
LiveOperation operation) {
uploadProgressDialog.dismiss();
showToast(exception.getMessage());
}
@Override
public void onUploadCompleted(LiveOperation operation) {
uploadProgressDialog.dismiss();
JSONObject result = operation.getResult();
if (result.has(JsonKeys.ERROR)) {
JSONObject error = result.optJSONObject(JsonKeys.ERROR);
String message = error.optString(JsonKeys.MESSAGE);
String code = error.optString(JsonKeys.CODE);
showToast(code + ": " + message);
return;
}
loadFolder(mCurrentFolderId);
}
});
uploadProgressDialog.setOnCancelListener(new OnCancelListener() {
@Override
public void onCancel(DialogInterface dialog) {
operation.cancel();
}
});
}
}
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.skydrive);
mPrevFolderIds = new Stack<String>();
ListView lv = getListView();
lv.setTextFilterEnabled(true);
lv.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
SkyDriveObject skyDriveObj = (SkyDriveObject) parent.getItemAtPosition(position);
skyDriveObj.accept(new Visitor() {
@Override
public void visit(SkyDriveAlbum album) {
mPrevFolderIds.push(mCurrentFolderId);
loadFolder(album.getId());
}
@Override
public void visit(SkyDrivePhoto photo) {
ViewPhotoDialog dialog =
new ViewPhotoDialog(SkyDriveActivity.this, photo);
dialog.setOwnerActivity(SkyDriveActivity.this);
dialog.show();
}
@Override
public void visit(SkyDriveFolder folder) {
mPrevFolderIds.push(mCurrentFolderId);
loadFolder(folder.getId());
}
@Override
public void visit(SkyDriveFile file) {
Bundle b = new Bundle();
b.putString(JsonKeys.ID, file.getId());
b.putString(JsonKeys.NAME, file.getName());
showDialog(DIALOG_DOWNLOAD_ID, b);
}
@Override
public void visit(SkyDriveVideo video) {
PlayVideoDialog dialog = new PlayVideoDialog(SkyDriveActivity.this, video);
dialog.setOwnerActivity(SkyDriveActivity.this);
dialog.show();
}
@Override
public void visit(SkyDriveAudio audio) {
PlayAudioDialog audioDialog =
new PlayAudioDialog(SkyDriveActivity.this, audio);
audioDialog.show();
}
});
}
});
LinearLayout layout = new LinearLayout(this);
Button newFolderButton = new Button(this);
newFolderButton.setText("New Folder");
newFolderButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
NewFolderDialog dialog = new NewFolderDialog(SkyDriveActivity.this);
dialog.setOwnerActivity(SkyDriveActivity.this);
dialog.show();
}
});
layout.addView(newFolderButton);
Button uploadFileButton = new Button(this);
uploadFileButton.setText("Upload File");
uploadFileButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(getApplicationContext(), FilePicker.class);
startActivityForResult(intent, FilePicker.PICK_FILE_REQUEST);
}
});
layout.addView(uploadFileButton);
lv.addHeaderView(layout);
mPhotoAdapter = new SkyDriveListAdapter(this);
setListAdapter(mPhotoAdapter);
LiveSdkSampleApplication app = (LiveSdkSampleApplication) getApplication();
mClient = app.getConnectClient();
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
// if prev folders is empty, send the back button to the TabView activity.
if (mPrevFolderIds.isEmpty()) {
return false;
}
loadFolder(mPrevFolderIds.pop());
return true;
} else {
return super.onKeyDown(keyCode, event);
}
}
@Override
protected Dialog onCreateDialog(final int id, final Bundle bundle) {
Dialog dialog = null;
switch (id) {
case DIALOG_DOWNLOAD_ID: {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Download")
.setMessage("This file will be downloaded to the sdcard.")
.setPositiveButton("OK", new Dialog.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
final ProgressDialog progressDialog =
new ProgressDialog(SkyDriveActivity.this);
progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
progressDialog.setMessage("Downloading...");
progressDialog.setCancelable(true);
progressDialog.show();
String fileId = bundle.getString(JsonKeys.ID);
String name = bundle.getString(JsonKeys.NAME);
File file = new File(Environment.getExternalStorageDirectory(), name);
final LiveDownloadOperation operation =
mClient.downloadAsync(fileId + "/content",
file,
new LiveDownloadOperationListener() {
@Override
public void onDownloadProgress(int totalBytes,
int bytesRemaining,
LiveDownloadOperation operation) {
int percentCompleted =
computePrecentCompleted(totalBytes, bytesRemaining);
progressDialog.setProgress(percentCompleted);
}
@Override
public void onDownloadFailed(LiveOperationException exception,
LiveDownloadOperation operation) {
progressDialog.dismiss();
showToast(exception.getMessage());
}
@Override
public void onDownloadCompleted(LiveDownloadOperation operation) {
progressDialog.dismiss();
showToast("File downloaded.");
}
});
progressDialog.setOnCancelListener(new OnCancelListener() {
@Override
public void onCancel(DialogInterface dialog) {
operation.cancel();
}
});
}
}).setNegativeButton("Cancel", new Dialog.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
});
dialog = builder.create();
break;
}
}
if (dialog != null) {
dialog.setOnDismissListener(new OnDismissListener() {
@Override
public void onDismiss(DialogInterface dialog) {
removeDialog(id);
}
});
}
return dialog;
}
@Override
protected void onStart() {
super.onStart();
loadFolder(HOME_FOLDER);
}
private void loadFolder(String folderId) {
assert folderId != null;
mCurrentFolderId = folderId;
final ProgressDialog progressDialog =
ProgressDialog.show(this, "", "Loading. Please wait...", true);
mClient.getAsync(folderId + "/files", new LiveOperationListener() {
@Override
public void onComplete(LiveOperation operation) {
progressDialog.dismiss();
JSONObject result = operation.getResult();
if (result.has(JsonKeys.ERROR)) {
JSONObject error = result.optJSONObject(JsonKeys.ERROR);
String message = error.optString(JsonKeys.MESSAGE);
String code = error.optString(JsonKeys.CODE);
showToast(code + ": " + message);
return;
}
ArrayList<SkyDriveObject> skyDriveObjs = mPhotoAdapter.getSkyDriveObjs();
skyDriveObjs.clear();
JSONArray data = result.optJSONArray(JsonKeys.DATA);
for (int i = 0; i < data.length(); i++) {
SkyDriveObject skyDriveObj = SkyDriveObject.create(data.optJSONObject(i));
if (skyDriveObj != null) {
skyDriveObjs.add(skyDriveObj);
}
}
mPhotoAdapter.notifyDataSetChanged();
}
@Override
public void onError(LiveOperationException exception, LiveOperation operation) {
progressDialog.dismiss();
showToast(exception.getMessage());
}
});
}
private void showToast(String message) {
Toast.makeText(this, message, Toast.LENGTH_LONG).show();
}
private int computePrecentCompleted(int totalBytes, int bytesRemaining) {
return (int) (((float)(totalBytes - bytesRemaining)) / totalBytes * 100);
}
private ProgressDialog showProgressDialog(String title, String message, boolean indeterminate) {
return ProgressDialog.show(this, title, message, indeterminate);
}
/**
* Extract a photo from SkyDrive and creates a scaled bitmap according to the device resolution, this is needed to
* prevent memory over-allocation that can cause some devices to crash when opening high-resolution pictures
*
* Note: this method should not be used for downloading photos, only for displaying photos on-screen
*
| java | MIT | 7feda438a5492a7544fdad527325b5b05f760cc5 | 2026-01-05T02:42:35.605851Z | true |
rafaeltoledo/android-security | https://github.com/rafaeltoledo/android-security/blob/2ca3680b911bd25663036d48a81df13d6c00e6ef/app/src/main/java/net/rafaeltoledo/security/SecurityApp.java | app/src/main/java/net/rafaeltoledo/security/SecurityApp.java | package net.rafaeltoledo.security;
import android.app.Application;
import android.util.Log;
import com.orhanobut.hawk.Hawk;
import net.sqlcipher.database.SQLiteDatabase;
public class SecurityApp extends Application {
private static final String TAG = SecurityApp.class.getSimpleName();
private static final String PREF_TIMES = "net.rafaeltoledo.security.PREF_TIMES";
@Override
public void onCreate() {
super.onCreate();
Hawk.init(this).build();
SQLiteDatabase.loadLibs(this);
int times = Hawk.get(PREF_TIMES, 0) + 1;
Log.d(TAG, "Psss! Let me tell a secret: you opened this app " + times + " times.");
Hawk.put(PREF_TIMES, times);
}
}
| java | Apache-2.0 | 2ca3680b911bd25663036d48a81df13d6c00e6ef | 2026-01-05T02:42:40.426670Z | false |
rafaeltoledo/android-security | https://github.com/rafaeltoledo/android-security/blob/2ca3680b911bd25663036d48a81df13d6c00e6ef/app/src/main/java/net/rafaeltoledo/security/util/SignatureUtils.java | app/src/main/java/net/rafaeltoledo/security/util/SignatureUtils.java | package net.rafaeltoledo.security.util;
import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.Signature;
import android.util.Base64;
import android.util.Log;
import java.security.MessageDigest;
public class SignatureUtils {
private static final String TAG = SignatureUtils.class.getSimpleName();
private static final String SIGNATURE = "0P333z1O57jHJ87piTMi3W6VuQU=\n";
public static boolean checkSignature(Context context) {
try {
PackageInfo packageInfo = context.getPackageManager()
.getPackageInfo(context.getPackageName(), PackageManager.GET_SIGNATURES);
for (Signature signature : packageInfo.signatures) {
MessageDigest sha = MessageDigest.getInstance("SHA");
sha.update(signature.toByteArray());
final String currentSignature = Base64.encodeToString(sha.digest(), Base64.DEFAULT);
if (SIGNATURE.equals(currentSignature)) {
return true;
}
}
} catch (Exception e) {
Log.e(TAG, "Failed to check signature", e);
}
return false;
}
}
| java | Apache-2.0 | 2ca3680b911bd25663036d48a81df13d6c00e6ef | 2026-01-05T02:42:40.426670Z | false |
rafaeltoledo/android-security | https://github.com/rafaeltoledo/android-security/blob/2ca3680b911bd25663036d48a81df13d6c00e6ef/app/src/main/java/net/rafaeltoledo/security/util/EnvironmentChecker.java | app/src/main/java/net/rafaeltoledo/security/util/EnvironmentChecker.java | package net.rafaeltoledo.security.util;
import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.os.Build;
import android.util.Log;
public class EnvironmentChecker {
private static final String TAG = EnvironmentChecker.class.getSimpleName();
private static String getSystemProperty(String name) throws Exception {
Class systemPropertyClass = Class.forName("android.os.SystemProperties");
return (String) systemPropertyClass.getMethod("get", new Class[]{String.class})
.invoke(systemPropertyClass, name);
}
public static boolean alternativeIsEmulator() {
return Build.FINGERPRINT.startsWith("generic")
|| Build.FINGERPRINT.startsWith("unknown")
|| Build.MODEL.contains("google_sdk")
|| Build.MODEL.contains("Emulator")
|| Build.MODEL.contains("Android SDK built for x86")
|| Build.MANUFACTURER.contains("Genymotion")
|| (Build.BRAND.startsWith("generic") && Build.DEVICE.startsWith("generic"))
|| "google_sdk".equals(Build.PRODUCT)
|| "goldfish".equals(Build.HARDWARE);
}
public static boolean isEmulator() {
try {
boolean goldfish = getSystemProperty("ro.hardware").contains("goldfish");
boolean emu = getSystemProperty("ro.kernel.qemu").length() > 0;
boolean sdk = getSystemProperty("ro.product.model").equals("sdk");
if (emu || goldfish || sdk) {
return true;
}
} catch (Exception e) {
Log.d(TAG, "Failed to check enviroment", e);
}
return false;
}
public static boolean isDebuggable(Context context) {
return (context.getApplicationInfo().flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0;
}
}
| java | Apache-2.0 | 2ca3680b911bd25663036d48a81df13d6c00e6ef | 2026-01-05T02:42:40.426670Z | false |
rafaeltoledo/android-security | https://github.com/rafaeltoledo/android-security/blob/2ca3680b911bd25663036d48a81df13d6c00e6ef/app/src/main/java/net/rafaeltoledo/security/util/InstallationChecker.java | app/src/main/java/net/rafaeltoledo/security/util/InstallationChecker.java | package net.rafaeltoledo.security.util;
import android.content.Context;
public class InstallationChecker {
private static final String GOOGLE_PLAY = "com.android.vending";
private static final String ORIGINAL_PACKAGE = "net.rafaeltoledo.security";
public static boolean verifyInstaller(Context context) {
final String installer = context.getPackageManager()
.getInstallerPackageName(context.getPackageName());
return installer != null && installer.compareTo(GOOGLE_PLAY) == 0;
}
public static boolean checkPackage(Context context) {
return context.getPackageName().compareTo(ORIGINAL_PACKAGE) == 0;
}
}
| java | Apache-2.0 | 2ca3680b911bd25663036d48a81df13d6c00e6ef | 2026-01-05T02:42:40.426670Z | false |
rafaeltoledo/android-security | https://github.com/rafaeltoledo/android-security/blob/2ca3680b911bd25663036d48a81df13d6c00e6ef/app/src/main/java/net/rafaeltoledo/security/ui/MainController.java | app/src/main/java/net/rafaeltoledo/security/ui/MainController.java | package net.rafaeltoledo.security.ui;
public interface MainController {
void requestSafetyNetCheck();
void performOkHttpRequest();
}
| java | Apache-2.0 | 2ca3680b911bd25663036d48a81df13d6c00e6ef | 2026-01-05T02:42:40.426670Z | false |
rafaeltoledo/android-security | https://github.com/rafaeltoledo/android-security/blob/2ca3680b911bd25663036d48a81df13d6c00e6ef/app/src/main/java/net/rafaeltoledo/security/ui/MainActivity.java | app/src/main/java/net/rafaeltoledo/security/ui/MainActivity.java | package net.rafaeltoledo.security.ui;
import android.databinding.DataBindingUtil;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.api.GoogleApiClient;
import com.google.android.gms.safetynet.SafetyNet;
import com.scottyab.rootbeer.RootBeer;
import net.rafaeltoledo.security.R;
import net.rafaeltoledo.security.databinding.ActivityMainBinding;
import net.rafaeltoledo.security.http.HttpClientProvider;
import net.rafaeltoledo.security.http.Tls12SslSocketFactory;
import net.rafaeltoledo.security.util.EnvironmentChecker;
import net.rafaeltoledo.security.util.InstallationChecker;
import net.rafaeltoledo.security.util.SignatureUtils;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.security.GeneralSecurityException;
import java.security.KeyStore;
import java.security.SecureRandom;
import java.util.Collections;
import java.util.Random;
import javax.net.ssl.TrustManager;
import javax.net.ssl.TrustManagerFactory;
import javax.net.ssl.X509TrustManager;
import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.ConnectionSpec;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
import okhttp3.TlsVersion;
public class MainActivity extends AppCompatActivity implements GoogleApiClient.OnConnectionFailedListener, MainController {
private static final String TAG = MainActivity.class.getSimpleName();
private GoogleApiClient client;
private final Random random = new SecureRandom();
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ActivityMainBinding binding = DataBindingUtil.setContentView(this, R.layout.activity_main);
client = new GoogleApiClient.Builder(this)
.addApi(SafetyNet.API)
.enableAutoManage(this, this)
.build();
binding.root.setText(new RootBeer(this).isRooted() ? "Device is rooted" : "Device isn't rooted");
binding.installation.setText(InstallationChecker.verifyInstaller(this) ? "Installed from Play Store" : "Installed from unknown source");
binding.enviroment.setText((EnvironmentChecker.alternativeIsEmulator() ? "Running on an emulator" : "Running on a device")
+ (EnvironmentChecker.isDebuggable(this) ? " with debugger" : ""));
binding.tampering.setText((InstallationChecker.checkPackage(this) ?
"The package is consistent" : "The package was modified")
+ (SignatureUtils.checkSignature(this) ? " and the signature is ok" : " and the signature was changed!"));
binding.setController(this);
}
@Override
public void onConnectionFailed(@NonNull ConnectionResult connectionResult) {
Log.e(TAG, "Failed to connect to Google Client");
}
@Override
public void requestSafetyNetCheck() {
byte[] nonce = getRequestNonce();
SafetyNet.SafetyNetApi.attest(client, nonce)
.setResultCallback(result -> {
if (result.getStatus().isSuccess()) {
showSafetyNetResult(result.getJwsResult());
} else {
Log.e(TAG, "Error on SafetyNet request - Code ("
+ result.getStatus().getStatusCode() + "): " +
"" + result.getStatus().getStatusMessage());
}
});
}
@Override
public void performOkHttpRequest() {
OkHttpClient client = HttpClientProvider.getClient();
Request request = new Request.Builder()
.url("https://github.com/robots.txt")
.build();
client.newCall(request).enqueue(new Callback() {
@Override
public void onFailure(Call call, IOException e) {
Log.e(TAG, "Failed to perform request", e);
}
@Override
public void onResponse(Call call, Response response) throws IOException {
Log.d(TAG, response.body().string());
}
});
}
private void showSafetyNetResult(String result) {
/*
Forward this result to your server together with the nonce for verification.
You can also parse the JwsResult locally to confirm that the API
returned a response by checking for an 'error' field first and before
retrying the request with an exponential backoff.
NOTE: Do NOT rely on a local, client-side only check for security, you
must verify the response on a remote server!
*/
Log.d(TAG, "Success! SafetyNet result:\n" + result + "\n");
}
// Ideally, the Nonce should be generated in your server
private byte[] getRequestNonce() {
String nonceData = "SafetyNet Sample: " + System.currentTimeMillis();
ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
byte[] bytes = new byte[24];
random.nextBytes(bytes);
try {
byteStream.write(bytes);
byteStream.write(nonceData.getBytes());
} catch (IOException e) {
Log.e(TAG, "Failed to generate nonce", e);
return null;
}
return byteStream.toByteArray();
}
}
| java | Apache-2.0 | 2ca3680b911bd25663036d48a81df13d6c00e6ef | 2026-01-05T02:42:40.426670Z | false |
rafaeltoledo/android-security | https://github.com/rafaeltoledo/android-security/blob/2ca3680b911bd25663036d48a81df13d6c00e6ef/app/src/main/java/net/rafaeltoledo/security/http/Tls12SslSocketFactory.java | app/src/main/java/net/rafaeltoledo/security/http/Tls12SslSocketFactory.java | package net.rafaeltoledo.security.http;
import java.io.IOException;
import java.net.InetAddress;
import java.net.Socket;
import javax.net.ssl.SSLSocket;
import javax.net.ssl.SSLSocketFactory;
public class Tls12SslSocketFactory extends SSLSocketFactory {
private final String tag = "TLSv1.2";
private SSLSocketFactory delegate;
public Tls12SslSocketFactory() {
delegate = (SSLSocketFactory) SSLSocketFactory.getDefault();
}
@Override
public String[] getDefaultCipherSuites() {
return delegate.getDefaultCipherSuites();
}
@Override
public String[] getSupportedCipherSuites() {
return delegate.getSupportedCipherSuites();
}
@Override
public Socket createSocket(Socket socket, String host, int port, boolean autoClose) throws IOException {
SSLSocket s = (SSLSocket) delegate.createSocket(socket, host, port, autoClose);
s.setEnabledProtocols(new String[]{tag});
return s;
}
@Override
public Socket createSocket(String host, int port) throws IOException {
SSLSocket s = (SSLSocket) delegate.createSocket(host, port);
s.setEnabledProtocols(new String[]{tag});
return s;
}
@Override
public Socket createSocket(String host, int port, InetAddress localHost, int localPort) throws IOException {
SSLSocket s = (SSLSocket) delegate.createSocket(host, port, localHost, localPort);
s.setEnabledProtocols(new String[]{tag});
return s;
}
@Override
public Socket createSocket(InetAddress host, int port) throws IOException {
SSLSocket s = (SSLSocket) delegate.createSocket(host, port);
s.setEnabledProtocols(new String[]{tag});
return s;
}
@Override
public Socket createSocket(InetAddress address, int port, InetAddress localAddress, int localPort) throws IOException {
SSLSocket s = (SSLSocket) delegate.createSocket(address, port, localAddress, localPort);
s.setEnabledProtocols(new String[]{tag});
return s;
}
}
| java | Apache-2.0 | 2ca3680b911bd25663036d48a81df13d6c00e6ef | 2026-01-05T02:42:40.426670Z | false |
rafaeltoledo/android-security | https://github.com/rafaeltoledo/android-security/blob/2ca3680b911bd25663036d48a81df13d6c00e6ef/app/src/main/java/net/rafaeltoledo/security/http/HttpClientProvider.java | app/src/main/java/net/rafaeltoledo/security/http/HttpClientProvider.java | package net.rafaeltoledo.security.http;
import android.util.Log;
import java.security.GeneralSecurityException;
import java.security.KeyStore;
import java.util.Collections;
import javax.net.ssl.TrustManager;
import javax.net.ssl.TrustManagerFactory;
import javax.net.ssl.X509TrustManager;
import okhttp3.CertificatePinner;
import okhttp3.ConnectionSpec;
import okhttp3.OkHttpClient;
import okhttp3.TlsVersion;
public class HttpClientProvider {
private static final String TAG = HttpClientProvider.class.getSimpleName();
private static final OkHttpClient CLIENT = init();
private static OkHttpClient init() {
ConnectionSpec.Builder spec = new ConnectionSpec.Builder(ConnectionSpec.MODERN_TLS)
.tlsVersions(TlsVersion.TLS_1_2);
OkHttpClient.Builder client = new OkHttpClient.Builder()
.connectionSpecs(Collections.singletonList(spec.build()));
// This setup is necessary because API 16-18 support TLS 1.2,
// but use 1.0 as default.
setupTls(client);
setupPinning(client);
return client.build();
}
private static void setupPinning(OkHttpClient.Builder client) {
client.certificatePinner(new CertificatePinner.Builder()
.add("github.com", "sha256/pL1+qb9HTMRZJmuC/bB/ZI9d302BYrrqiVuRyW+DGrU=")
.add("github.com", "sha256/RRM1dGqnDFsCJXBTHky16vi1obOlCgFFn/yOhI/y+ho=")
.add("github.com", "sha256/WoiWRyIOVNa9ihaBciRSC7XHjliYS9VwUGOIud4PB18=")
.build());
}
private static void setupTls(OkHttpClient.Builder builder) {
try {
TrustManagerFactory factory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
factory.init((KeyStore) null);
for (TrustManager trustManager : factory.getTrustManagers()) {
if (trustManager instanceof X509TrustManager) {
builder.sslSocketFactory(new Tls12SslSocketFactory(), (X509TrustManager) trustManager);
break;
}
}
} catch (GeneralSecurityException e) {
Log.e(TAG, "Failed to initialize SSL Socket Factory", e);
}
}
public static OkHttpClient getClient() {
return CLIENT;
}
}
| java | Apache-2.0 | 2ca3680b911bd25663036d48a81df13d6c00e6ef | 2026-01-05T02:42:40.426670Z | false |
ansitech/weixin4j | https://github.com/ansitech/weixin4j/blob/f5e7a60e0c377f7420866b229a9ac79e687d5ac5/src/main/java/org/weixin4j/Configuration.java | src/main/java/org/weixin4j/Configuration.java | /*
* 微信公众平台(JAVA) SDK
*
* Copyright (c) 2014, Ansitech Network Technology Co.,Ltd All rights reserved.
*
* http://www.weixin4j.org/
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.weixin4j;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.security.AccessControlException;
import java.util.Properties;
/**
* 微信平台调用基础配置
*
* <p>
* 如果存在weixin4j.properties,则加载属性文件中配置的参数</p>
*
* @author yangqisheng
* @since 0.0.1
*/
public class Configuration {
private static Properties defaultProperty;
static {
init();
}
static void init() {
//初始化默认配置
defaultProperty = new Properties();
defaultProperty.setProperty("weixin4j.debug", "true");
defaultProperty.setProperty("weixin4j.token", "weixin4j");
defaultProperty.setProperty("weixin4j.http.connectionTimeout", "20000");
defaultProperty.setProperty("weixin4j.http.readTimeout", "120000");
defaultProperty.setProperty("weixin4j.http.retryCount", "3");
//读取自定义配置
String t4jProps = "weixin4j.properties";
boolean loaded = loadProperties(defaultProperty, "." + File.separatorChar + t4jProps)
|| loadProperties(defaultProperty, Configuration.class.getResourceAsStream("/WEB-INF/" + t4jProps))
|| loadProperties(defaultProperty, Configuration.class.getClassLoader().getResourceAsStream(t4jProps));
if (!loaded) {
System.out.println("weixin4j:没有加载到weixin4j.properties属性文件!");
}
}
/**
* 加载属性文件
*
* @param props 属性文件实例
* @param path 属性文件路径
* @return 是否加载成功
*/
private static boolean loadProperties(Properties props, String path) {
try {
File file = new File(path);
if (file.exists() && file.isFile()) {
props.load(new FileInputStream(file));
return true;
}
} catch (IOException ignore) {
//异常忽略
ignore.printStackTrace();
}
return false;
}
/**
* 加载属性文件
*
* @param props 属性文件实例
* @param is 属性文件流
* @return 是否加载成功
*/
private static boolean loadProperties(Properties props, InputStream is) {
try {
if (is != null) {
props.load(is);
return true;
}
} catch (IOException ignore) {
//异常忽略
ignore.printStackTrace();
}
return false;
}
/**
* 获取开发者第三方用户唯一凭证
*
* @return 第三方用户唯一凭证
*/
public static String getOAuthAppId() {
return getProperty("weixin4j.oauth.appid");
}
/**
* 获取开发者第三方用户唯一凭证
*
* @param appid 默认第三方用户唯一凭证
* @return 第三方用户唯一凭证
*/
public static String getOAuthAppId(String appid) {
return getProperty("weixin4j.oauth.appid", appid);
}
/**
* 获取开发者第三方用户唯一凭证密钥
*
* @return 第三方用户唯一凭证密钥
*/
public static String getOAuthSecret() {
return getProperty("weixin4j.oauth.secret");
}
/**
* 获取开发者第三方用户唯一凭证密钥
*
* @param secret 默认第三方用户唯一凭证密钥
* @return 第三方用户唯一凭证密钥
*/
public static String getOAuthSecret(String secret) {
return getProperty("weixin4j.oauth.secret", secret);
}
/**
* 获取 连接超时时间
*
* @return 连接超时时间
*/
public static int getConnectionTimeout() {
return getIntProperty("weixin4j.http.connectionTimeout");
}
/**
* 获取 连接超时时间
*
* @param connectionTimeout 默认连接超时时间
* @return 连接超时时间
*/
public static int getConnectionTimeout(int connectionTimeout) {
return getIntProperty("weixin4j.http.connectionTimeout", connectionTimeout);
}
/**
* 获取 请求超时时间
*
* @return 请求超时时间
*/
public static int getReadTimeout() {
return getIntProperty("weixin4j.http.readTimeout");
}
/**
* 获取 请求超时时间
*
* @param readTimeout 默认请求超时时间
* @return 请求超时时间
*/
public static int getReadTimeout(int readTimeout) {
return getIntProperty("weixin4j.http.readTimeout", readTimeout);
}
/**
* 获取 是否为调试模式
*
* @return 是否为调试模式
*/
public static boolean isDebug() {
return getBoolean("weixin4j.debug");
}
public static boolean getBoolean(String name) {
String value = getProperty(name);
return Boolean.valueOf(value);
}
public static int getIntProperty(String name) {
String value = getProperty(name);
try {
return Integer.parseInt(value);
} catch (NumberFormatException nfe) {
return -1;
}
}
public static int getIntProperty(String name, int fallbackValue) {
String value = getProperty(name, String.valueOf(fallbackValue));
try {
return Integer.parseInt(value);
} catch (NumberFormatException nfe) {
return -1;
}
}
/**
* 获取属性值
*
* @param name 属性名称
* @return 属性值
*/
public static String getProperty(String name) {
return getProperty(name, null);
}
/**
* 获取属性值
*
* @param name 属性名
* @param fallbackValue 默认返回值
* @return 属性值
*/
public static String getProperty(String name, String fallbackValue) {
String value;
try {
//从全局系统获取
value = System.getProperty(name, null);
if (null == value) {
//先从系统配置文件获取
value = defaultProperty.getProperty(name, fallbackValue);
}
} catch (AccessControlException ace) {
// Unsigned applet cannot access System properties
value = fallbackValue;
}
return value;
}
}
| java | Apache-2.0 | f5e7a60e0c377f7420866b229a9ac79e687d5ac5 | 2026-01-05T02:42:41.143783Z | false |
ansitech/weixin4j | https://github.com/ansitech/weixin4j/blob/f5e7a60e0c377f7420866b229a9ac79e687d5ac5/src/main/java/org/weixin4j/Weixin.java | src/main/java/org/weixin4j/Weixin.java | /*
* 微信公众平台(JAVA) SDK
*
* Copyright (c) 2014, Ansitech Network Technology Co.,Ltd All rights reserved.
*
* http://www.weixin4j.org/
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.weixin4j;
import org.weixin4j.model.base.Token;
import java.util.HashMap;
import java.util.Map;
import org.weixin4j.component.AbstractComponent;
import org.weixin4j.component.BaseComponent;
import org.weixin4j.component.FileComponent;
import org.weixin4j.component.GroupsComponent;
import org.weixin4j.component.JsSdkComponent;
import org.weixin4j.component.MaterialComponent;
import org.weixin4j.component.MediaComponent;
import org.weixin4j.component.MenuComponent;
import org.weixin4j.component.MessageComponent;
import org.weixin4j.component.PayComponent;
import org.weixin4j.component.QrcodeComponent;
import org.weixin4j.component.RedpackComponent;
import org.weixin4j.component.SnsComponent;
import org.weixin4j.component.TagsComponent;
import org.weixin4j.component.UserComponent;
import org.weixin4j.loader.DefaultTokenLoader;
import org.weixin4j.loader.DefaultTicketLoader;
import org.weixin4j.loader.ITokenLoader;
import org.weixin4j.loader.ITicketLoader;
import org.weixin4j.model.js.Ticket;
import org.weixin4j.model.js.TicketType;
/**
* 微信平台基础支持对象
*
* @author yangqisheng
* @since 0.0.1
*/
public class Weixin extends WeixinSupport implements java.io.Serializable {
/**
* 同步锁
*/
private final static byte[] LOCK = new byte[0];
/**
* 公众号开发者ID
*/
private final String appId;
/**
* 公众号开发者密钥
*/
private final String secret;
/**
* 公众号配置
*
* @since 0.1.3
*/
private final WeixinConfig weixinConfig;
/**
* 微信支付配置
*
* @since 0.1.3
*/
private final WeixinPayConfig weixinPayConfig;
/**
* AccessToken加载器
*/
protected ITokenLoader tokenLoader = new DefaultTokenLoader();
/**
* Ticket加载器
*/
protected ITicketLoader ticketLoader = new DefaultTicketLoader();
/**
* 新增组件
*/
private final Map<String, AbstractComponent> components = new HashMap<String, AbstractComponent>();
/**
* 单公众号,并且只支持一个公众号方式
*/
public Weixin() {
this(Configuration.getOAuthAppId(), Configuration.getOAuthSecret());
}
/**
* 多公众号,同一个环境中使用方式
*
* @param appId 公众号开发者AppId
* @param secret 公众号开发者秘钥
*/
public Weixin(String appId, String secret) {
this.appId = appId;
this.secret = secret;
weixinConfig = new WeixinConfig();
weixinConfig.setAppid(appId);
weixinConfig.setSecret(secret);
weixinConfig.setOriginalid(Configuration.getProperty("weixin4j.oauth.originalid"));
weixinConfig.setEncodingtype(Configuration.getIntProperty("weixin4j.oauth.encodingtype"));
weixinConfig.setEncodingaeskey(Configuration.getProperty("weixin4j.oauth.encodingaeskey"));
weixinConfig.setOauthUrl(Configuration.getProperty("weixin4j.oauth.url"));
weixinConfig.setApiDomain(Configuration.getProperty("weixin4j.api.domain"));
weixinPayConfig = new WeixinPayConfig();
weixinPayConfig.setAppId(appId);
weixinPayConfig.setPartnerId(Configuration.getProperty("weixin4j.pay.partner.id"));
weixinPayConfig.setPartnerKey(Configuration.getProperty("weixin4j.pay.partner.key"));
weixinPayConfig.setNotifyUrl(Configuration.getProperty("weixin4j.pay.notify_url"));
weixinPayConfig.setMchId(Configuration.getProperty("weixin4j.pay.mch.id", Configuration.getProperty("weixin4j.pay.partner.id")));
weixinPayConfig.setMchKey(Configuration.getProperty("weixin4j.pay.mch.key", Configuration.getProperty("weixin4j.pay.partner.key")));
weixinPayConfig.setCertPath(Configuration.getProperty("weixin4j.http.cert.path"));
weixinPayConfig.setCertSecret(Configuration.getProperty("weixin4j.http.cert.secret"));
if (null == this.weixinPayConfig.getAppId() || "".equals(this.weixinPayConfig.getAppId())) {
this.weixinPayConfig.setAppId(weixinConfig.getAppid());
}
if (null == this.weixinPayConfig.getMchId() || "".equals(this.weixinPayConfig.getMchId())) {
this.weixinPayConfig.setMchId(weixinPayConfig.getPartnerId());
}
if (null == this.weixinPayConfig.getMchKey() || "".equals(this.weixinPayConfig.getMchKey())) {
this.weixinPayConfig.setMchKey(weixinPayConfig.getPartnerKey());
}
//兼容证书密钥未设置
if (null == this.weixinPayConfig.getCertSecret() || "".equals(this.weixinPayConfig.getCertSecret())) {
weixinPayConfig.setCertSecret(weixinPayConfig.getMchId());
}
}
/**
* 外部配置注入方式,更灵活
*
* @param weixinConfig 微信公众号配置
* @since 0.1.3
*/
public Weixin(WeixinConfig weixinConfig) {
this(weixinConfig, null);
}
/**
* 外部配置注入方式(带微信支付),更灵活
*
* @param weixinPayConfig 微信支付配置
* @since 0.1.3
*/
public Weixin(WeixinPayConfig weixinPayConfig) {
this.appId = Configuration.getOAuthAppId();
this.secret = Configuration.getOAuthSecret();
weixinConfig = new WeixinConfig();
weixinConfig.setAppid(Configuration.getOAuthAppId());
weixinConfig.setSecret(Configuration.getOAuthSecret());
weixinConfig.setOriginalid(Configuration.getProperty("weixin4j.oauth.originalid"));
weixinConfig.setEncodingtype(Configuration.getIntProperty("weixin4j.oauth.encodingtype"));
weixinConfig.setEncodingaeskey(Configuration.getProperty("weixin4j.oauth.encodingaeskey"));
weixinConfig.setOauthUrl(Configuration.getProperty("weixin4j.oauth.url"));
weixinConfig.setApiDomain(Configuration.getProperty("weixin4j.api.domain"));
this.weixinPayConfig = weixinPayConfig;
//兼容0.1.6以前的版本
if (this.weixinPayConfig != null) {
if (null == this.weixinPayConfig.getAppId() || "".equals(this.weixinPayConfig.getAppId())) {
this.weixinPayConfig.setAppId(weixinConfig.getAppid());
}
if (null == this.weixinPayConfig.getMchId() || "".equals(this.weixinPayConfig.getMchId())) {
this.weixinPayConfig.setMchId(weixinPayConfig.getPartnerId());
}
if (null == this.weixinPayConfig.getMchKey() || "".equals(this.weixinPayConfig.getMchKey())) {
this.weixinPayConfig.setMchKey(weixinPayConfig.getPartnerKey());
}
//兼容证书密钥未设置
if (null == this.weixinPayConfig.getCertSecret() || "".equals(this.weixinPayConfig.getCertSecret())) {
weixinPayConfig.setCertSecret(weixinPayConfig.getMchId());
}
}
}
/**
* 外部配置注入方式(带微信支付),更灵活
*
* @param weixinConfig 微信公众号配置
* @param weixinPayConfig 微信支付配置
* @since 0.1.3
*/
public Weixin(WeixinConfig weixinConfig, WeixinPayConfig weixinPayConfig) {
this.appId = weixinConfig.getAppid();
this.secret = weixinConfig.getSecret();
this.weixinConfig = weixinConfig;
this.weixinPayConfig = weixinPayConfig;
//兼容0.1.6以前的版本
if (this.weixinPayConfig != null) {
if (null == this.weixinPayConfig.getAppId() || "".equals(this.weixinPayConfig.getAppId())) {
this.weixinPayConfig.setAppId(weixinConfig.getAppid());
}
if (null == this.weixinPayConfig.getMchId() || "".equals(this.weixinPayConfig.getMchId())) {
this.weixinPayConfig.setMchId(weixinPayConfig.getPartnerId());
}
if (null == this.weixinPayConfig.getMchKey() || "".equals(this.weixinPayConfig.getMchKey())) {
this.weixinPayConfig.setMchKey(weixinPayConfig.getPartnerKey());
}
//兼容证书密钥未设置
if (null == this.weixinPayConfig.getCertSecret() || "".equals(this.weixinPayConfig.getCertSecret())) {
weixinPayConfig.setCertSecret(weixinPayConfig.getMchId());
}
}
}
public String getAppId() {
return appId;
}
public String getSecret() {
return secret;
}
/**
* 获取Token对象
*
* @return Token对象
* @throws org.weixin4j.WeixinException 微信操作异常
* @since 0.1.0
*/
public Token getToken() throws WeixinException {
Token token = tokenLoader.get();
if (token == null) {
synchronized (LOCK) {
token = tokenLoader.get();
if (token == null) {
token = base().token();
tokenLoader.refresh(token);
}
}
}
return token;
}
/**
* 获取jsapi开发ticket
*
* @return jsapi_ticket
* @throws org.weixin4j.WeixinException 微信操作异常
*/
public Ticket getJsApiTicket() throws WeixinException {
Ticket ticket = ticketLoader.get(TicketType.JSAPI);
if (ticket == null) {
synchronized (LOCK) {
ticket = ticketLoader.get(TicketType.JSAPI);
if (ticket == null) {
ticket = js().getJsApiTicket();
ticketLoader.refresh(ticket);
}
}
}
return ticket;
}
public BaseComponent base() {
String key = BaseComponent.class.getName();
if (components.containsKey(key)) {
return (BaseComponent) components.get(key);
}
BaseComponent component = new BaseComponent(this);
components.put(key, component);
return component;
}
public JsSdkComponent js() {
String key = JsSdkComponent.class.getName();
if (components.containsKey(key)) {
return (JsSdkComponent) components.get(key);
}
JsSdkComponent component = new JsSdkComponent(this);
components.put(key, component);
return component;
}
public UserComponent user() {
String key = UserComponent.class.getName();
if (components.containsKey(key)) {
return (UserComponent) components.get(key);
}
UserComponent component = new UserComponent(this);
components.put(key, component);
return component;
}
public SnsComponent sns() {
String key = SnsComponent.class.getName();
if (components.containsKey(key)) {
return (SnsComponent) components.get(key);
}
SnsComponent component = new SnsComponent(this);
components.put(key, component);
return component;
}
public SnsComponent sns(String authorize_url) {
String key = SnsComponent.class.getName();
if (components.containsKey(key)) {
return (SnsComponent) components.get(key);
}
SnsComponent component = new SnsComponent(this, authorize_url);
components.put(key, component);
return component;
}
public TagsComponent tags() {
String key = TagsComponent.class.getName();
if (components.containsKey(key)) {
return (TagsComponent) components.get(key);
}
TagsComponent component = new TagsComponent(this);
components.put(key, component);
return component;
}
public GroupsComponent groups() {
String key = GroupsComponent.class.getName();
if (components.containsKey(key)) {
return (GroupsComponent) components.get(key);
}
GroupsComponent component = new GroupsComponent(this);
components.put(key, component);
return component;
}
public PayComponent pay() {
String key = PayComponent.class.getName();
if (components.containsKey(key)) {
return (PayComponent) components.get(key);
}
PayComponent component = new PayComponent(this);
components.put(key, component);
return component;
}
public RedpackComponent redpack() {
String key = RedpackComponent.class.getName();
if (components.containsKey(key)) {
return (RedpackComponent) components.get(key);
}
RedpackComponent component = new RedpackComponent(this);
components.put(key, component);
return component;
}
public MessageComponent message() {
String key = MessageComponent.class.getName();
if (components.containsKey(key)) {
return (MessageComponent) components.get(key);
}
MessageComponent component = new MessageComponent(this);
components.put(key, component);
return component;
}
public MenuComponent menu() {
String key = MenuComponent.class.getName();
if (components.containsKey(key)) {
return (MenuComponent) components.get(key);
}
MenuComponent component = new MenuComponent(this);
components.put(key, component);
return component;
}
@Deprecated
public MediaComponent media() {
String key = MediaComponent.class.getName();
if (components.containsKey(key)) {
return (MediaComponent) components.get(key);
}
MediaComponent component = new MediaComponent(this);
components.put(key, component);
return component;
}
@Deprecated
public FileComponent file() {
String key = FileComponent.class.getName();
if (components.containsKey(key)) {
return (FileComponent) components.get(key);
}
FileComponent component = new FileComponent(this);
components.put(key, component);
return component;
}
public MaterialComponent material() {
String key = MaterialComponent.class.getName();
if (components.containsKey(key)) {
return (MaterialComponent) components.get(key);
}
MaterialComponent component = new MaterialComponent(this);
components.put(key, component);
return component;
}
public QrcodeComponent qrcode() {
String key = QrcodeComponent.class.getName();
if (components.containsKey(key)) {
return (QrcodeComponent) components.get(key);
}
QrcodeComponent component = new QrcodeComponent(this);
components.put(key, component);
return component;
}
/**
* 获取微信配置对象
*
* @return 微信配置对象
* @since 0.1.3
*/
public WeixinConfig getWeixinConfig() {
return weixinConfig;
}
/**
* 获取微信支付配置对象
*
* @return 微信支付配置对象
* @since 0.1.3
*/
public WeixinPayConfig getWeixinPayConfig() {
return weixinPayConfig;
}
}
| java | Apache-2.0 | f5e7a60e0c377f7420866b229a9ac79e687d5ac5 | 2026-01-05T02:42:41.143783Z | false |
ansitech/weixin4j | https://github.com/ansitech/weixin4j/blob/f5e7a60e0c377f7420866b229a9ac79e687d5ac5/src/main/java/org/weixin4j/WeixinConfig.java | src/main/java/org/weixin4j/WeixinConfig.java | /*
* 微信公众平台(JAVA) SDK
*
* Copyright (c) 2014, Ansitech Network Technology Co.,Ltd All rights reserved.
*
* http://www.weixin4j.org/
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.weixin4j;
/**
* 微信配置
*
* @author yangqisheng
* @since 0.1.3
*/
public class WeixinConfig {
/**
* 开发者第三方用户唯一凭证
*/
private String appid;
/**
* 开发者第三方用户唯一凭证密钥
*/
private String secret;
/**
* 公众号原始ID
*/
private String originalid;
/**
* 消息加密方式 0:明文模式(默认), 1:兼容模式, 2:安全模式(推荐)
*/
private int encodingtype = 0;
/**
* 消息加密密钥(43位字符组成A-Za-z0-9)
*/
private String encodingaeskey;
/**
* 网页安全授权URL
*/
private String oauthUrl;
/**
* 公众平台接口域名
*/
private String apiDomain = "api.weixin.qq.com";
public String getAppid() {
return appid;
}
public void setAppid(String appid) {
this.appid = appid;
}
public String getSecret() {
return secret;
}
public void setSecret(String secret) {
this.secret = secret;
}
public String getOriginalid() {
return originalid;
}
public void setOriginalid(String originalid) {
this.originalid = originalid;
}
public int getEncodingtype() {
return encodingtype;
}
public void setEncodingtype(int encodingtype) {
this.encodingtype = encodingtype;
}
public String getEncodingaeskey() {
return encodingaeskey;
}
public void setEncodingaeskey(String encodingaeskey) {
this.encodingaeskey = encodingaeskey;
}
public String getOauthUrl() {
return oauthUrl;
}
public void setOauthUrl(String oauthUrl) {
this.oauthUrl = oauthUrl;
}
public String getApiDomain() {
return apiDomain;
}
public void setApiDomain(String apiDomain) {
this.apiDomain = apiDomain;
}
}
| java | Apache-2.0 | f5e7a60e0c377f7420866b229a9ac79e687d5ac5 | 2026-01-05T02:42:41.143783Z | false |
ansitech/weixin4j | https://github.com/ansitech/weixin4j/blob/f5e7a60e0c377f7420866b229a9ac79e687d5ac5/src/main/java/org/weixin4j/WeixinException.java | src/main/java/org/weixin4j/WeixinException.java | /*
* 微信公众平台(JAVA) SDK
*
* Copyright (c) 2014, Ansitech Network Technology Co.,Ltd All rights reserved.
*
* http://www.weixin4j.org/
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.weixin4j;
/**
*
* 微信操作全局异常
*
* @author yangqisheng
* @since 0.0.1
*/
public class WeixinException extends Exception {
public WeixinException(String msg) {
super(msg);
}
public WeixinException(Exception cause) {
super(cause);
}
public WeixinException(String msg, Exception cause) {
super(msg, cause);
}
}
| java | Apache-2.0 | f5e7a60e0c377f7420866b229a9ac79e687d5ac5 | 2026-01-05T02:42:41.143783Z | false |
ansitech/weixin4j | https://github.com/ansitech/weixin4j/blob/f5e7a60e0c377f7420866b229a9ac79e687d5ac5/src/main/java/org/weixin4j/WeixinBuilder.java | src/main/java/org/weixin4j/WeixinBuilder.java | /*
* 微信公众平台(JAVA) SDK
*
* Copyright (c) 2014, Ansitech Network Technology Co.,Ltd All rights reserved.
*
* http://www.weixin4j.org/
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.weixin4j;
import org.weixin4j.factory.WeixinFactory;
import org.weixin4j.factory.defaults.DefaultWeixinFactory;
import org.weixin4j.loader.ITicketLoader;
import org.weixin4j.loader.ITokenLoader;
/**
* 微信对象构建器
*
* @author yangqisheng
* @since 0.1.0
*/
public final class WeixinBuilder {
private Weixin weixin;
private ITokenLoader tokenLoader;
private ITicketLoader ticketLoader;
/**
* 获取一个新的微信构建器
*
* @return 微信构造器
*/
public static WeixinBuilder newInstance() {
WeixinBuilder builder = new WeixinBuilder();
builder.weixin = new Weixin();
return builder;
}
/**
* 获取一个新的微信构建器
*
* @param appId 微信开发者appId
* @param secret 微信开发者secret
* @return 微信构造器
*/
public static WeixinBuilder newInstance(String appId, String secret) {
WeixinBuilder builder = new WeixinBuilder();
builder.weixin = new Weixin(appId, secret);
return builder;
}
/**
* 外部自定义微信公众号配置
*
* @param weixinConfig 微信公众号配置对象
* @return 自身引用对象
* @since 0.1.3
*/
public static WeixinBuilder newInstance(WeixinConfig weixinConfig) {
WeixinBuilder builder = new WeixinBuilder();
builder.weixin = new Weixin(weixinConfig);
return builder;
}
/**
* 外部自定义微信支付配置
*
* @param weixinPayConfig 微信支付配置对象
* @return 自身引用对象
* @since 0.1.3
*/
public static WeixinBuilder newInstance(WeixinPayConfig weixinPayConfig) {
WeixinBuilder builder = new WeixinBuilder();
builder.weixin = new Weixin(weixinPayConfig);
return builder;
}
/**
* 外部自定义微信支付配置
*
* @param weixinConfig 微信公众号配置对象
* @param weixinPayConfig 微信支付配置对象
* @return 自身引用对象
* @since 0.1.3
*/
public static WeixinBuilder newInstance(WeixinConfig weixinConfig, WeixinPayConfig weixinPayConfig) {
WeixinBuilder builder = new WeixinBuilder();
builder.weixin = new Weixin(weixinConfig, weixinPayConfig);
return builder;
}
/**
* 配置access_token加载器
*
* @param tokenLoader token加载器
* @return return this
*/
public WeixinBuilder setTokenLoader(ITokenLoader tokenLoader) {
if (tokenLoader == null) {
throw new IllegalStateException("tokenLoader can't be null");
}
this.tokenLoader = tokenLoader;
return this;
}
/**
* 配置ticket加载器
*
* @param ticketLoader ticket加载器
* @return return this
*/
public WeixinBuilder setTicketLoader(ITicketLoader ticketLoader) {
if (ticketLoader == null) {
throw new IllegalStateException("ticketLoader can't be null");
}
this.ticketLoader = ticketLoader;
return this;
}
/**
* 返回最终配置好的Weixin对象
*
* @return 微信对象
*/
public Weixin build() {
if (tokenLoader != null) {
weixin.tokenLoader = this.tokenLoader;
}
if (this.ticketLoader != null) {
weixin.ticketLoader = this.ticketLoader;
}
return weixin;
}
/**
* 返回微信工厂对象
*
* @return 微信工厂对象
* @since 0.1.3
*/
public WeixinFactory buildWeixinFactory() {
DefaultWeixinFactory weixinFactory = new DefaultWeixinFactory();
weixinFactory.setWeixin(build());
return weixinFactory;
}
}
| java | Apache-2.0 | f5e7a60e0c377f7420866b229a9ac79e687d5ac5 | 2026-01-05T02:42:41.143783Z | false |
ansitech/weixin4j | https://github.com/ansitech/weixin4j/blob/f5e7a60e0c377f7420866b229a9ac79e687d5ac5/src/main/java/org/weixin4j/WeixinPayConfig.java | src/main/java/org/weixin4j/WeixinPayConfig.java | /*
* 微信公众平台(JAVA) SDK
*
* Copyright (c) 2014, Ansitech Network Technology Co.,Ltd All rights reserved.
*
* http://www.weixin4j.org/
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.weixin4j;
/**
* 微信支付配置
*
* @author yangqisheng
* @since 0.1.3
*/
public class WeixinPayConfig {
/**
* 微信支付_商户ID
*/
@Deprecated
private String partnerId;
/**
* 微信支付_商户密钥
*/
@Deprecated
private String partnerKey;
/**
* 微信支付_通知URL
*/
@Deprecated
private String notifyUrl;
/**
* 开发者第三方用户唯一凭证
*/
private String appId;
/**
* 商户号
*
* @since 0.1.6
*/
private String mchId;
/**
* Api密钥
*/
private String mchKey;
/**
* 证书路径
*/
private String certPath;
/**
* 证书密钥,证书密码默认为您的商户号
*/
private String certSecret;
/**
* 商户号,官方已改名,请调用getMchId()方法
*
* @return 商户号
* @since 0.1.3
* @deprecated
*/
@Deprecated
public String getPartnerId() {
return partnerId;
}
@Deprecated
public void setPartnerId(String partnerId) {
this.partnerId = partnerId;
}
/**
* 支付密钥,官方已改名,请调用getMchKey()方法
*
* <p>
* 账户设置--API安全--密钥设置</p>
*
* @return 支付密钥
* @since 0.1.3
* @deprecated
*/
@Deprecated
public String getPartnerKey() {
return partnerKey;
}
@Deprecated
public void setPartnerKey(String partnerKey) {
this.partnerKey = partnerKey;
}
@Deprecated
public String getNotifyUrl() {
return notifyUrl;
}
@Deprecated
public void setNotifyUrl(String notifyUrl) {
this.notifyUrl = notifyUrl;
}
public String getAppId() {
return appId;
}
public void setAppId(String appId) {
this.appId = appId;
}
public String getMchId() {
return mchId;
}
public void setMchId(String mchId) {
this.mchId = mchId;
}
public String getMchKey() {
return mchKey;
}
public void setMchKey(String mchKey) {
this.mchKey = mchKey;
}
public String getCertPath() {
return certPath;
}
public void setCertPath(String certPath) {
this.certPath = certPath;
}
public String getCertSecret() {
return certSecret;
}
public void setCertSecret(String certSecret) {
this.certSecret = certSecret;
}
}
| java | Apache-2.0 | f5e7a60e0c377f7420866b229a9ac79e687d5ac5 | 2026-01-05T02:42:41.143783Z | false |
ansitech/weixin4j | https://github.com/ansitech/weixin4j/blob/f5e7a60e0c377f7420866b229a9ac79e687d5ac5/src/main/java/org/weixin4j/WeixinUrlFilter.java | src/main/java/org/weixin4j/WeixinUrlFilter.java | /*
* 微信公众平台(JAVA) SDK
*
* Copyright (c) 2014, Ansitech Network Technology Co.,Ltd All rights reserved.
*
* http://www.weixin4j.org/
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.weixin4j;
import org.weixin4j.util.TokenUtil;
import java.io.IOException;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletInputStream;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.weixin4j.spi.IMessageHandler;
import org.weixin4j.spi.HandlerFactory;
/**
* 微信公众平台接受消息默认拦截器
*
* @author yangqisheng
* @since 0.0.1
*/
public class WeixinUrlFilter implements Filter {
@Override
public void init(FilterConfig config) throws ServletException {
if (Configuration.isDebug()) {
System.out.println("WeixinUrlFilter启动成功!");
}
}
@Override
public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException {
HttpServletRequest request = (HttpServletRequest) req;
HttpServletResponse response = (HttpServletResponse) res;
//微信服务器将发送GET请求到填写的URL上,这里需要判定是否为GET请求
boolean isGet = request.getMethod().toLowerCase().equals("get");
if (Configuration.isDebug()) {
System.out.println("获得微信请求:" + request.getMethod() + " 方式");
System.out.println("微信请求URL:" + request.getServletPath());
}
//消息来源可靠性验证
String signature = request.getParameter("signature");// 微信加密签名
String timestamp = request.getParameter("timestamp");// 时间戳
String nonce = request.getParameter("nonce"); // 随机数
//Token为weixin4j.properties中配置的Token
String token = TokenUtil.get();
if (isGet) {
//1.验证消息真实性
//http://mp.weixin.qq.com/wiki/index.php?title=验证消息真实性
//URL为http://www.weixin4j.org/api/公众号
//成为开发者验证
String echostr = request.getParameter("echostr"); //
//确认此次GET请求来自微信服务器,原样返回echostr参数内容,则接入生效,成为开发者成功,否则接入失败
if (TokenUtil.checkSignature(token, signature, timestamp, nonce)) {
response.getWriter().write(echostr);
}
} else {
//确认此次GET请求来自微信服务器,原样返回echostr参数内容,则接入生效,成为开发者成功,否则接入失败
if (!TokenUtil.checkSignature(token, signature, timestamp, nonce)) {
//消息不可靠,直接返回
response.getWriter().write("");
return;
}
//用户每次向公众号发送消息、或者产生自定义菜单点击事件时,响应URL将得到推送
doPost(request, response);
}
}
//当普通微信用户向公众账号发消息时,微信服务器将POST消息的XML数据包到开发者填写的URL上
//用户在关注与取消关注公众号时,微信会把这个事件推送到开发者填写的URL
//用户每次发送语音给公众号时,微信会在推送的语音消息XML数据包中,增加一个Recongnition字段
private void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException {
try {
response.setCharacterEncoding("UTF-8");
response.setContentType("text/xml");
//获取POST流
ServletInputStream in = request.getInputStream();
if (Configuration.isDebug()) {
System.out.println("接收到微信输入流,准备处理...");
}
IMessageHandler messageHandler = HandlerFactory.getMessageHandler();
//处理输入消息,返回结果
String xml = messageHandler.invoke(in);
//返回结果
response.getWriter().write(xml);
} catch (Exception ex) {
ex.printStackTrace();
response.getWriter().write("");
}
}
@Override
public void destroy() {
}
}
| java | Apache-2.0 | f5e7a60e0c377f7420866b229a9ac79e687d5ac5 | 2026-01-05T02:42:41.143783Z | false |
ansitech/weixin4j | https://github.com/ansitech/weixin4j/blob/f5e7a60e0c377f7420866b229a9ac79e687d5ac5/src/main/java/org/weixin4j/WeixinSupport.java | src/main/java/org/weixin4j/WeixinSupport.java | /*
* 微信公众平台(JAVA) SDK
*
* Copyright (c) 2014, Ansitech Network Technology Co.,Ltd All rights reserved.
*
* http://www.weixin4j.org/
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.weixin4j;
import java.util.HashMap;
import java.util.Map;
/**
* 微信平台支持
*
* <p>
* 通过<tt>Weixin</tt>产生一个请求对象,对应生成一个<tt>HttpClient</tt>,
* 每次登陆产生一个<tt>OAuth</tt>用户连接,使用<tt>OAuthToken</tt>
* 可以不用重复向微信平台发送登陆请求,在没有过期时间内,可继续请求。</p>
*
* @author yangqisheng
* @since 0.0.1
*/
public class WeixinSupport {
/**
* 全局返回码说明
*/
private final static Map<Integer, String> RETURN_CODE_MAP = new HashMap<Integer, String>();
static {
RETURN_CODE_MAP.put(-1, "系统繁忙,此时请开发者稍候再试");
RETURN_CODE_MAP.put(0, "请求成功");
RETURN_CODE_MAP.put(40001, "获取 access_token 时 AppSecret 错误,或者 access_token 无效。请开发者认真比对 AppSecret 的正确性,或查看是否正在为恰当的公众号调用接口");
RETURN_CODE_MAP.put(40002, "不合法的凭证类型");
RETURN_CODE_MAP.put(40003, "不合法的 OpenID ,请开发者确认 OpenID (该用户)是否已关注公众号,或是否是其他公众号的 OpenID");
RETURN_CODE_MAP.put(40004, "不合法的媒体文件类型");
RETURN_CODE_MAP.put(40005, "不合法的文件类型");
RETURN_CODE_MAP.put(40006, "不合法的文件大小");
RETURN_CODE_MAP.put(40007, "不合法的媒体文件 id");
RETURN_CODE_MAP.put(40008, "不合法的消息类型");
RETURN_CODE_MAP.put(40009, "不合法的图片文件大小");
RETURN_CODE_MAP.put(40010, "不合法的语音文件大小");
RETURN_CODE_MAP.put(40011, "不合法的视频文件大小");
RETURN_CODE_MAP.put(40012, "不合法的缩略图文件大小");
RETURN_CODE_MAP.put(40013, "不合法的 AppID ,请开发者检查 AppID 的正确性,避免异常字符,注意大小写");
RETURN_CODE_MAP.put(40014, "不合法的 access_token ,请开发者认真比对 access_token 的有效性(如是否过期),或查看是否正在为恰当的公众号调用接口");
RETURN_CODE_MAP.put(40015, "不合法的菜单类型");
RETURN_CODE_MAP.put(40016, "不合法的按钮个数");
RETURN_CODE_MAP.put(40017, "不合法的按钮个数");
RETURN_CODE_MAP.put(40018, "不合法的按钮名字长度");
RETURN_CODE_MAP.put(40019, "不合法的按钮 KEY 长度");
RETURN_CODE_MAP.put(40020, "不合法的按钮 URL 长度");
RETURN_CODE_MAP.put(40021, "不合法的菜单版本号");
RETURN_CODE_MAP.put(40022, "不合法的子菜单级数");
RETURN_CODE_MAP.put(40023, "不合法的子菜单按钮个数");
RETURN_CODE_MAP.put(40024, "不合法的子菜单按钮类型");
RETURN_CODE_MAP.put(40025, "不合法的子菜单按钮名字长度");
RETURN_CODE_MAP.put(40026, "不合法的子菜单按钮 KEY 长度");
RETURN_CODE_MAP.put(40027, "不合法的子菜单按钮 URL 长度");
RETURN_CODE_MAP.put(40028, "不合法的自定义菜单使用用户");
RETURN_CODE_MAP.put(40029, "不合法的 oauth_code");
RETURN_CODE_MAP.put(40030, "不合法的 refresh_token");
RETURN_CODE_MAP.put(40031, "不合法的 openid 列表");
RETURN_CODE_MAP.put(40032, "不合法的 openid 列表长度");
RETURN_CODE_MAP.put(40033, "不合法的请求字符,不能包含 \\uxxxx 格式的字符");
RETURN_CODE_MAP.put(40035, "不合法的参数");
RETURN_CODE_MAP.put(40038, "不合法的请求格式");
RETURN_CODE_MAP.put(40039, "不合法的 URL 长度");
RETURN_CODE_MAP.put(40050, "不合法的分组 id");
RETURN_CODE_MAP.put(40051, "分组名字不合法");
RETURN_CODE_MAP.put(40060, "删除单篇图文时,指定的 article_idx 不合法");
RETURN_CODE_MAP.put(40117, "分组名字不合法");
RETURN_CODE_MAP.put(40118, "media_id 大小不合法");
RETURN_CODE_MAP.put(40119, "button 类型错误");
RETURN_CODE_MAP.put(40120, "button 类型错误");
RETURN_CODE_MAP.put(40121, "不合法的 media_id 类型");
RETURN_CODE_MAP.put(40132, "微信号不合法");
RETURN_CODE_MAP.put(40137, "不支持的图片格式");
RETURN_CODE_MAP.put(40155, "请勿添加其他公众号的主页链接");
RETURN_CODE_MAP.put(41001, "缺少 access_token 参数");
RETURN_CODE_MAP.put(41002, "缺少 appid 参数");
RETURN_CODE_MAP.put(41003, "缺少 refresh_token 参数");
RETURN_CODE_MAP.put(41004, "缺少 secret 参数");
RETURN_CODE_MAP.put(41005, "缺少多媒体文件数据");
RETURN_CODE_MAP.put(41006, "缺少 media_id 参数");
RETURN_CODE_MAP.put(41007, "缺少子菜单数据");
RETURN_CODE_MAP.put(41008, "缺少 oauth code");
RETURN_CODE_MAP.put(41009, "缺少 openid");
RETURN_CODE_MAP.put(42001, "access_token 超时,请检查 access_token 的有效期,请参考基础支持 - 获取 access_token 中,对 access_token 的详细机制说明");
RETURN_CODE_MAP.put(42002, "refresh_token 超时");
RETURN_CODE_MAP.put(42003, "oauth_code 超时");
RETURN_CODE_MAP.put(42007, "用户修改微信密码, accesstoken 和 refreshtoken 失效,需要重新授权");
RETURN_CODE_MAP.put(43001, "需要 GET 请求");
RETURN_CODE_MAP.put(43002, "需要 POST 请求");
RETURN_CODE_MAP.put(43003, "需要 HTTPS 请求");
RETURN_CODE_MAP.put(43004, "需要接收者关注");
RETURN_CODE_MAP.put(43005, "需要好友关系");
RETURN_CODE_MAP.put(43019, "需要将接收者从黑名单中移除");
RETURN_CODE_MAP.put(44001, "多媒体文件为空");
RETURN_CODE_MAP.put(44002, "POST 的数据包为空");
RETURN_CODE_MAP.put(44003, "图文消息内容为空");
RETURN_CODE_MAP.put(44004, "文本消息内容为空");
RETURN_CODE_MAP.put(45001, "多媒体文件大小超过限制");
RETURN_CODE_MAP.put(45002, "消息内容超过限制");
RETURN_CODE_MAP.put(45003, "标题字段超过限制");
RETURN_CODE_MAP.put(45004, "描述字段超过限制");
RETURN_CODE_MAP.put(45005, "链接字段超过限制");
RETURN_CODE_MAP.put(45006, "图片链接字段超过限制");
RETURN_CODE_MAP.put(45007, "语音播放时间超过限制");
RETURN_CODE_MAP.put(45008, "图文消息超过限制");
RETURN_CODE_MAP.put(45009, "接口调用超过限制");
RETURN_CODE_MAP.put(45010, "创建菜单个数超过限制");
RETURN_CODE_MAP.put(45011, "API 调用太频繁,请稍候再试");
RETURN_CODE_MAP.put(45015, "回复时间超过限制");
RETURN_CODE_MAP.put(45016, "系统分组,不允许修改");
RETURN_CODE_MAP.put(45017, "分组名字过长");
RETURN_CODE_MAP.put(45018, "分组数量超过上限");
RETURN_CODE_MAP.put(45047, "客服接口下行条数超过上限");
RETURN_CODE_MAP.put(46001, "不存在媒体数据");
RETURN_CODE_MAP.put(46002, "不存在的菜单版本");
RETURN_CODE_MAP.put(46003, "不存在的菜单数据");
RETURN_CODE_MAP.put(46004, "不存在的用户");
RETURN_CODE_MAP.put(47001, "解析 JSON/XML 内容错误");
RETURN_CODE_MAP.put(48001, "api 功能未授权,请确认公众号已获得该接口,可以在公众平台官网 - 开发者中心页中查看接口权限");
RETURN_CODE_MAP.put(48002, "粉丝拒收消息(粉丝在公众号选项中,关闭了 “ 接收消息 ” )");
RETURN_CODE_MAP.put(48004, "api 接口被封禁,请登录 mp.weixin.qq.com 查看详情");
RETURN_CODE_MAP.put(48005, "api 禁止删除被自动回复和自定义菜单引用的素材");
RETURN_CODE_MAP.put(48006, "api 禁止清零调用次数,因为清零次数达到上限");
RETURN_CODE_MAP.put(48008, "没有该类型消息的发送权限");
RETURN_CODE_MAP.put(50001, "用户未授权该 api");
RETURN_CODE_MAP.put(50002, "用户受限,可能是违规后接口被封禁");
RETURN_CODE_MAP.put(61451, "参数错误 (invalid parameter)");
RETURN_CODE_MAP.put(61452, "无效客服账号 (invalid kf_account)");
RETURN_CODE_MAP.put(61453, "客服帐号已存在 (kf_account exsited)");
RETURN_CODE_MAP.put(61454, "客服帐号名长度超过限制 ( 仅允许 10 个英文字符,不包括 @ 及 @ 后的公众号的微信号 )(invalid kf_acount length)");
RETURN_CODE_MAP.put(61455, "客服帐号名包含非法字符 ( 仅允许英文 + 数字 )(illegal character in kf_account)");
RETURN_CODE_MAP.put(61456, "客服帐号个数超过限制 (10 个客服账号 )(kf_account count exceeded)");
RETURN_CODE_MAP.put(61457, "无效头像文件类型 (invalid file type)");
RETURN_CODE_MAP.put(61450, "系统错误 (system error)");
RETURN_CODE_MAP.put(61500, "日期格式错误");
RETURN_CODE_MAP.put(65301, "不存在此 menuid 对应的个性化菜单");
RETURN_CODE_MAP.put(65302, "没有相应的用户");
RETURN_CODE_MAP.put(65303, "没有默认菜单,不能创建个性化菜单");
RETURN_CODE_MAP.put(65304, "MatchRule 信息为空");
RETURN_CODE_MAP.put(65305, "个性化菜单数量受限");
RETURN_CODE_MAP.put(65306, "不支持个性化菜单的帐号");
RETURN_CODE_MAP.put(65307, "个性化菜单信息为空");
RETURN_CODE_MAP.put(65308, "包含没有响应类型的 button");
RETURN_CODE_MAP.put(65309, "个性化菜单开关处于关闭状态");
RETURN_CODE_MAP.put(65310, "填写了省份或城市信息,国家信息不能为空");
RETURN_CODE_MAP.put(65311, "填写了城市信息,省份信息不能为空");
RETURN_CODE_MAP.put(65312, "不合法的国家信息");
RETURN_CODE_MAP.put(65313, "不合法的省份信息");
RETURN_CODE_MAP.put(65314, "不合法的城市信息");
RETURN_CODE_MAP.put(65316, "该公众号的菜单设置了过多的域名外跳(最多跳转到 3 个域名的链接)");
RETURN_CODE_MAP.put(65317, "不合法的 URL");
RETURN_CODE_MAP.put(9001001, "POST 数据参数不合法");
RETURN_CODE_MAP.put(9001002, "远端服务不可用");
RETURN_CODE_MAP.put(9001003, "Ticket 不合法");
RETURN_CODE_MAP.put(9001004, "获取摇周边用户信息失败");
RETURN_CODE_MAP.put(9001005, "获取商户信息失败");
RETURN_CODE_MAP.put(9001006, "获取 openid 失败");
RETURN_CODE_MAP.put(9001007, "上传文件缺失");
RETURN_CODE_MAP.put(9001008, "上传素材的文件类型不合法");
RETURN_CODE_MAP.put(9001009, "上传素材的文件尺寸不合法");
RETURN_CODE_MAP.put(9001010, "上传失败");
RETURN_CODE_MAP.put(9001020, "帐号不合法");
RETURN_CODE_MAP.put(9001021, "已有设备激活率低于 50% ,不能新增设备");
RETURN_CODE_MAP.put(9001022, "设备申请数不合法,必须为大于 0 的数字");
RETURN_CODE_MAP.put(9001023, "已存在审核中的设备 ID 申请");
RETURN_CODE_MAP.put(9001024, "一次查询设备 ID 数量不能超过 50");
RETURN_CODE_MAP.put(9001025, "设备 ID 不合法");
RETURN_CODE_MAP.put(9001026, "页面 ID 不合法");
RETURN_CODE_MAP.put(9001027, "页面参数不合法");
RETURN_CODE_MAP.put(9001028, "一次删除页面 ID 数量不能超过 10");
RETURN_CODE_MAP.put(9001029, "页面已应用在设备中,请先解除应用关系再删除");
RETURN_CODE_MAP.put(9001030, "一次查询页面 ID 数量不能超过 50");
RETURN_CODE_MAP.put(9001031, "时间区间不合法");
RETURN_CODE_MAP.put(9001032, "保存设备与页面的绑定关系参数错误");
RETURN_CODE_MAP.put(9001033, "门店 ID 不合法");
RETURN_CODE_MAP.put(9001034, "设备备注信息过长");
RETURN_CODE_MAP.put(9001035, "设备申请参数不合法");
RETURN_CODE_MAP.put(9001036, "查询起始值 begin 不合法");
}
/**
* 异常代码识别
*
* @param statusCode 异常代码
* @return 错误信息
*/
public String getCause(int statusCode) {
if (RETURN_CODE_MAP.containsKey(statusCode)) {
//根据错误码返回错误代码
return statusCode + ":" + RETURN_CODE_MAP.get(statusCode);
}
return statusCode + ":操作异常";
}
}
| java | Apache-2.0 | f5e7a60e0c377f7420866b229a9ac79e687d5ac5 | 2026-01-05T02:42:41.143783Z | false |
ansitech/weixin4j | https://github.com/ansitech/weixin4j/blob/f5e7a60e0c377f7420866b229a9ac79e687d5ac5/src/main/java/org/weixin4j/util/PayUtil.java | src/main/java/org/weixin4j/util/PayUtil.java | /*
* 微信公众平台(JAVA) SDK
*
* Copyright (c) 2014, Ansitech Network Technology Co.,Ltd All rights reserved.
*
* http://www.weixin4j.org/
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.weixin4j.util;
import java.io.StringReader;
import java.util.Map;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Unmarshaller;
import org.weixin4j.model.pay.PayNotifyResult;
import org.weixin4j.model.pay.WCPay;
import org.weixin4j.model.pay.WXPay;
/**
* 微信支付工具
*
* @author yangqisheng
* @since 0.0.4
*/
public class PayUtil {
/**
* 对预下单Id进行H5支付
*
* @param appId 开发者Id
* @param prepay_id 预下单Id
* @param mchKey API密钥
* @return 支付对象
*/
public static WCPay getBrandWCPayRequest(String appId, String prepay_id, String mchKey) {
//初始化支付对象
return new WCPay(appId, prepay_id, mchKey);
}
/**
* chooseWXPay
*
* @param appId 公众号Id
* @param jsapi_ticket jsapi验证票据
* @param prepay_id 预下单Id
* @param mchKey API密钥
* @param url 发起请求的url地址
* @return 支付对象
*/
public static WXPay getChooseWXPay(String appId, String jsapi_ticket, String prepay_id, String url, String mchKey) {
return new WXPay(appId, jsapi_ticket, prepay_id, url, mchKey);
}
/**
* 验证签名
*
* @param xmlMsg xml参数字符串
* @param mchKey 商户密钥
* @return 签名验证,成功返回true,否则返回false
*/
public static boolean verifySign(String xmlMsg, String mchKey) {
try {
JAXBContext context = JAXBContext.newInstance(PayNotifyResult.class);
Unmarshaller unmarshaller = context.createUnmarshaller();
PayNotifyResult result = (PayNotifyResult) unmarshaller.unmarshal(new StringReader(xmlMsg));
//转换为Map
Map<String, String> map = result.toMap();
if (map.containsKey("sign")) {
map.remove("sign");
}
//签名
String sign = SignUtil.getSign(map, mchKey);
if (sign == null || sign.equals("")) {
return false;
}
//判断是否一致
return sign.equals(result.getSign());
} catch (JAXBException ex) {
return false;
}
}
}
| java | Apache-2.0 | f5e7a60e0c377f7420866b229a9ac79e687d5ac5 | 2026-01-05T02:42:41.143783Z | false |
ansitech/weixin4j | https://github.com/ansitech/weixin4j/blob/f5e7a60e0c377f7420866b229a9ac79e687d5ac5/src/main/java/org/weixin4j/util/MapUtil.java | src/main/java/org/weixin4j/util/MapUtil.java | /*
* 微信公众平台(JAVA) SDK
*
* Copyright (c) 2014, Ansitech Network Technology Co.,Ltd All rights reserved.
*
* http://www.weixin4j.org/
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.weixin4j.util;
import java.io.ByteArrayInputStream;
import java.io.UnsupportedEncodingException;
import java.io.IOException;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import org.w3c.dom.DOMException;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;
/**
* MapUtil业务
*
* @author yangqisheng
* @since 0.0.1
*/
public class MapUtil {
/**
* Map key 升序排序
*
* 排序方式:ASCII码从小到大排序(字典序)
*
* @param map 需排序的map集合
* @return 排序后的map集合
*/
public static Map<String, String> sortAsc(Map<String, String> map) {
HashMap<String, String> tempMap = new LinkedHashMap<String, String>();
List<Map.Entry<String, String>> infoIds = new ArrayList<Map.Entry<String, String>>(map.entrySet());
//排序
Collections.sort(infoIds, new Comparator<Map.Entry<String, String>>() {
@Override
public int compare(Map.Entry<String, String> o1, Map.Entry<String, String> o2) {
return o1.getKey().compareTo(o2.getKey());
}
});
for (int i = 0; i < infoIds.size(); i++) {
Map.Entry<String, String> item = infoIds.get(i);
tempMap.put(item.getKey(), item.getValue());
}
return tempMap;
}
/**
* url 参数串连
*
* @param map 需拼接的参数map
* @param valueUrlEncode 是否需要对map的value进行url编码
* @return 拼接后的URL键值对字符串
*/
public static String mapJoin(Map<String, String> map, boolean valueUrlEncode) {
StringBuilder sb = new StringBuilder();
for (String key : map.keySet()) {
if (map.get(key) != null && !"".equals(map.get(key))) {
try {
String temp = (key.endsWith("_") && key.length() > 1) ? key.substring(0, key.length() - 1) : key;
sb.append(temp);
sb.append("=");
//获取到map的值
String value = map.get(key);
//判断是否需要url编码
if (valueUrlEncode) {
value = URLEncoder.encode(map.get(key), "utf-8").replace("+", "%20");
}
sb.append(value);
sb.append("&");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
}
}
if (sb.length() > 0) {
sb.deleteCharAt(sb.length() - 1);
}
return sb.toString();
}
/**
* 简单 xml 转换为 Map
*
* @param xml xml字符串
* @return Map对象
*/
public static Map<String, String> xmlToMap(String xml) {
try {
DocumentBuilder documentBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
Document document = documentBuilder.parse(new ByteArrayInputStream(xml.getBytes()));
Element element = document.getDocumentElement();
NodeList nodeList = element.getChildNodes();
Map<String, String> map = new LinkedHashMap<String, String>();
for (int i = 0; i < nodeList.getLength(); i++) {
Element e = (Element) nodeList.item(i);
map.put(e.getNodeName(), e.getTextContent());
}
return map;
} catch (DOMException e) {
e.printStackTrace();
} catch (ParserConfigurationException e) {
e.printStackTrace();
} catch (SAXException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
}
| java | Apache-2.0 | f5e7a60e0c377f7420866b229a9ac79e687d5ac5 | 2026-01-05T02:42:41.143783Z | false |
ansitech/weixin4j | https://github.com/ansitech/weixin4j/blob/f5e7a60e0c377f7420866b229a9ac79e687d5ac5/src/main/java/org/weixin4j/util/SignUtil.java | src/main/java/org/weixin4j/util/SignUtil.java | /*
* 微信公众平台(JAVA) SDK
*
* Copyright (c) 2014, Ansitech Network Technology Co.,Ltd All rights reserved.
*
* http://www.weixin4j.org/
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.weixin4j.util;
import java.io.UnsupportedEncodingException;
import java.util.HashMap;
import java.util.Map;
import org.apache.commons.codec.digest.DigestUtils;
import org.weixin4j.Configuration;
/**
* 签名算法
*
* @author yangqisheng
* @since 0.0.1
*/
public class SignUtil {
/**
* 生成jsapi授权签名
*
* 签名算法
*
* 签名生成规则如下:
*
* 参与签名的字段包括noncestr(随机字符串), 有效的jsapi_ticket, timestamp(时间戳),
* url(当前网页的URL,不包含#及其后面部分)。
*
* 对所有待签名参数按照字段名的ASCII 码从小到大排序(字典序)后,使用URL键值对的格式,拼接成字符串string1
*
* 这里需要注意的是所有参数名均为小写字符。
*
* 对string1进行sha1签名,得到signature, 字段名和字段值都采用原始值,不进行URL 转义。
*
* @param jsapi_ticket 微信JS接口的临时票据
* @param noncestr 随机字符串
* @param timestamp 时间戳
* @param url 调用的页面Url,包括?后的部分
* @return 成功返回授权签名,否则返回空
*/
public static String getSignature(String jsapi_ticket, String noncestr, String timestamp, String url) {
Map<String, String> params = new HashMap<String, String>();
params.put("jsapi_ticket", jsapi_ticket);
params.put("noncestr", noncestr);
params.put("timestamp", timestamp);
params.put("url", url);
//1.1 对所有待签名参数按照字段名的ASCII 码从小到大排序(字典序)
Map<String, String> sortParams = MapUtil.sortAsc(params);
//1.2 使用URL键值对的格式拼接成字符串
String string1 = MapUtil.mapJoin(sortParams, false);
try {
//2 对string1进行sha1签名
return DigestUtils.sha1Hex(string1.getBytes("UTF-8"));
} catch (UnsupportedEncodingException e) {
}
return "";
}
/**
* getBrandWCPayRequest签名
*
* @param map 待签名参数
* @param mchKey 商户密钥
* @return 签名paySign
*/
public static String getSign(Map<String, String> map, String mchKey) {
//1.1 对所有待签名参数按照字段名的ASCII 码从小到大排序(字典序)
Map<String, String> sortParams = MapUtil.sortAsc(map);
//1.2 使用URL键值对的格式
String string1 = MapUtil.mapJoin(sortParams, false);
if (Configuration.isDebug()) {
System.out.println("#1.生成字符串:");
System.out.println(string1);
}
//拼接签名字符串
String stringSignTemp = string1 + "&key=" + mchKey;
if (Configuration.isDebug()) {
System.out.println("#2.连接商户key:");
System.out.println(stringSignTemp);
}
//2.对string1进行MD5签名
String sign = DigestUtils.md5Hex(stringSignTemp).toUpperCase();
if (Configuration.isDebug()) {
System.out.println("#3.md5编码并转成大写:");
System.out.println("sign=" + sign);
}
return sign;
}
}
| java | Apache-2.0 | f5e7a60e0c377f7420866b229a9ac79e687d5ac5 | 2026-01-05T02:42:41.143783Z | false |
ansitech/weixin4j | https://github.com/ansitech/weixin4j/blob/f5e7a60e0c377f7420866b229a9ac79e687d5ac5/src/main/java/org/weixin4j/util/TokenUtil.java | src/main/java/org/weixin4j/util/TokenUtil.java | /*
* 微信公众平台(JAVA) SDK
*
* Copyright (c) 2014, Ansitech Network Technology Co.,Ltd All rights reserved.
*
* http://www.weixin4j.org/
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.weixin4j.util;
import org.weixin4j.Configuration;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
/**
* <p>
* Title: 微信公众平台Token算法工具类</p>
*
* <p>
* Description: 为应用提供URL算法 根据不同的URL返回不同的Token,以适应多微站的需求
* 例如:Url:http://www.weixin4j.org/api/tiexinqiao
* 则默认Token:为jEvQdLxi0PvtgK8N+HzUpA== 根据配置的系统Token不同,而改变</p>
*
* @author yangqisheng
* @since 0.0.1
*/
public class TokenUtil {
//此加密密钥用于加密公众号Token,一经配置,不能修改,一旦修改,所有公众号需要重新填写Token
private static String systemToken = null;
/**
* 获取配置文件配置的Token
*
* @return 微站Token
*/
public static String get() {
if (systemToken == null) {
systemToken = Configuration.getProperty("weixin4j.token", "weixin4j");
}
return systemToken;
}
/**
* 加密/校验流程如下:
*
* <p>
* 1. 将token、timestamp、nonce三个参数进行字典序排序<br>
* 2.将三个参数字符串拼接成一个字符串进行sha1加密<br>
* 3. 开发者获得加密后的字符串可与signature对比,标识该请求来源于微信<br>
* </p>
*
* @param token Token验证密钥
* @param signature 微信加密签名,signature结合了开发者填写的token参数和请求中的timestamp参数,nonce参数
* @param timestamp 时间戳
* @param nonce 随机数
* @return 验证成功返回true,否则返回false
*/
public static boolean checkSignature(String token, String signature, String timestamp, String nonce) {
List<String> params = new ArrayList<String>();
params.add(token);
params.add(timestamp);
params.add(nonce);
//1. 将token、timestamp、nonce三个参数进行字典序排序
Collections.sort(params, new Comparator<String>() {
@Override
public int compare(String o1, String o2) {
return o1.compareTo(o2);
}
});
//2. 将三个参数字符串拼接成一个字符串进行sha1加密
String temp = SHA1.encode(params.get(0) + params.get(1) + params.get(2));
//3. 开发者获得加密后的字符串可与signature对比,标识该请求来源于微信
return temp.equals(signature);
}
}
| java | Apache-2.0 | f5e7a60e0c377f7420866b229a9ac79e687d5ac5 | 2026-01-05T02:42:41.143783Z | false |
ansitech/weixin4j | https://github.com/ansitech/weixin4j/blob/f5e7a60e0c377f7420866b229a9ac79e687d5ac5/src/main/java/org/weixin4j/util/SHA1.java | src/main/java/org/weixin4j/util/SHA1.java | /*
* 微信公众平台(JAVA) SDK
*
* Copyright (c) 2014, Ansitech Network Technology Co.,Ltd All rights reserved.
*
* http://www.weixin4j.org/
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.weixin4j.util;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
/**
* SHA1算法
*
* @author yangqisheng
* @since 0.0.1
*/
public final class SHA1 {
private static final char[] HEX_DIGITS = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
/**
* Takes the raw bytes from the digest and formats them correct.
*
* @param bytes the raw bytes from the digest.
* @return the formatted bytes.
*/
private static String getFormattedText(byte[] bytes) {
int len = bytes.length;
StringBuilder buf = new StringBuilder(len * 2);
// 把密文转换成十六进制的字符串形式
for (int j = 0; j < len; j++) {
buf.append(HEX_DIGITS[(bytes[j] >> 4) & 0x0f]);
buf.append(HEX_DIGITS[bytes[j] & 0x0f]);
}
return buf.toString();
}
public static String encode(String str) {
if (str == null) {
return null;
}
try {
MessageDigest messageDigest = MessageDigest.getInstance("SHA1");
messageDigest.update(str.getBytes());
return getFormattedText(messageDigest.digest());
} catch (NoSuchAlgorithmException e) {
throw new RuntimeException(e);
}
}
}
| java | Apache-2.0 | f5e7a60e0c377f7420866b229a9ac79e687d5ac5 | 2026-01-05T02:42:41.143783Z | false |
ansitech/weixin4j | https://github.com/ansitech/weixin4j/blob/f5e7a60e0c377f7420866b229a9ac79e687d5ac5/src/main/java/org/weixin4j/util/XStreamFactory.java | src/main/java/org/weixin4j/util/XStreamFactory.java | /*
* 微信公众平台(JAVA) SDK
*
* Copyright (c) 2014, Ansitech Network Technology Co.,Ltd All rights reserved.
*
* http://www.weixin4j.org/
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.weixin4j.util;
import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
/**
* 将微信POST的流转换为XStream,然后转换为InputMessage对象
*
* @author yangqisheng
* @since 0.0.1
*/
public class XStreamFactory {
/**
* 将输入流转读取成字符串
*
* @param in 输入流
* @return 字符串
* @throws UnsupportedEncodingException 字符转换异常
* @throws IOException IO异常
*/
public static String inputStream2String(InputStream in)
throws UnsupportedEncodingException, IOException {
if (in == null) {
return "";
}
StringBuilder out = new StringBuilder();
byte[] b = new byte[4096];
for (int n; (n = in.read(b)) != -1;) {
out.append(new String(b, 0, n, "UTF-8"));
}
return out.toString();
}
}
| java | Apache-2.0 | f5e7a60e0c377f7420866b229a9ac79e687d5ac5 | 2026-01-05T02:42:41.143783Z | false |
ansitech/weixin4j | https://github.com/ansitech/weixin4j/blob/f5e7a60e0c377f7420866b229a9ac79e687d5ac5/src/main/java/org/weixin4j/util/MD5.java | src/main/java/org/weixin4j/util/MD5.java | /*
* 微信公众平台(JAVA) SDK
*
* Copyright (c) 2014, Ansitech Network Technology Co.,Ltd All rights reserved.
*
* http://www.weixin4j.org/
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.weixin4j.util;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import org.weixin4j.misc.BASE64Encoder;
/**
* MD5加密算法
*
* @author yangqisheng
* @since 0.0.1
*/
public class MD5 {
/**
* 将字符串加密
*
* @param str 要加密的字符串
* @return 加密后的字符串
*/
public static String encryptByMd5(String str) {
if (str == null) {
return null;
}
try {
MessageDigest md5 = MessageDigest.getInstance("MD5");
BASE64Encoder base64en = new BASE64Encoder();
byte[] b = str.getBytes();
byte[] digest = md5.digest(b);
String newstr = base64en.encode(digest);
return newstr;
} catch (NoSuchAlgorithmException e) {
throw new RuntimeException(e);
}
}
}
| java | Apache-2.0 | f5e7a60e0c377f7420866b229a9ac79e687d5ac5 | 2026-01-05T02:42:41.143783Z | false |
ansitech/weixin4j | https://github.com/ansitech/weixin4j/blob/f5e7a60e0c377f7420866b229a9ac79e687d5ac5/src/main/java/org/weixin4j/misc/CharacterDecoder.java | src/main/java/org/weixin4j/misc/CharacterDecoder.java | package org.weixin4j.misc;
import java.io.OutputStream;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.io.PushbackInputStream;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.nio.ByteBuffer;
public abstract class CharacterDecoder {
abstract protected int bytesPerAtom();
abstract protected int bytesPerLine();
protected void decodeBufferPrefix(PushbackInputStream aStream,
OutputStream bStream) throws IOException {
}
protected void decodeBufferSuffix(PushbackInputStream aStream,
OutputStream bStream) throws IOException {
}
protected int decodeLinePrefix(PushbackInputStream aStream,
OutputStream bStream) throws IOException {
return (bytesPerLine());
}
protected void decodeLineSuffix(PushbackInputStream aStream,
OutputStream bStream) throws IOException {
}
protected void decodeAtom(PushbackInputStream aStream,
OutputStream bStream, int l) throws IOException {
throw new CEStreamExhausted();
}
protected int readFully(InputStream in, byte buffer[], int offset, int len)
throws java.io.IOException {
for (int i = 0; i < len; i++) {
int q = in.read();
if (q == -1) {
return ((i == 0) ? -1 : i);
}
buffer[i + offset] = (byte) q;
}
return len;
}
public void decodeBuffer(InputStream aStream, OutputStream bStream)
throws IOException {
int i;
int totalBytes = 0;
PushbackInputStream ps = new PushbackInputStream(aStream);
decodeBufferPrefix(ps, bStream);
while (true) {
int length;
try {
length = decodeLinePrefix(ps, bStream);
for (i = 0; (i + bytesPerAtom()) < length; i += bytesPerAtom()) {
decodeAtom(ps, bStream, bytesPerAtom());
totalBytes += bytesPerAtom();
}
if ((i + bytesPerAtom()) == length) {
decodeAtom(ps, bStream, bytesPerAtom());
totalBytes += bytesPerAtom();
} else {
decodeAtom(ps, bStream, length - i);
totalBytes += (length - i);
}
decodeLineSuffix(ps, bStream);
} catch (CEStreamExhausted e) {
break;
}
}
decodeBufferSuffix(ps, bStream);
}
public byte decodeBuffer (String inputString) [] throws IOException {
byte inputBuffer[] = new byte[inputString.length()];
ByteArrayInputStream inStream;
ByteArrayOutputStream outStream;
inputString.getBytes(0, inputString.length(), inputBuffer, 0);
inStream = new ByteArrayInputStream(inputBuffer);
outStream = new ByteArrayOutputStream();
decodeBuffer(inStream, outStream);
return (outStream.toByteArray());
}
public byte decodeBuffer (InputStream in) [] throws IOException {
ByteArrayOutputStream outStream = new ByteArrayOutputStream();
decodeBuffer(in, outStream);
return (outStream.toByteArray());
}
public ByteBuffer decodeBufferToByteBuffer(String inputString)
throws IOException {
return ByteBuffer.wrap(decodeBuffer(inputString));
}
public ByteBuffer decodeBufferToByteBuffer(InputStream in)
throws IOException {
return ByteBuffer.wrap(decodeBuffer(in));
}
}
| java | Apache-2.0 | f5e7a60e0c377f7420866b229a9ac79e687d5ac5 | 2026-01-05T02:42:41.143783Z | false |
ansitech/weixin4j | https://github.com/ansitech/weixin4j/blob/f5e7a60e0c377f7420866b229a9ac79e687d5ac5/src/main/java/org/weixin4j/misc/BASE64Decoder.java | src/main/java/org/weixin4j/misc/BASE64Decoder.java | package org.weixin4j.misc;
import java.io.OutputStream;
import java.io.PushbackInputStream;
public class BASE64Decoder extends CharacterDecoder {
@Override
protected int bytesPerAtom() {
return (4);
}
@Override
protected int bytesPerLine() {
return (72);
}
private final static char pem_array[] = {
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H',
'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P',
'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X',
'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f',
'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n',
'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
'w', 'x', 'y', 'z', '0', '1', '2', '3',
'4', '5', '6', '7', '8', '9', '+', '/'
};
private final static byte pem_convert_array[] = new byte[256];
static {
for (int i = 0; i < 255; i++) {
pem_convert_array[i] = -1;
}
for (int i = 0; i < pem_array.length; i++) {
pem_convert_array[pem_array[i]] = (byte) i;
}
}
byte decode_buffer[] = new byte[4];
@Override
protected void decodeAtom(PushbackInputStream inStream, OutputStream outStream, int rem)
throws java.io.IOException {
int i;
byte a = -1, b = -1, c = -1, d = -1;
if (rem < 2) {
throw new CEFormatException("BASE64Decoder: Not enough bytes for an atom.");
}
do {
i = inStream.read();
if (i == -1) {
throw new CEStreamExhausted();
}
} while (i == '\n' || i == '\r');
decode_buffer[0] = (byte) i;
i = readFully(inStream, decode_buffer, 1, rem - 1);
if (i == -1) {
throw new CEStreamExhausted();
}
if (rem > 3 && decode_buffer[3] == '=') {
rem = 3;
}
if (rem > 2 && decode_buffer[2] == '=') {
rem = 2;
}
switch (rem) {
case 4:
d = pem_convert_array[decode_buffer[3] & 0xff];
// NOBREAK
case 3:
c = pem_convert_array[decode_buffer[2] & 0xff];
// NOBREAK
case 2:
b = pem_convert_array[decode_buffer[1] & 0xff];
a = pem_convert_array[decode_buffer[0] & 0xff];
break;
}
switch (rem) {
case 2:
outStream.write((byte) (((a << 2) & 0xfc) | ((b >>> 4) & 3)));
break;
case 3:
outStream.write((byte) (((a << 2) & 0xfc) | ((b >>> 4) & 3)));
outStream.write((byte) (((b << 4) & 0xf0) | ((c >>> 2) & 0xf)));
break;
case 4:
outStream.write((byte) (((a << 2) & 0xfc) | ((b >>> 4) & 3)));
outStream.write((byte) (((b << 4) & 0xf0) | ((c >>> 2) & 0xf)));
outStream.write((byte) (((c << 6) & 0xc0) | (d & 0x3f)));
break;
}
}
}
| java | Apache-2.0 | f5e7a60e0c377f7420866b229a9ac79e687d5ac5 | 2026-01-05T02:42:41.143783Z | false |
ansitech/weixin4j | https://github.com/ansitech/weixin4j/blob/f5e7a60e0c377f7420866b229a9ac79e687d5ac5/src/main/java/org/weixin4j/misc/CEStreamExhausted.java | src/main/java/org/weixin4j/misc/CEStreamExhausted.java | package org.weixin4j.misc;
import java.io.IOException;
public class CEStreamExhausted extends IOException {
}
| java | Apache-2.0 | f5e7a60e0c377f7420866b229a9ac79e687d5ac5 | 2026-01-05T02:42:41.143783Z | false |
ansitech/weixin4j | https://github.com/ansitech/weixin4j/blob/f5e7a60e0c377f7420866b229a9ac79e687d5ac5/src/main/java/org/weixin4j/misc/CEFormatException.java | src/main/java/org/weixin4j/misc/CEFormatException.java | package org.weixin4j.misc;
import java.io.IOException;
public class CEFormatException extends IOException {
public CEFormatException(String s) {
super(s);
}
}
| java | Apache-2.0 | f5e7a60e0c377f7420866b229a9ac79e687d5ac5 | 2026-01-05T02:42:41.143783Z | false |
ansitech/weixin4j | https://github.com/ansitech/weixin4j/blob/f5e7a60e0c377f7420866b229a9ac79e687d5ac5/src/main/java/org/weixin4j/misc/BASE64Encoder.java | src/main/java/org/weixin4j/misc/BASE64Encoder.java | package org.weixin4j.misc;
import java.io.OutputStream;
import java.io.IOException;
public class BASE64Encoder extends CharacterEncoder {
@Override
protected int bytesPerAtom() {
return (3);
}
@Override
protected int bytesPerLine() {
return (57);
}
private final static char pem_array[] = {
// 0 1 2 3 4 5 6 7
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H',
'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P',
'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X',
'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f',
'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n',
'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
'w', 'x', 'y', 'z', '0', '1', '2', '3',
'4', '5', '6', '7', '8', '9', '+', '/'
};
@Override
protected void encodeAtom(OutputStream outStream, byte data[], int offset,
int len) throws IOException {
byte a, b, c;
if (len == 1) {
a = data[offset];
b = 0;
c = 0;
outStream.write(pem_array[(a >>> 2) & 0x3F]);
outStream.write(pem_array[((a << 4) & 0x30) + ((b >>> 4) & 0xf)]);
outStream.write('=');
outStream.write('=');
} else if (len == 2) {
a = data[offset];
b = data[offset + 1];
c = 0;
outStream.write(pem_array[(a >>> 2) & 0x3F]);
outStream.write(pem_array[((a << 4) & 0x30) + ((b >>> 4) & 0xf)]);
outStream.write(pem_array[((b << 2) & 0x3c) + ((c >>> 6) & 0x3)]);
outStream.write('=');
} else {
a = data[offset];
b = data[offset + 1];
c = data[offset + 2];
outStream.write(pem_array[(a >>> 2) & 0x3F]);
outStream.write(pem_array[((a << 4) & 0x30) + ((b >>> 4) & 0xf)]);
outStream.write(pem_array[((b << 2) & 0x3c) + ((c >>> 6) & 0x3)]);
outStream.write(pem_array[c & 0x3F]);
}
}
}
| java | Apache-2.0 | f5e7a60e0c377f7420866b229a9ac79e687d5ac5 | 2026-01-05T02:42:41.143783Z | false |
ansitech/weixin4j | https://github.com/ansitech/weixin4j/blob/f5e7a60e0c377f7420866b229a9ac79e687d5ac5/src/main/java/org/weixin4j/misc/CharacterEncoder.java | src/main/java/org/weixin4j/misc/CharacterEncoder.java | package org.weixin4j.misc;
import java.io.InputStream;
import java.io.ByteArrayInputStream;
import java.io.OutputStream;
import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
import java.io.IOException;
import java.nio.ByteBuffer;
public abstract class CharacterEncoder {
protected PrintStream pStream;
abstract protected int bytesPerAtom();
abstract protected int bytesPerLine();
protected void encodeBufferPrefix(OutputStream aStream) throws IOException {
pStream = new PrintStream(aStream);
}
protected void encodeBufferSuffix(OutputStream aStream) throws IOException {
}
protected void encodeLinePrefix(OutputStream aStream, int aLength)
throws IOException {
}
protected void encodeLineSuffix(OutputStream aStream) throws IOException {
pStream.println();
}
abstract protected void encodeAtom(OutputStream aStream, byte someBytes[],
int anOffset, int aLength) throws IOException;
protected int readFully(InputStream in, byte buffer[])
throws java.io.IOException {
for (int i = 0; i < buffer.length; i++) {
int q = in.read();
if (q == -1) {
return i;
}
buffer[i] = (byte) q;
}
return buffer.length;
}
public void encode(InputStream inStream, OutputStream outStream)
throws IOException {
int j;
int numBytes;
byte tmpbuffer[] = new byte[bytesPerLine()];
encodeBufferPrefix(outStream);
while (true) {
numBytes = readFully(inStream, tmpbuffer);
if (numBytes == 0) {
break;
}
encodeLinePrefix(outStream, numBytes);
for (j = 0; j < numBytes; j += bytesPerAtom()) {
if ((j + bytesPerAtom()) <= numBytes) {
encodeAtom(outStream, tmpbuffer, j, bytesPerAtom());
} else {
encodeAtom(outStream, tmpbuffer, j, (numBytes) - j);
}
}
if (numBytes < bytesPerLine()) {
break;
} else {
encodeLineSuffix(outStream);
}
}
encodeBufferSuffix(outStream);
}
public void encode(byte aBuffer[], OutputStream aStream) throws IOException {
ByteArrayInputStream inStream = new ByteArrayInputStream(aBuffer);
encode(inStream, aStream);
}
public String encode(byte aBuffer[]) {
ByteArrayOutputStream outStream = new ByteArrayOutputStream();
ByteArrayInputStream inStream = new ByteArrayInputStream(aBuffer);
String retVal = null;
try {
encode(inStream, outStream);
// explicit ascii->unicode conversion
retVal = outStream.toString("8859_1");
} catch (Exception IOException) {
// This should never happen.
throw new Error("CharacterEncoder.encode internal error");
}
return (retVal);
}
private byte[] getBytes(ByteBuffer bb) {
byte[] buf = null;
if (bb.hasArray()) {
byte[] tmp = bb.array();
if ((tmp.length == bb.capacity()) && (tmp.length == bb.remaining())) {
buf = tmp;
bb.position(bb.limit());
}
}
if (buf == null) {
buf = new byte[bb.remaining()];
bb.get(buf);
}
return buf;
}
public void encode(ByteBuffer aBuffer, OutputStream aStream)
throws IOException {
byte[] buf = getBytes(aBuffer);
encode(buf, aStream);
}
public String encode(ByteBuffer aBuffer) {
byte[] buf = getBytes(aBuffer);
return encode(buf);
}
public void encodeBuffer(InputStream inStream, OutputStream outStream)
throws IOException {
int j;
int numBytes;
byte tmpbuffer[] = new byte[bytesPerLine()];
encodeBufferPrefix(outStream);
while (true) {
numBytes = readFully(inStream, tmpbuffer);
if (numBytes == 0) {
break;
}
encodeLinePrefix(outStream, numBytes);
for (j = 0; j < numBytes; j += bytesPerAtom()) {
if ((j + bytesPerAtom()) <= numBytes) {
encodeAtom(outStream, tmpbuffer, j, bytesPerAtom());
} else {
encodeAtom(outStream, tmpbuffer, j, (numBytes) - j);
}
}
encodeLineSuffix(outStream);
if (numBytes < bytesPerLine()) {
break;
}
}
encodeBufferSuffix(outStream);
}
public void encodeBuffer(byte aBuffer[], OutputStream aStream)
throws IOException {
ByteArrayInputStream inStream = new ByteArrayInputStream(aBuffer);
encodeBuffer(inStream, aStream);
}
public String encodeBuffer(byte aBuffer[]) {
ByteArrayOutputStream outStream = new ByteArrayOutputStream();
ByteArrayInputStream inStream = new ByteArrayInputStream(aBuffer);
try {
encodeBuffer(inStream, outStream);
} catch (Exception IOException) {
// This should never happen.
throw new Error("CharacterEncoder.encodeBuffer internal error");
}
return (outStream.toString());
}
public void encodeBuffer(ByteBuffer aBuffer, OutputStream aStream)
throws IOException {
byte[] buf = getBytes(aBuffer);
encodeBuffer(buf, aStream);
}
public String encodeBuffer(ByteBuffer aBuffer) {
byte[] buf = getBytes(aBuffer);
return encodeBuffer(buf);
}
}
| java | Apache-2.0 | f5e7a60e0c377f7420866b229a9ac79e687d5ac5 | 2026-01-05T02:42:41.143783Z | false |
ansitech/weixin4j | https://github.com/ansitech/weixin4j/blob/f5e7a60e0c377f7420866b229a9ac79e687d5ac5/src/main/java/org/weixin4j/loader/ITicketLoader.java | src/main/java/org/weixin4j/loader/ITicketLoader.java | /*
* 微信公众平台(JAVA) SDK
*
* Copyright (c) 2014, Ansitech Network Technology Co.,Ltd All rights reserved.
*
* http://www.weixin4j.org/
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.weixin4j.loader;
import org.weixin4j.model.js.Ticket;
import org.weixin4j.model.js.TicketType;
/**
* JsApiTicket加载接口
*
* @author yangqisheng
* @since 0.1.0
*/
public interface ITicketLoader {
/**
* 获取Ticket
*
* @param ticketType 临时凭证类型
* @see org.weixin4j.model.js.TicketType
* @return 有效的ticket,若返回""或null,则触发重新从微信请求Ticket的方法refresh
*/
Ticket get(TicketType ticketType);
/**
* 刷新Ticket
*
* @param ticket 包含ticket数据的对象
*/
void refresh(Ticket ticket);
}
| java | Apache-2.0 | f5e7a60e0c377f7420866b229a9ac79e687d5ac5 | 2026-01-05T02:42:41.143783Z | false |
ansitech/weixin4j | https://github.com/ansitech/weixin4j/blob/f5e7a60e0c377f7420866b229a9ac79e687d5ac5/src/main/java/org/weixin4j/loader/ITokenLoader.java | src/main/java/org/weixin4j/loader/ITokenLoader.java | /*
* 微信公众平台(JAVA) SDK
*
* Copyright (c) 2014, Ansitech Network Technology Co.,Ltd All rights reserved.
*
* http://www.weixin4j.org/
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.weixin4j.loader;
import org.weixin4j.model.base.Token;
/**
* AccessToken加载接口
*
* @author yangqisheng
* @since 0.1.0
*/
public interface ITokenLoader {
/**
* 获取access_token
*
* @return 包含access_token数据的对象
*/
public Token get();
/**
* 刷新access_token
*
* @param accessToken 包含access_token数据的对象
*/
public void refresh(Token accessToken);
}
| java | Apache-2.0 | f5e7a60e0c377f7420866b229a9ac79e687d5ac5 | 2026-01-05T02:42:41.143783Z | false |
ansitech/weixin4j | https://github.com/ansitech/weixin4j/blob/f5e7a60e0c377f7420866b229a9ac79e687d5ac5/src/main/java/org/weixin4j/loader/DefaultTicketLoader.java | src/main/java/org/weixin4j/loader/DefaultTicketLoader.java | /*
* 微信公众平台(JAVA) SDK
*
* Copyright (c) 2014, Ansitech Network Technology Co.,Ltd All rights reserved.
*
* http://www.weixin4j.org/
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.weixin4j.loader;
import java.util.EnumMap;
import java.util.Map;
import org.apache.commons.lang.StringUtils;
import org.weixin4j.model.js.Ticket;
import org.weixin4j.model.js.TicketType;
/**
* 内存式Ticket存储器
*
* 单项目时使用(生产环境不推荐)
*
* @author yangqisheng
* @since 0.1.0
*/
public class DefaultTicketLoader implements ITicketLoader {
private final Map<TicketType, Ticket> tickets = new EnumMap<TicketType, Ticket>(TicketType.class);
@Override
public Ticket get(TicketType ticketType) {
Ticket ticket = tickets.get(ticketType);
return (ticket == null
|| StringUtils.isEmpty(ticket.getTicket())
|| ticket.isExprexpired()) ? null : ticket;
}
@Override
public void refresh(Ticket ticket) {
tickets.put(ticket.getTicketType(), ticket);
}
}
| java | Apache-2.0 | f5e7a60e0c377f7420866b229a9ac79e687d5ac5 | 2026-01-05T02:42:41.143783Z | false |
ansitech/weixin4j | https://github.com/ansitech/weixin4j/blob/f5e7a60e0c377f7420866b229a9ac79e687d5ac5/src/main/java/org/weixin4j/loader/DefaultTokenLoader.java | src/main/java/org/weixin4j/loader/DefaultTokenLoader.java | /*
* 微信公众平台(JAVA) SDK
*
* Copyright (c) 2014, Ansitech Network Technology Co.,Ltd All rights reserved.
*
* http://www.weixin4j.org/
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.weixin4j.loader;
import org.weixin4j.model.base.Token;
import org.apache.commons.lang.StringUtils;
/**
* 内存式AccessToken存储器
*
* 单项目时使用(生产环境不推荐)
*
* @author yangqisheng
* @since 0.1.0
*/
public class DefaultTokenLoader implements ITokenLoader {
/**
* AccessToken对象
*/
private Token token = null;
@Override
public Token get() {
return (token == null
|| StringUtils.isEmpty(token.getAccess_token())
|| token.isExprexpired()) ? null : token;
}
@Override
public void refresh(Token token) {
if (null == token || StringUtils.isEmpty(token.getAccess_token())) {
throw new IllegalStateException("access_token is null or empty");
}
if (token.getCreate_time() <= 0) {
throw new IllegalStateException("createtime can not be zero");
}
if (token.isExprexpired()) {
throw new IllegalStateException("access_token is exprexpired");
}
this.token = token;
}
}
| java | Apache-2.0 | f5e7a60e0c377f7420866b229a9ac79e687d5ac5 | 2026-01-05T02:42:41.143783Z | false |
ansitech/weixin4j | https://github.com/ansitech/weixin4j/blob/f5e7a60e0c377f7420866b229a9ac79e687d5ac5/src/main/java/org/weixin4j/spi/IEventMessageHandler.java | src/main/java/org/weixin4j/spi/IEventMessageHandler.java | /*
* 微信公众平台(JAVA) SDK
*
* Copyright (c) 2014, Ansitech Network Technology Co.,Ltd All rights reserved.
*
* http://www.weixin4j.org/
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.weixin4j.spi;
import org.weixin4j.model.message.event.SubscribeEventMessage;
import org.weixin4j.model.message.event.UnSubscribeEventMessage;
import org.weixin4j.model.message.OutputMessage;
import org.weixin4j.model.message.event.ClickEventMessage;
import org.weixin4j.model.message.event.LocationEventMessage;
import org.weixin4j.model.message.event.LocationSelectEventMessage;
import org.weixin4j.model.message.event.PicPhotoOrAlbumEventMessage;
import org.weixin4j.model.message.event.PicSysPhotoEventMessage;
import org.weixin4j.model.message.event.PicWeixinEventMessage;
import org.weixin4j.model.message.event.QrsceneScanEventMessage;
import org.weixin4j.model.message.event.QrsceneSubscribeEventMessage;
import org.weixin4j.model.message.event.ScanCodePushEventMessage;
import org.weixin4j.model.message.event.ScanCodeWaitMsgEventMessage;
import org.weixin4j.model.message.event.ViewEventMessage;
/**
* 接收事件推送
*
* @author yangqisheng
* @since 0.0.6
*/
public interface IEventMessageHandler {
/**
* 关注事件
*
* @param msg 接受消息对象
* @return 输出消息对象
*/
public OutputMessage subscribe(SubscribeEventMessage msg);
/**
* 取消关注事件
*
* @param msg 接受消息对象
* @return 输出消息对象
*/
public OutputMessage unSubscribe(UnSubscribeEventMessage msg);
/**
* 用户未关注,扫描带参数二维码事件
*
* @param msg 接受消息对象
* @return 输出消息对象
*/
public OutputMessage qrsceneSubscribe(QrsceneSubscribeEventMessage msg);
/**
* 用户已关注,扫描带参数二维码事件
*
* @param msg 接受消息对象
* @return 输出消息对象
*/
public OutputMessage qrsceneScan(QrsceneScanEventMessage msg);
/**
* 上报地理位置事件
*
* @param msg 接受消息对象
* @return 输出消息对象
*/
public OutputMessage location(LocationEventMessage msg);
/**
* 自定义菜单事件,点击菜单拉取消息时的事件推送
*
* @param msg 接受消息对象
* @return 输出消息对象
*/
public OutputMessage click(ClickEventMessage msg);
/**
* 自定义菜单事件,点击菜单跳转链接时的事件推送
*
* @param msg 接受消息对象
* @return 输出消息对象
*/
public OutputMessage view(ViewEventMessage msg);
/**
* 自定义菜单事件,扫码推事件的事件推送
*
* @param msg 接受消息对象
* @return 输出消息对象
*/
public OutputMessage scanCodePush(ScanCodePushEventMessage msg);
/**
* 自定义菜单事件,扫码推事件的事件推送
*
* @param msg 接受消息对象
* @return 输出消息对象
*/
public OutputMessage scanCodeWaitMsg(ScanCodeWaitMsgEventMessage msg);
/**
* 自定义菜单事件,弹出系统拍照发图的事件推送
*
* @param msg 接受消息对象
* @return 输出消息对象
*/
public OutputMessage picSysPhoto(PicSysPhotoEventMessage msg);
/**
* 自定义菜单事件,弹出拍照或者相册发图的事件推送
*
* @param msg 接受消息对象
* @return 输出消息对象
*/
public OutputMessage picPhotoOrAlbum(PicPhotoOrAlbumEventMessage msg);
/**
* 自定义菜单事件,弹出微信相册发图器的事件推送
*
* @param msg 接受消息对象
* @return 输出消息对象
*/
public OutputMessage picWeixin(PicWeixinEventMessage msg);
/**
* 自定义菜单事件,弹出地理位置选择器的事件推送
*
* @param msg 接受消息对象
* @return 输出消息对象
*/
public OutputMessage locationSelect(LocationSelectEventMessage msg);
}
| java | Apache-2.0 | f5e7a60e0c377f7420866b229a9ac79e687d5ac5 | 2026-01-05T02:42:41.143783Z | false |
ansitech/weixin4j | https://github.com/ansitech/weixin4j/blob/f5e7a60e0c377f7420866b229a9ac79e687d5ac5/src/main/java/org/weixin4j/spi/IMessageHandler.java | src/main/java/org/weixin4j/spi/IMessageHandler.java | /*
* 微信公众平台(JAVA) SDK
*
* Copyright (c) 2014, Ansitech Network Technology Co.,Ltd All rights reserved.
*
* http://www.weixin4j.org/
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.weixin4j.spi;
import javax.servlet.ServletInputStream;
import org.weixin4j.WeixinException;
/**
* 输入消息处理器
*
* @author yangqisheng
* @since 0.0.6
*/
public interface IMessageHandler {
/**
* 微信输入消息处理器
*
* @param inputStream 输入流
* @return 返回xml格式的回复消息
* @throws org.weixin4j.WeixinException 微信操作异常
*/
String invoke(ServletInputStream inputStream) throws WeixinException;
/**
* 微信输入消息处理器
*
* @param inputXml 输入xml
* @return 返回xml格式的回复消息
* @throws org.weixin4j.WeixinException 微信操作异常
*/
String invoke(String inputXml) throws WeixinException;
}
| java | Apache-2.0 | f5e7a60e0c377f7420866b229a9ac79e687d5ac5 | 2026-01-05T02:42:41.143783Z | false |
ansitech/weixin4j | https://github.com/ansitech/weixin4j/blob/f5e7a60e0c377f7420866b229a9ac79e687d5ac5/src/main/java/org/weixin4j/spi/HandlerFactory.java | src/main/java/org/weixin4j/spi/HandlerFactory.java | /*
* 微信公众平台(JAVA) SDK
*
* Copyright (c) 2014, Ansitech Network Technology Co.,Ltd All rights reserved.
*
* http://www.weixin4j.org/
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.weixin4j.spi;
import org.weixin4j.Configuration;
/**
* 输入消息处理器工具类
*
* @author yangqisheng
* @since 0.0.6
*/
public class HandlerFactory {
private static IMessageHandler messageHandler = null;
private static String defaultHandler = "org.weixin4j.spi.DefaultMessageHandler";
public static IMessageHandler getMessageHandler() {
if (messageHandler == null) {
try {
//获取
defaultHandler = Configuration.getProperty("weixin4j.handler", defaultHandler);
if (Configuration.isDebug()) {
System.out.println("微信输入消息处理Hanler:" + defaultHandler);
}
// 加载处理器
Class<?> clazz = Class.forName(defaultHandler);
try {
messageHandler = (IMessageHandler) clazz.newInstance();
} catch (Exception ex) {
System.out.println("初始化 IMessageHandler 异常:");
ex.printStackTrace();
}
} catch (ClassNotFoundException ex) {
System.out.println("找不到: " + defaultHandler + " 类!");
ex.printStackTrace();
}
}
return messageHandler;
}
private static INormalMessageHandler normalMessageHandler = null;
private static String defaultNormalHandler = "org.weixin4j.spi.DefaultNormalMessageHandler";
public static INormalMessageHandler getNormalMessageHandler() {
if (normalMessageHandler == null) {
try {
//获取
defaultNormalHandler = Configuration.getProperty("weixin4j.message.handler.normal", defaultNormalHandler);
if (Configuration.isDebug()) {
System.out.println("微信接受消息处理Hanler:" + defaultNormalHandler);
}
// 加载处理器
Class<?> clazz = Class.forName(defaultNormalHandler);
try {
normalMessageHandler = (INormalMessageHandler) clazz.newInstance();
} catch (Exception ex) {
System.out.println("初始化 INormalMessageHandler 异常:");
ex.printStackTrace();
}
} catch (ClassNotFoundException ex) {
System.out.println("找不到: " + defaultNormalHandler + " 类!");
ex.printStackTrace();
}
}
return normalMessageHandler;
}
private static IEventMessageHandler eventMessageHandler = null;
private static String defaultEventHandler = "org.weixin4j.spi.DefaultEventMessageHandler";
public static IEventMessageHandler getEventMessageHandler() {
if (eventMessageHandler == null) {
try {
//获取
defaultEventHandler = Configuration.getProperty("weixin4j.message.handler.event", defaultEventHandler);
if (Configuration.isDebug()) {
System.out.println("微信接受消息处理Hanler:" + defaultEventHandler);
}
// 加载处理器
Class<?> clazz = Class.forName(defaultEventHandler);
try {
eventMessageHandler = (IEventMessageHandler) clazz.newInstance();
} catch (Exception ex) {
System.out.println("初始化 IEventMessageHandler 异常:");
ex.printStackTrace();
}
} catch (ClassNotFoundException ex) {
System.out.println("找不到: " + defaultEventHandler + " 类!");
ex.printStackTrace();
}
}
return eventMessageHandler;
}
}
| java | Apache-2.0 | f5e7a60e0c377f7420866b229a9ac79e687d5ac5 | 2026-01-05T02:42:41.143783Z | false |
ansitech/weixin4j | https://github.com/ansitech/weixin4j/blob/f5e7a60e0c377f7420866b229a9ac79e687d5ac5/src/main/java/org/weixin4j/spi/DefaultEventMessageHandler.java | src/main/java/org/weixin4j/spi/DefaultEventMessageHandler.java | /*
* 微信公众平台(JAVA) SDK
*
* Copyright (c) 2014, Ansitech Network Technology Co.,Ltd All rights reserved.
*
* http://www.weixin4j.org/
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.weixin4j.spi;
import org.weixin4j.model.message.OutputMessage;
import org.weixin4j.model.message.event.ClickEventMessage;
import org.weixin4j.model.message.event.EventMessage;
import org.weixin4j.model.message.event.LocationEventMessage;
import org.weixin4j.model.message.event.LocationSelectEventMessage;
import org.weixin4j.model.message.event.PicPhotoOrAlbumEventMessage;
import org.weixin4j.model.message.event.PicSysPhotoEventMessage;
import org.weixin4j.model.message.event.PicWeixinEventMessage;
import org.weixin4j.model.message.event.QrsceneScanEventMessage;
import org.weixin4j.model.message.event.QrsceneSubscribeEventMessage;
import org.weixin4j.model.message.event.ScanCodePushEventMessage;
import org.weixin4j.model.message.event.ScanCodeWaitMsgEventMessage;
import org.weixin4j.model.message.event.SubscribeEventMessage;
import org.weixin4j.model.message.event.UnSubscribeEventMessage;
import org.weixin4j.model.message.event.ViewEventMessage;
import org.weixin4j.model.message.output.TextOutputMessage;
/**
* 默认事件消息处理器
*
* @author yangqisheng
* @since 0.0.6
*/
public class DefaultEventMessageHandler implements IEventMessageHandler {
private OutputMessage allType(EventMessage msg) {
TextOutputMessage out = new TextOutputMessage();
out.setContent("你的消息已经收到!");
return out;
}
@Override
public OutputMessage subscribe(SubscribeEventMessage msg) {
return allType(msg);
}
@Override
public OutputMessage unSubscribe(UnSubscribeEventMessage msg) {
return allType(msg);
}
@Override
public OutputMessage qrsceneSubscribe(QrsceneSubscribeEventMessage msg) {
return allType(msg);
}
@Override
public OutputMessage qrsceneScan(QrsceneScanEventMessage msg) {
return allType(msg);
}
@Override
public OutputMessage location(LocationEventMessage msg) {
return allType(msg);
}
@Override
public OutputMessage click(ClickEventMessage msg) {
return allType(msg);
}
@Override
public OutputMessage view(ViewEventMessage msg) {
return allType(msg);
}
@Override
public OutputMessage scanCodePush(ScanCodePushEventMessage msg) {
return allType(msg);
}
@Override
public OutputMessage scanCodeWaitMsg(ScanCodeWaitMsgEventMessage msg) {
return allType(msg);
}
@Override
public OutputMessage picSysPhoto(PicSysPhotoEventMessage msg) {
return allType(msg);
}
@Override
public OutputMessage picPhotoOrAlbum(PicPhotoOrAlbumEventMessage msg) {
return allType(msg);
}
@Override
public OutputMessage picWeixin(PicWeixinEventMessage msg) {
return allType(msg);
}
@Override
public OutputMessage locationSelect(LocationSelectEventMessage msg) {
return allType(msg);
}
}
| java | Apache-2.0 | f5e7a60e0c377f7420866b229a9ac79e687d5ac5 | 2026-01-05T02:42:41.143783Z | false |
ansitech/weixin4j | https://github.com/ansitech/weixin4j/blob/f5e7a60e0c377f7420866b229a9ac79e687d5ac5/src/main/java/org/weixin4j/spi/DefaultNormalMessageHandler.java | src/main/java/org/weixin4j/spi/DefaultNormalMessageHandler.java | /*
* 微信公众平台(JAVA) SDK
*
* Copyright (c) 2014, Ansitech Network Technology Co.,Ltd All rights reserved.
*
* http://www.weixin4j.org/
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.weixin4j.spi;
import org.weixin4j.model.message.normal.TextInputMessage;
import org.weixin4j.model.message.normal.ImageInputMessage;
import org.weixin4j.model.message.normal.LinkInputMessage;
import org.weixin4j.model.message.normal.LocationInputMessage;
import org.weixin4j.model.message.normal.NormalMessage;
import org.weixin4j.model.message.normal.ShortVideoInputMessage;
import org.weixin4j.model.message.normal.VideoInputMessage;
import org.weixin4j.model.message.normal.VoiceInputMessage;
import org.weixin4j.model.message.OutputMessage;
import org.weixin4j.model.message.output.TextOutputMessage;
/**
* <p>
* Title: 微信公众平台接受消息处理器</p>
*
* <p>
* Description: 此消息处理器只负责接收消息和返回已收到消息的功能,无特殊功能。</p>
*
* @author yangqisheng
* @since 0.0.6
*/
public class DefaultNormalMessageHandler implements INormalMessageHandler {
private OutputMessage allType(NormalMessage msg) {
TextOutputMessage out = new TextOutputMessage();
out.setContent("你的消息已经收到!");
return out;
}
@Override
public OutputMessage textTypeMsg(TextInputMessage msg) {
return allType(msg);
}
@Override
public OutputMessage imageTypeMsg(ImageInputMessage msg) {
return allType(msg);
}
@Override
public OutputMessage voiceTypeMsg(VoiceInputMessage msg) {
return allType(msg);
}
@Override
public OutputMessage videoTypeMsg(VideoInputMessage msg) {
return allType(msg);
}
@Override
public OutputMessage shortvideoTypeMsg(ShortVideoInputMessage msg) {
return allType(msg);
}
@Override
public OutputMessage locationTypeMsg(LocationInputMessage msg) {
return allType(msg);
}
@Override
public OutputMessage linkTypeMsg(LinkInputMessage msg) {
return allType(msg);
}
}
| java | Apache-2.0 | f5e7a60e0c377f7420866b229a9ac79e687d5ac5 | 2026-01-05T02:42:41.143783Z | false |
ansitech/weixin4j | https://github.com/ansitech/weixin4j/blob/f5e7a60e0c377f7420866b229a9ac79e687d5ac5/src/main/java/org/weixin4j/spi/DefaultMessageHandler.java | src/main/java/org/weixin4j/spi/DefaultMessageHandler.java | /*
* 微信公众平台(JAVA) SDK
*
* Copyright (c) 2014, Ansitech Network Technology Co.,Ltd All rights reserved.
*
* http://www.weixin4j.org/
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.weixin4j.spi;
import org.weixin4j.model.message.InputMessage;
import java.io.IOException;
import java.io.StringReader;
import java.util.Date;
import javax.servlet.ServletInputStream;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.Unmarshaller;
import org.weixin4j.Configuration;
import org.weixin4j.WeixinException;
import org.weixin4j.model.message.EventType;
import org.weixin4j.model.message.MsgType;
import org.weixin4j.model.message.OutputMessage;
import org.weixin4j.util.XStreamFactory;
/**
* 默认消息处理器
*
* @author yangqisheng
* @since 0.0.1
*/
public class DefaultMessageHandler implements IMessageHandler {
private final IEventMessageHandler eventMsgHandler;
private final INormalMessageHandler normalMsgHandler;
public DefaultMessageHandler() {
//获取普通消息处理工具类
normalMsgHandler = HandlerFactory.getNormalMessageHandler();
//获取消息处理工具类
eventMsgHandler = HandlerFactory.getEventMessageHandler();
}
/**
* 带参构造,外部传入消息处理类
*
* @param normalMsgHandler 普通消息处理类
* @param eventMsgHandler 事件消息处理类
* @since 0.1.3
*/
public DefaultMessageHandler(INormalMessageHandler normalMsgHandler, IEventMessageHandler eventMsgHandler) {
this.normalMsgHandler = normalMsgHandler;
this.eventMsgHandler = eventMsgHandler;
}
@Override
public String invoke(ServletInputStream inputStream) throws WeixinException {
try {
//将输入流转换为字符串
String xmlMsg = XStreamFactory.inputStream2String(inputStream);
if (Configuration.isDebug()) {
System.out.println("获取POST的消息:");
System.out.println(xmlMsg);
System.out.println("------------------------");
}
return this.invoke(xmlMsg);
} catch (IOException ex) {
throw new WeixinException("输入流转换错误:", ex);
}
}
@Override
public String invoke(String inputXml) throws WeixinException {
//输出消息对象
OutputMessage outputMsg = null;
try {
JAXBContext context = JAXBContext.newInstance(InputMessage.class);
Unmarshaller unmarshaller = context.createUnmarshaller();
InputMessage inputMsg = (InputMessage) unmarshaller.unmarshal(new StringReader(inputXml));
if (Configuration.isDebug()) {
System.out.println("将指定节点下的xml节点数据转换为对象成功!");
}
// 取得消息类型
String msgType = inputMsg.getMsgType();
if (Configuration.isDebug()) {
System.out.println("POST的消息类型:[" + msgType + "]");
}
if (msgType.equals(MsgType.Text.toString())) {
//处理文本消息
outputMsg = normalMsgHandler.textTypeMsg(inputMsg.toTextInputMessage());
} else if (msgType.equals(MsgType.Image.toString())) {
//处理图片消息
outputMsg = normalMsgHandler.imageTypeMsg(inputMsg.toImageInputMessage());
} else if (msgType.equals(MsgType.Voice.toString())) {
//处理语音消息
outputMsg = normalMsgHandler.voiceTypeMsg(inputMsg.toVoiceInputMessage());
} else if (msgType.equals(MsgType.Video.toString())) {
//处理视频消息
outputMsg = normalMsgHandler.videoTypeMsg(inputMsg.toVideoInputMessage());
} else if (msgType.equals(MsgType.ShortVideo.toString())) {
//处理小视频消息
outputMsg = normalMsgHandler.shortvideoTypeMsg(inputMsg.toShortVideoInputMessage());
} else if (msgType.equals(MsgType.Location.toString())) {
//处理地理位置消息
outputMsg = normalMsgHandler.locationTypeMsg(inputMsg.toLocationInputMessage());
} else if (msgType.equals(MsgType.Link.toString())) {
//处理链接消息
outputMsg = normalMsgHandler.linkTypeMsg(inputMsg.toLinkInputMessage());
} else if (msgType.equals(MsgType.Event.toString())) {
//获取事件类型
String event = inputMsg.getEvent();
//自定义菜单事件
if (event.equals(EventType.Click.toString())) {
//点击菜单拉取消息时的事件推送
outputMsg = eventMsgHandler.click(inputMsg.toClickEventMessage());
} else if (event.equals(EventType.View.toString())) {
//点击菜单跳转链接时的事件推送
outputMsg = eventMsgHandler.view(inputMsg.toViewEventMessage());
} else if (event.equals(EventType.Subscribe.toString())) {
//获取事件KEY值,判断是否关注
String eventKey = inputMsg.getEventKey();
if (eventKey != null && eventKey.startsWith("qrscene_")) {
//用户未关注时,进行关注后的事件推送
outputMsg = eventMsgHandler.qrsceneSubscribe(inputMsg.toQrsceneSubscribeEventMessage());
} else {
//关注事件
outputMsg = eventMsgHandler.subscribe(inputMsg.toSubscribeEventMessage());
}
} else if (event.equals(EventType.Unsubscribe.toString())) {
//取消关注事件
outputMsg = eventMsgHandler.unSubscribe(inputMsg.toUnSubscribeEventMessage());
} else if (event.equals(EventType.Scan.toString())) {
//扫描带参数二维码事件
outputMsg = eventMsgHandler.qrsceneScan(inputMsg.toQrsceneScanEventMessage());
} else if (event.equals(EventType.Location.toString())) {
//上报地理位置事件
outputMsg = eventMsgHandler.location(inputMsg.toLocationEventMessage());
} else if (event.equals(EventType.Scancode_Push.toString())) {
//扫码推事件的事件推送
outputMsg = eventMsgHandler.scanCodePush(inputMsg.toScanCodePushEventMessage());
} else if (event.equals(EventType.Scancode_Waitmsg.toString())) {
//扫码推事件且弹出“消息接收中”提示框的事件推送
outputMsg = eventMsgHandler.scanCodeWaitMsg(inputMsg.toScanCodeWaitMsgEventMessage());
} else if (event.equals(EventType.Pic_Sysphoto.toString())) {
//弹出系统拍照发图的事件推送
outputMsg = eventMsgHandler.picSysPhoto(inputMsg.toPicSysPhotoEventMessage());
} else if (event.equals(EventType.Pic_Photo_OR_Album.toString())) {
//弹出拍照或者相册发图的事件推送
outputMsg = eventMsgHandler.picPhotoOrAlbum(inputMsg.toPicPhotoOrAlbumEventMessage());
} else if (event.equals(EventType.Pic_Weixin.toString())) {
//弹出微信相册发图器的事件推送
outputMsg = eventMsgHandler.picWeixin(inputMsg.toPicWeixinEventMessage());
} else if (event.equals(EventType.Location_Select.toString())) {
//弹出地理位置选择器的事件推送
outputMsg = eventMsgHandler.locationSelect(inputMsg.toLocationSelectEventMessage());
}
}
if (outputMsg != null) {
//设置收件人消息
setOutputMsgInfo(outputMsg, inputMsg);
}
} catch (IOException ex) {
throw new WeixinException("输入流转换错误:", ex);
} catch (NoSuchMethodException ex) {
throw new WeixinException("没有找打对应方法:", ex);
} catch (SecurityException ex) {
throw new WeixinException("安全错误:", ex);
} catch (Exception ex) {
throw new WeixinException("系统错误:", ex);
}
if (outputMsg != null) {
try {
// 把发送发送对象转换为xml输出
String xml = outputMsg.toXML();
if (Configuration.isDebug()) {
System.out.println("POST输出消息:");
System.out.println(xml);
System.out.println("------------------------");
}
return xml;
} catch (Exception ex) {
throw new WeixinException("转换回复消息为xml时错误:", ex);
}
}
return "";
}
//设置详细信息
private static void setOutputMsgInfo(OutputMessage oms, InputMessage msg) throws Exception {
// 设置发送信息
oms.setCreateTime(System.currentTimeMillis());
oms.setToUserName(msg.getFromUserName());
oms.setFromUserName(msg.getToUserName());
}
}
| java | Apache-2.0 | f5e7a60e0c377f7420866b229a9ac79e687d5ac5 | 2026-01-05T02:42:41.143783Z | false |
ansitech/weixin4j | https://github.com/ansitech/weixin4j/blob/f5e7a60e0c377f7420866b229a9ac79e687d5ac5/src/main/java/org/weixin4j/spi/INormalMessageHandler.java | src/main/java/org/weixin4j/spi/INormalMessageHandler.java | /*
* 微信公众平台(JAVA) SDK
*
* Copyright (c) 2014, Ansitech Network Technology Co.,Ltd All rights reserved.
*
* http://www.weixin4j.org/
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.weixin4j.spi;
import org.weixin4j.model.message.normal.TextInputMessage;
import org.weixin4j.model.message.normal.ImageInputMessage;
import org.weixin4j.model.message.normal.LinkInputMessage;
import org.weixin4j.model.message.normal.LocationInputMessage;
import org.weixin4j.model.message.normal.ShortVideoInputMessage;
import org.weixin4j.model.message.normal.VideoInputMessage;
import org.weixin4j.model.message.normal.VoiceInputMessage;
import org.weixin4j.model.message.OutputMessage;
/**
* <p>
* Title: 微信公众平台接受消息处理器</p>
*
* <p>
* Description: 接受消息分8类,普通消息(1.文本消息、2.图片消息、3.语音消息
* 、4.视频消息、5.地理位置消息、6.链接消息)
* 事件推送(1.关注/取消关注事件、2.扫描带二维码参数事件、3.上报地理位置事件、4.自定义
* 菜单事件、5.点击菜单拉取消息时事件推送、6.点击菜单跳转链接时的事件推送</p>
*
* @author yangqisheng
* @since 0.0.6
*/
public interface INormalMessageHandler {
/**
* 文字内容的消息处理
*
* @param msg 接受消息对象
* @return 输出消息对象
*/
public OutputMessage textTypeMsg(TextInputMessage msg);
/**
* 图片类型的消息处理
*
* @param msg 接受消息对象
* @return 输出消息对象
*/
public OutputMessage imageTypeMsg(ImageInputMessage msg);
/**
* 语音类型的消息处理
*
* @param msg 接受消息对象
* @return 输出消息对象
*/
public OutputMessage voiceTypeMsg(VoiceInputMessage msg);
/**
* 视频类型的消息处理
*
* @param msg 接受消息对象
* @return 输出消息对象
*/
public OutputMessage videoTypeMsg(VideoInputMessage msg);
/**
* 小视频类型的消息处理
*
* @param msg 接受消息对象
* @return 输出消息对象
*/
public OutputMessage shortvideoTypeMsg(ShortVideoInputMessage msg);
/**
* 地理位置类型的消息处理
*
* @param msg 接受消息对象
* @return 输出消息对象
*/
public OutputMessage locationTypeMsg(LocationInputMessage msg);
/**
* 链接类型的消息处理
*
* @param msg 接受消息对象
* @return 输出消息对象
*/
public OutputMessage linkTypeMsg(LinkInputMessage msg);
}
| java | Apache-2.0 | f5e7a60e0c377f7420866b229a9ac79e687d5ac5 | 2026-01-05T02:42:41.143783Z | false |
ansitech/weixin4j | https://github.com/ansitech/weixin4j/blob/f5e7a60e0c377f7420866b229a9ac79e687d5ac5/src/main/java/org/weixin4j/model/base/Token.java | src/main/java/org/weixin4j/model/base/Token.java | /*
* 微信公众平台(JAVA) SDK
*
* Copyright (c) 2014, Ansitech Network Technology Co.,Ltd All rights reserved.
*
* http://www.weixin4j.org/
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.weixin4j.model.base;
import com.alibaba.fastjson.JSONObject;
import org.weixin4j.WeixinException;
import java.io.Serializable;
import java.util.Date;
import org.weixin4j.http.Response;
/**
* 微信平台用户凭证对象
*
* <p>
* 通过<tt>Weixin</tt>产生一个请求对象,对应生成一个<tt>HttpClient</tt>,
* 每次登陆产生一个<tt>OAuth</tt>用户连接,使用<tt>OAuthToken</tt>
* 可以不用重复向微信平台发送登陆请求,在没有过期时间内,可继续请求。</p>
*
* @author yangqisheng
* @since 0.1.0
*/
public final class Token implements Serializable {
private String access_token;
private int expires_in = 7200;
private long exprexpired_time;
private long create_time;
public Token() {
}
public Token(String accessToken, int expiresIn) {
this.access_token = accessToken;
setExpires_in(expiresIn);
}
public Token(String accessToken, int expiresIn, long createTime) {
this.access_token = accessToken;
setExpires_in(expiresIn, createTime);
}
/**
* 通过输出对象,从输出对象转换为JSON对象,后获取JSON数据包
*
* <p>
* 要求输出内容为一个标准的JSON数据包,正常情况下, 微信会返回下述JSON数据包给公众号:
* {"access_token":"ACCESS_TOKEN","expires_in":7200}</p>
*
* @param response 输出对象
* @throws org.weixin4j.WeixinException 微信操作异常
*/
public Token(Response response) throws WeixinException {
this(response.asJSONObject());
}
/**
* 通过微信公众平台返回JSON对象创建凭证对象
*
* <p>
* 正常情况下,微信会返回下述JSON数据包给公众号:
* {"access_token":"ACCESS_TOKEN","expires_in":7200}</p>
*
* @param jsonObj JSON数据包
* @throws org.weixin4j.WeixinException 微信操作异常
*/
public Token(JSONObject jsonObj) throws WeixinException {
this.access_token = jsonObj.getString("access_token");
//根据当前时间的毫秒数+获取的秒数计算过期时间
int expiresIn = jsonObj.getIntValue("expires_in");
if (jsonObj.containsKey("create_time")) {
//获取创建时间
long createTime = jsonObj.getLong("create_time");
if (createTime > 0) {
//设定指定日期
setExpires_in(expiresIn, createTime);
return;
}
}
setExpires_in(expiresIn);
}
/**
* 获取用户凭证
*
* @return 用户凭证
*/
public String getAccess_token() {
return access_token;
}
/**
* 设置用户凭证
*
* @param access_token 用户凭证
*/
public void setAccess_token(String access_token) {
this.access_token = access_token;
}
/**
* 判断用户凭证是否过期
*
* @return 过期返回 true,否则返回false
*/
public boolean isExprexpired() {
Date now = new Date();
long nowLong = now.getTime();
return nowLong >= exprexpired_time;
}
/**
* 获取 凭证有效时间,单位:秒
*
* @return 凭证有效时间,单位:秒
*/
public int getExpires_in() {
return expires_in;
}
/**
* 设置 凭证有效时间,单位:秒
*
* <p>
* 为了与微信服务器保存同步,误差设置为提前1分钟,即:将创建时间提早1分钟
* </p>
*
* @param expires_in 凭证有效时间,单位:秒
*/
public void setExpires_in(int expires_in) {
this.expires_in = expires_in;
//使用当前时间记录
setExpires_in(expires_in, System.currentTimeMillis());
}
/**
* 设置 凭证有效时间,单位:秒
*
* <p>
* 为了与微信服务器保存同步,误差设置为提前1分钟,即:将创建时间提早1分钟
* </p>
*
* @param expires_in 凭证有效时间,单位:秒
* @param create_time 凭证创建时间
*/
public void setExpires_in(int expires_in, long create_time) {
this.expires_in = expires_in;
//获取当前时间毫秒数
this.create_time = create_time - 60000;
//设置下次过期时间 = 当前时间 + (凭证有效时间(秒) * 1000)
this.exprexpired_time = this.create_time + (expires_in * 1000);
}
/**
* 获取 此次凭证创建时间 单位:毫秒数
*
* @return 创建时间 毫秒数
*/
public long getCreate_time() {
return this.create_time + 60000;
}
/**
* 将数据转换为JSON数据包
*
* @return JSON数据包
*/
@Override
public String toString() {
//对外的时间 需要加上扣掉的 60秒
return "{\"access_token\":\"" + this.getAccess_token() + "\",\"expires_in\":" + this.getExpires_in() + ",\"create_time\" : " + this.getCreate_time() + "}";
}
}
| java | Apache-2.0 | f5e7a60e0c377f7420866b229a9ac79e687d5ac5 | 2026-01-05T02:42:41.143783Z | false |
ansitech/weixin4j | https://github.com/ansitech/weixin4j/blob/f5e7a60e0c377f7420866b229a9ac79e687d5ac5/src/main/java/org/weixin4j/model/user/Data.java | src/main/java/org/weixin4j/model/user/Data.java | /*
* 微信公众平台(JAVA) SDK
*
* Copyright (c) 2014, Ansitech Network Technology Co.,Ltd All rights reserved.
*
* http://www.weixin4j.org/
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.weixin4j.model.user;
import java.util.List;
/**
* 微信平台关注者openid数据对象
*
* @author yangqisheng
* @since 0.0.1
*/
public class Data {
private List<String> openid; //列表数据,OPENID的列表
public List<String> getOpenid() {
return openid;
}
public void setOpenid(List<String> openid) {
this.openid = openid;
}
}
| java | Apache-2.0 | f5e7a60e0c377f7420866b229a9ac79e687d5ac5 | 2026-01-05T02:42:41.143783Z | false |
ansitech/weixin4j | https://github.com/ansitech/weixin4j/blob/f5e7a60e0c377f7420866b229a9ac79e687d5ac5/src/main/java/org/weixin4j/model/user/User.java | src/main/java/org/weixin4j/model/user/User.java | /*
* 微信公众平台(JAVA) SDK
*
* Copyright (c) 2014, Ansitech Network Technology Co.,Ltd All rights reserved.
*
* http://www.weixin4j.org/
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.weixin4j.model.user;
/**
* 微信平台用户管理
*
* <p>
* 通过<tt>Weixin</tt>产生一个请求对象,通过<code>getUser()</code>生成一个<tt>User</tt>,
* 然后可以调用其他方法</p>
*
* @author yangqisheng
* @since 0.0.1
*/
public class User {
private String openid; //用户的标识,对当前公众号唯一
private String subscribe; //用户是否订阅该公众号标识,值为0时,代表此用户没有关注该公众号,拉取不到其余信息。
private String nickname; //用户的昵称
private int sex; //用户的性别,值为1时是男性,值为2时是女性,值为0时是未知
private String city; //用户所在城市
private String country; //用户所在国家
private String province; //用户所在省份
private String language; //用户的语言,简体中文为zh_CN
private String headimgurl; //用户头像,最后一个数值代表正方形头像大小(有0、46、64、96、132数值可选,0代表640*640正方形头像),用户没有头像时该项为空
private long subscribe_time; //用户关注时间,为时间戳。如果用户曾多次关注,则取最后关注时间
private String unionid; //只有在用户将公众号绑定到微信开放平台帐号后,才会出现该字段。
private String remark; //用户备注
private String groupid; //用户分组
private int[] tagid_list; //用户被打上的标签ID列表
private String subscribe_scene; //返回用户关注的渠道来源,ADD_SCENE_SEARCH 公众号搜索,ADD_SCENE_ACCOUNT_MIGRATION 公众号迁移,ADD_SCENE_PROFILE_CARD 名片分享,ADD_SCENE_QR_CODE 扫描二维码,ADD_SCENEPROFILE LINK 图文页内名称点击,ADD_SCENE_PROFILE_ITEM 图文页右上角菜单,ADD_SCENE_PAID 支付后关注,ADD_SCENE_OTHERS 其他
private String qr_scene; //二维码扫码场景(开发者自定义)
private String qr_scene_str; //二维码扫码场景描述(开发者自定义)
public User() {
}
/**
* 获取 用户的标识
*
* <p>
* 对当前公众号唯一</p>
*
* @return 用户的标识
*/
public String getOpenid() {
return openid;
}
/**
* 设置 用户的标识
*
* <p>
* 对当前公众号唯一</p>
*
* @param openId 用户的标识
*/
public void setOpenid(String openId) {
this.openid = openId;
}
/**
* 获取 用户是否订阅该公众号标识
*
* <p>
* 值为0时,代表此用户没有关注该公众号,拉取不到其余信息。</p>
*
* @return 用户是否订阅该公众号标识
*/
public String getSubscribe() {
return subscribe;
}
/**
* 设置 用户是否订阅该公众号标识
*
* <p>
* 值为0时,代表此用户没有关注该公众号,拉取不到其余信息。</p>
*
* @param subscribe 用户是否订阅该公众号标识
*/
public void setSubscribe(String subscribe) {
this.subscribe = subscribe;
}
/**
* 获取 用户的昵称
*
* @return 用户的昵称
*/
public String getNickname() {
return nickname;
}
/**
* 设置 用户的昵称
*
* @param nickName 用户的昵称
*/
public void setNickname(String nickName) {
this.nickname = nickName;
}
/**
* 获取 用户的性别
*
* <p>
* 值为1时是男性,值为2时是女性,值为0时是未知</p>
*
* @return 用户的性别
*/
public int getSex() {
return sex;
}
/**
* 设置 用户的性别
*
* <p>
* 值为1时是男性,值为2时是女性,值为0时是未知</p>
*
* @param sex 用户的性别
*/
public void setSex(int sex) {
this.sex = sex;
}
/**
* 获取 用户所在城市
*
* @return 用户所在城市
*/
public String getCity() {
return city;
}
/**
* 设置 用户所在城市
*
* @param city 用户所在城市
*/
public void setCity(String city) {
this.city = city;
}
/**
* 获取 用户所在国家
*
* @return 用户所在国家
*/
public String getCountry() {
return country;
}
/**
*
* 设置 用户所在国家
*
* @param country 用户所在国家
*/
public void setCountry(String country) {
this.country = country;
}
/**
*
* 获取 用户所在省份
*
* @return 用户所在省份
*/
public String getProvince() {
return province;
}
/**
*
* 设置 用户所在省份
*
* @param province 用户所在省份
*/
public void setProvince(String province) {
this.province = province;
}
/**
* 获取 用户的语言
*
* <p>
* zh_CN 简体,zh_TW 繁体,en 英语</p>
*
* @return 用户的语言
*/
public String getLanguage() {
return language;
}
/**
* 设置 用户的语言
*
* <p>
* zh_CN 简体,zh_TW 繁体,en 英语</p>
*
* @param language 用户的语言
*/
public void setLanguage(String language) {
this.language = language;
}
/**
* 获取 用户头像
*
* <p>
* 最后一个数值代表正方形头像大小(有0、46、64、96、132数值可选, <br>
* 0代表640*640正方形头像),用户没有头像时该项为空</p>
*
* @return 用户头像
*/
public String getHeadimgurl() {
return headimgurl;
}
/**
* 设置 用户头像
*
* <p>
* 最后一个数值代表正方形头像大小(有0、46、64、96、132数值可选, <br>
* 0代表640*640正方形头像),用户没有头像时该项为空</p>
*
* @param headimgUrl 用户头像
*/
public void setHeadimgurl(String headimgUrl) {
this.headimgurl = headimgUrl;
}
/**
*
* 获取 用户关注时间,为时间戳
*
* <p>
* 如果用户曾多次关注,则取最后关注时间</p>
*
* @return 用户关注时间,为时间戳
*/
public long getSubscribe_time() {
return subscribe_time;
}
/**
* 设置 用户关注时间,为时间戳
*
* @param subscribeTime 用户关注时间
*/
public void setSubscribe_time(long subscribeTime) {
this.subscribe_time = subscribeTime;
}
/**
* 获取 用户备注
*
* @return 用户备注
*/
public String getRemark() {
return remark;
}
/**
* 设置 用户备注
*
* @param remark 用户备注
*/
public void setRemark(String remark) {
this.remark = remark;
}
public String getGroupid() {
return groupid;
}
public void setGroupid(String groupid) {
this.groupid = groupid;
}
public int[] getTagid_list() {
return tagid_list;
}
public void setTagid_list(int[] tagid_list) {
this.tagid_list = tagid_list;
}
public String getUnionid() {
return unionid;
}
public void setUnionid(String unionid) {
this.unionid = unionid;
}
public String getSubscribe_scene() {
return subscribe_scene;
}
public void setSubscribe_scene(String subscribe_scene) {
this.subscribe_scene = subscribe_scene;
}
public String getQr_scene() {
return qr_scene;
}
public void setQr_scene(String qr_scene) {
this.qr_scene = qr_scene;
}
public String getQr_scene_str() {
return qr_scene_str;
}
public void setQr_scene_str(String qr_scene_str) {
this.qr_scene_str = qr_scene_str;
}
}
| java | Apache-2.0 | f5e7a60e0c377f7420866b229a9ac79e687d5ac5 | 2026-01-05T02:42:41.143783Z | false |
ansitech/weixin4j | https://github.com/ansitech/weixin4j/blob/f5e7a60e0c377f7420866b229a9ac79e687d5ac5/src/main/java/org/weixin4j/model/user/Followers.java | src/main/java/org/weixin4j/model/user/Followers.java | /*
* 微信公众平台(JAVA) SDK
*
* Copyright (c) 2014, Ansitech Network Technology Co.,Ltd All rights reserved.
*
* http://www.weixin4j.org/
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.weixin4j.model.user;
/**
* 微信平台关注者对象
*
* <p>通过<tt>Weixin</tt>产生一个请求对象,通过<code>getWeixinUser()</code>生成一个<tt>WeixinUser</tt>,
* 然后调用<tt>getUserList()</tt>,得到本对象.</p>
*
* @author yangqisheng
* @since 0.0.1
*/
public class Followers {
private int total; //关注该公众账号的总用户数
private int count; //拉取的OPENID个数,最大值为10000
private Data data; //列表数据,OPENID的列表
private String next_openid; //拉取列表的后一个用户的OPENID
/**
* @return the total
*/
public int getTotal() {
return total;
}
/**
* @param total the total to set
*/
public void setTotal(int total) {
this.total = total;
}
/**
* @return the count
*/
public int getCount() {
return count;
}
/**
* @param count the count to set
*/
public void setCount(int count) {
this.count = count;
}
/**
* @return the next_openid
*/
public String getNext_openid() {
return next_openid;
}
/**
* @param next_openid the next_openid to set
*/
public void setNext_openid(String next_openid) {
this.next_openid = next_openid;
}
/**
* @return the data
*/
public Data getData() {
return data;
}
/**
* @param data the data to set
*/
public void setData(Data data) {
this.data = data;
}
}
| java | Apache-2.0 | f5e7a60e0c377f7420866b229a9ac79e687d5ac5 | 2026-01-05T02:42:41.143783Z | false |
ansitech/weixin4j | https://github.com/ansitech/weixin4j/blob/f5e7a60e0c377f7420866b229a9ac79e687d5ac5/src/main/java/org/weixin4j/model/redpack/SendRedPackResult.java | src/main/java/org/weixin4j/model/redpack/SendRedPackResult.java | /*
* 微信公众平台(JAVA) SDK
*
* Copyright (c) 2014, Ansitech Network Technology Co.,Ltd All rights reserved.
*
* http://www.weixin4j.org/
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.weixin4j.model.redpack;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
/**
* 现金红包发放结果
*
* @author yangqisheng
* @since 0.0.4
*/
@XmlRootElement(name = "xml")
public class SendRedPackResult {
/**
* 字段名:返回状态码
*
* 必填:是
*
* 类型:String(16)
*
* 描述:SUCCESS/FAIL
*
* 此字段是通信标识,非交易标识,交易是否成功需要查看result_code来判断
*/
private String return_code;
/**
* 字段名:返回信息
*
* 必填:否
*
* 类型:String(128)
*
* 描述:返回信息,如非空,为错误原因
*
* 签名失败、参数格式校验错误等
*/
private String return_msg;
//*** 以下字段在return_code为SUCCESS的时候有返回 ***//
private String sign; //签名
private String result_code; //业务结果 SUCCESS/FAIL
private String err_code; //错误代码
private String err_code_des; //错误代码描述
//*** 以下字段在return_code 和result_code都为SUCCESS的时候有返回 ***//
private String mch_billno; //商户订单号
private String mch_id; //商户号
private String wxappid; //商户appid
private String re_openid; //用户openid
private int total_amount; //付款金额
private String send_time; //发放成功时间
private String send_listid; //微信单号
public String getReturn_code() {
return return_code;
}
@XmlElement(name = "return_code")
public void setReturn_code(String return_code) {
this.return_code = return_code;
}
public String getReturn_msg() {
return return_msg;
}
@XmlElement(name = "return_msg")
public void setReturn_msg(String return_msg) {
this.return_msg = return_msg;
}
public String getSign() {
return sign;
}
@XmlElement(name = "sign")
public void setSign(String sign) {
this.sign = sign;
}
public String getResult_code() {
return result_code;
}
@XmlElement(name = "result_code")
public void setResult_code(String result_code) {
this.result_code = result_code;
}
public String getErr_code() {
return err_code;
}
@XmlElement(name = "err_code")
public void setErr_code(String err_code) {
this.err_code = err_code;
}
public String getErr_code_des() {
return err_code_des;
}
@XmlElement(name = "err_code_des")
public void setErr_code_des(String err_code_des) {
this.err_code_des = err_code_des;
}
public String getMch_billno() {
return mch_billno;
}
@XmlElement(name = "mch_billno")
public void setMch_billno(String mch_billno) {
this.mch_billno = mch_billno;
}
public String getMch_id() {
return mch_id;
}
@XmlElement(name = "mch_id")
public void setMch_id(String mch_id) {
this.mch_id = mch_id;
}
public String getWxappid() {
return wxappid;
}
@XmlElement(name = "wxappid")
public void setWxappid(String wxappid) {
this.wxappid = wxappid;
}
public String getRe_openid() {
return re_openid;
}
@XmlElement(name = "re_openid")
public void setRe_openid(String re_openid) {
this.re_openid = re_openid;
}
public int getTotal_amount() {
return total_amount;
}
@XmlElement(name = "total_amount")
public void setTotal_amount(int total_amount) {
this.total_amount = total_amount;
}
public String getSend_time() {
return send_time;
}
@XmlElement(name = "send_time")
public void setSend_time(String send_time) {
this.send_time = send_time;
}
public String getSend_listid() {
return send_listid;
}
@XmlElement(name = "send_listid")
public void setSend_listid(String send_listid) {
this.send_listid = send_listid;
}
}
| java | Apache-2.0 | f5e7a60e0c377f7420866b229a9ac79e687d5ac5 | 2026-01-05T02:42:41.143783Z | false |
ansitech/weixin4j | https://github.com/ansitech/weixin4j/blob/f5e7a60e0c377f7420866b229a9ac79e687d5ac5/src/main/java/org/weixin4j/model/redpack/SendRedPack.java | src/main/java/org/weixin4j/model/redpack/SendRedPack.java | /*
* 微信公众平台(JAVA) SDK
*
* Copyright (c) 2014, Ansitech Network Technology Co.,Ltd All rights reserved.
*
* http://www.weixin4j.org/
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.weixin4j.model.redpack;
import java.util.HashMap;
import java.util.Map;
/**
* 现金红包对象
*
* 接口文档:https://pay.weixin.qq.com/wiki/doc/api/cash_coupon.php?chapter=13_5
*
* <p>
* 用于企业向微信用户个人发现金红包</p>
*
* <p>
* 目前支持向指定微信用户的openid发放指定金额红包。</p>
*
* <b>是否需要证书</b>
*
* 是(证书及使用说明详见https://pay.weixin.qq.com/wiki/doc/api/cash_coupon.php?chapter=4_3)
*
* @author yangqisheng
* @since 0.0.4
*/
public class SendRedPack {
/**
* 随机字符串
*
* 随机字符串,不长于32位
*/
private String nonce_str;
/**
* 签名
*
* 签名算法:https://pay.weixin.qq.com/wiki/doc/api/cash_coupon.php?chapter=4_3
*/
private String sign;
/**
* 商户订单号
*
* 商户订单号(每个订单号必须唯一)
*
* 组成:mch_id+yyyymmdd+10位一天内不能重复的数字。
*/
private String mch_billno;
/**
* 商户号
*/
private String mch_id;
/**
* 公众账号appid
*/
private String wxappid;
/**
* 提供方名称
*/
private String nick_name;
/**
* 商户名称
*
* 红包发送者名称
*/
private String send_name;
/**
* 用户openid
*
* 接受红包的用户
*
* 用户在wxappid下的openid
*/
private String re_openid;
/**
* 付款金额
*
* 付款金额,单位分
*/
private int total_amount;
/**
* 最小红包金额
*
* 最小红包金额,单位分
*/
private int min_value;
/**
* 最大红包金额
*
* 最大红包金额,单位分
*
* (最小金额等于最大金额:min_value=max_value=total_amount)
*/
private int max_value;
/**
* 红包发放总人数
*
* total_num=1
*/
private int total_num = 1;
/**
* 红包祝福语
*/
private String wishing;
/**
* Ip地址
*/
private String client_ip;
/**
* 活动名称
*/
private String act_name;
/**
* 备注
*/
private String remark;
/**
* 商户logo的url
*/
private String logo_imgurl;
public Map<String, String> toMap() {
Map<String, String> map = new HashMap<String, String>();
map.put("nonce_str", nonce_str);
map.put("mch_billno", mch_billno);
map.put("mch_id", mch_id);
map.put("wxappid", wxappid);
map.put("nick_name", nick_name);
map.put("send_name", send_name);
map.put("re_openid", re_openid);
map.put("total_amount", total_amount + "");
map.put("min_value", min_value + "");
map.put("max_value", max_value + "");
map.put("total_num", total_num + "");
map.put("wishing", wishing);
map.put("client_ip", client_ip);
map.put("act_name", act_name);
map.put("remark", remark);
return map;
}
public String toXML() {
StringBuilder sb = new StringBuilder();
sb.append("<xml>");
sb.append("<sign><![CDATA[").append(sign).append("]]></sign>");
sb.append("<mch_billno><![CDATA[").append(mch_billno).append("]]></mch_billno>");
sb.append("<mch_id><![CDATA[").append(mch_id).append("]]></mch_id>");
sb.append("<wxappid><![CDATA[").append(wxappid).append("]]></wxappid>");
sb.append("<nick_name><![CDATA[").append(nick_name).append("]]></nick_name>");
sb.append("<send_name><![CDATA[").append(send_name).append("]]></send_name>");
sb.append("<re_openid><![CDATA[").append(re_openid).append("]]></re_openid>");
sb.append("<total_amount><![CDATA[").append(total_amount).append("]]></total_amount>");
sb.append("<min_value><![CDATA[").append(min_value).append("]]></min_value>");
sb.append("<max_value><![CDATA[").append(max_value).append("]]></max_value>");
sb.append("<total_num><![CDATA[").append(total_num).append("]]></total_num>");
sb.append("<wishing><![CDATA[").append(wishing).append("]]></wishing>");
sb.append("<client_ip><![CDATA[").append(client_ip).append("]]></client_ip>");
sb.append("<act_name><![CDATA[").append(act_name).append("]]></act_name>");
// sb.append("<act_id><![CDATA[").append(act_id).append("]]></act_id>");
sb.append("<remark><![CDATA[").append(remark).append("]]></remark>");
// sb.append("<logo_imgurl><![CDATA[").append(logo_imgurl).append("]]></logo_imgurl>");
// sb.append("<share_content><![CDATA[").append(share_content).append("]]></share_content>");
// sb.append("<share_url><![CDATA[").append(share_url).append("]]></share_url>");
// sb.append("<share_imgurl><![CDATA[").append(share_imgurl).append("]]></share_imgurl>");
sb.append("<nonce_str><![CDATA[").append(nonce_str).append("]]></nonce_str>");
sb.append("</xml>");
return sb.toString();
}
public String getNonce_str() {
return nonce_str;
}
public void setNonce_str(String nonce_str) {
this.nonce_str = nonce_str;
}
public String getSign() {
return sign;
}
public void setSign(String sign) {
this.sign = sign;
}
public String getMch_billno() {
return mch_billno;
}
public void setMch_billno(String mch_billno) {
this.mch_billno = mch_billno;
}
public String getMch_id() {
return mch_id;
}
public void setMch_id(String mch_id) {
this.mch_id = mch_id;
}
public String getWxappid() {
return wxappid;
}
public void setWxappid(String wxappid) {
this.wxappid = wxappid;
}
public String getNick_name() {
return nick_name;
}
@Deprecated
public void setNick_name(String nick_name) {
this.nick_name = nick_name;
}
public String getSend_name() {
return send_name;
}
public void setSend_name(String send_name) {
this.send_name = send_name;
}
public String getRe_openid() {
return re_openid;
}
public void setRe_openid(String re_openid) {
this.re_openid = re_openid;
}
public int getTotal_amount() {
return total_amount;
}
public void setTotal_amount(int total_amount) {
this.total_amount = total_amount;
this.min_value = total_amount;
this.max_value = total_amount;
}
//
// public int getMin_value() {
// return min_value;
// }
//
// public void setMin_value(int min_value) {
// this.min_value = min_value;
// }
//
// public int getMax_value() {
// return max_value;
// }
//
// public void setMax_value(int max_value) {
// this.max_value = max_value;
// }
//
// public int getTotal_num() {
// return total_num;
// }
//
// public void setTotal_num(int total_num) {
// this.total_num = total_num;
// }
public String getWishing() {
return wishing;
}
public void setWishing(String wishing) {
this.wishing = wishing;
}
public String getClient_ip() {
return client_ip;
}
public void setClient_ip(String client_ip) {
this.client_ip = client_ip;
}
public String getAct_name() {
return act_name;
}
public void setAct_name(String act_name) {
this.act_name = act_name;
}
public String getRemark() {
return remark;
}
public void setRemark(String remark) {
this.remark = remark;
}
//
// public String getLogo_imgurl() {
// return logo_imgurl;
// }
//
// public void setLogo_imgurl(String logo_imgurl) {
// this.logo_imgurl = logo_imgurl;
// }
}
| java | Apache-2.0 | f5e7a60e0c377f7420866b229a9ac79e687d5ac5 | 2026-01-05T02:42:41.143783Z | false |
ansitech/weixin4j | https://github.com/ansitech/weixin4j/blob/f5e7a60e0c377f7420866b229a9ac79e687d5ac5/src/main/java/org/weixin4j/model/pay/UnifiedOrder.java | src/main/java/org/weixin4j/model/pay/UnifiedOrder.java | /*
* 微信公众平台(JAVA) SDK
*
* Copyright (c) 2014, Ansitech Network Technology Co.,Ltd All rights reserved.
*
* http://www.weixin4j.org/
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.weixin4j.model.pay;
import java.util.HashMap;
import java.util.Map;
/**
* 统一下单
*
* 接口文档:http://pay.weixin.qq.com/wiki/doc/api/index.php?chapter=9_1
*
* <b>应用场景</b>
*
* 除被扫支付场景以外,商户系统先调用该接口在微信支付服务后台生成预支付交易单,返回正确的预支付交易回话标识后再按扫码、JSAPI、APP等不同场景生成交易串调起支付。
*
* <b>是否需要证书</b>
*
* 不需要
*
* @author yangqisheng
* @since 0.0.4
*/
public class UnifiedOrder {
private String appid; //公众账号ID
private String mch_id; //商户号
private String nonce_str; //随机字符串
private String sign; //签名
private String body; //商品描述
private String out_trade_no; //商户订单号
private String total_fee; //总金额
private String spbill_create_ip; //终端IP
private String notify_url; //通知地址
private String trade_type; //交易类型 取值如下:JSAPI,NATIVE,APP
private String product_id; //商品ID,trade_type=NATIVE时,此参数必传。此id为二维码中包含的商品ID,商户自行定义。
private String openid; //用户标识
public Map<String, String> toMap() {
Map<String, String> map = new HashMap<String, String>();
map.put("appid", appid);
map.put("body", body);
map.put("mch_id", mch_id);
map.put("nonce_str", nonce_str);
map.put("notify_url", notify_url);
if ("JSAPI".equals(trade_type)) {
map.put("openid", openid);
}
map.put("out_trade_no", out_trade_no);
if ("NATIVE".equals(trade_type)) {
map.put("product_id", product_id);
}
map.put("spbill_create_ip", spbill_create_ip);
map.put("total_fee", total_fee);
map.put("trade_type", trade_type);
return map;
}
public String toXML() {
StringBuilder sb = new StringBuilder();
sb.append("<xml>");
sb.append("<appid><![CDATA[").append(appid).append("]]></appid>");
sb.append("<body><![CDATA[").append(body).append("]]></body>");
sb.append("<mch_id><![CDATA[").append(mch_id).append("]]></mch_id>");
sb.append("<nonce_str><![CDATA[").append(nonce_str).append("]]></nonce_str>");
sb.append("<notify_url><![CDATA[").append(notify_url).append("]]></notify_url>");
if ("JSAPI".equals(trade_type)) {
sb.append("<openid><![CDATA[").append(openid).append("]]></openid>");
}
sb.append("<out_trade_no><![CDATA[").append(out_trade_no).append("]]></out_trade_no>");
if ("NATIVE".equals(trade_type)) {
sb.append("<product_id><![CDATA[").append(product_id).append("]]></product_id>");
}
sb.append("<spbill_create_ip><![CDATA[").append(spbill_create_ip).append("]]></spbill_create_ip>");
sb.append("<total_fee><![CDATA[").append(total_fee).append("]]></total_fee>");
sb.append("<trade_type><![CDATA[").append(trade_type).append("]]></trade_type>");
sb.append("<sign><![CDATA[").append(sign).append("]]></sign>");
sb.append("</xml>");
return sb.toString();
}
public void setAppid(String appid) {
this.appid = appid;
}
public void setMch_id(String mch_id) {
this.mch_id = mch_id;
}
public void setNonce_str(String nonce_str) {
this.nonce_str = nonce_str;
}
public void setSign(String sign) {
this.sign = sign;
}
public void setBody(String body) {
this.body = body;
}
public void setOut_trade_no(String out_trade_no) {
this.out_trade_no = out_trade_no;
}
public void setTotal_fee(String total_fee) {
this.total_fee = total_fee;
}
public void setSpbill_create_ip(String spbill_create_ip) {
this.spbill_create_ip = spbill_create_ip;
}
public void setNotify_url(String notify_url) {
this.notify_url = notify_url;
}
public void setTrade_type(String trade_type) {
this.trade_type = trade_type;
}
public void setOpenid(String openid) {
this.openid = openid;
}
public String getProduct_id() {
return product_id;
}
public void setProduct_id(String product_id) {
this.product_id = product_id;
}
}
| java | Apache-2.0 | f5e7a60e0c377f7420866b229a9ac79e687d5ac5 | 2026-01-05T02:42:41.143783Z | false |
ansitech/weixin4j | https://github.com/ansitech/weixin4j/blob/f5e7a60e0c377f7420866b229a9ac79e687d5ac5/src/main/java/org/weixin4j/model/pay/WCPay.java | src/main/java/org/weixin4j/model/pay/WCPay.java | /*
* 微信公众平台(JAVA) SDK
*
* Copyright (c) 2014, Ansitech Network Technology Co.,Ltd All rights reserved.
*
* http://www.weixin4j.org/
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.weixin4j.model.pay;
import org.weixin4j.util.SignUtil;
import java.util.HashMap;
import java.util.Map;
/**
* 微信内网页支付
*
* @author yangqisheng
* @since 0.0.4
*/
public class WCPay {
private final String appId; //公众号Id
private final String timeStamp; //时间戳
private final String nonceStr; //随机字符串
private final String packages; //订单详情扩展字符串 统一下单接口返回的prepay_id参数值,提交格式如:prepay_id=***
private final String signType = "MD5"; //签名方式 签名算法,暂支持MD5
private final String paySign; //签名
/**
* getBrandWCPayRequest
*
* @param appId 公众号Id
* @param prepay_id 预下单Id
* @param paternerKey 商户密钥
*/
public WCPay(String appId, String prepay_id, String paternerKey) {
this.appId = appId;
this.timeStamp = System.currentTimeMillis() / 1000 + "";
this.nonceStr = java.util.UUID.randomUUID().toString().substring(0, 15);
this.packages = "prepay_id=" + prepay_id;
//对提交的参数进行签名
Map<String, String> paySignMap = new HashMap<String, String>();
paySignMap.put("appId", this.appId);
paySignMap.put("timeStamp", this.timeStamp);
paySignMap.put("nonceStr", this.nonceStr);
paySignMap.put("package", this.packages);
paySignMap.put("signType", this.signType);
//签名
this.paySign = SignUtil.getSign(paySignMap, paternerKey);
}
public String getAppId() {
return appId;
}
public String getTimeStamp() {
return timeStamp;
}
public String getNonceStr() {
return nonceStr;
}
public String getPackage() {
return packages;
}
public String getSignType() {
return signType;
}
public String getPaySign() {
return paySign;
}
}
| java | Apache-2.0 | f5e7a60e0c377f7420866b229a9ac79e687d5ac5 | 2026-01-05T02:42:41.143783Z | false |
ansitech/weixin4j | https://github.com/ansitech/weixin4j/blob/f5e7a60e0c377f7420866b229a9ac79e687d5ac5/src/main/java/org/weixin4j/model/pay/OrderQueryResult.java | src/main/java/org/weixin4j/model/pay/OrderQueryResult.java | /*
* 微信公众平台(JAVA) SDK
*
* Copyright (c) 2014, Ansitech Network Technology Co.,Ltd All rights reserved.
*
* http://www.weixin4j.org/
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.weixin4j.model.pay;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
/**
* 查询订单结果
*
* @author yangqisheng
* @since 0.1.1
*/
@XmlRootElement(name = "xml")
public class OrderQueryResult {
private String return_code;
private String return_msg;
//以下字段在return_code为SUCCESS的时候有返回
private String appid; //公众账号ID
private String mch_id; //商户号
private String nonce_str; //随机字符串
private String sign; //签名
private String result_code; //签名类型
private String err_code; //错误代码
private String err_code_des; //错误代码描述
//以下字段在return_code 、result_code、trade_state都为SUCCESS时有返回 ,如trade_state不为 SUCCESS,则只返回out_trade_no(必传)和attach(选传)。
private String device_info;
private String openid;
private String is_subscribe;
private String trade_type;
private String trade_state;
private String bank_type;
private int total_fee;
private int settlement_total_fee;
private String fee_type;
private int cash_fee;
private String cash_fee_type;
private int coupon_fee;
private int coupon_count;
private String transaction_id; //微信支付订单号
private String attach; //附加数据
private String out_trade_no; //商户订单号
private String time_end; //支付完成时间
private String trade_state_desc; //交易状态描述
public String getReturn_code() {
return return_code;
}
@XmlElement(name = "return_code")
public void setReturn_code(String return_code) {
this.return_code = return_code;
}
public String getReturn_msg() {
return return_msg;
}
@XmlElement(name = "return_msg")
public void setReturn_msg(String return_msg) {
this.return_msg = return_msg;
}
public String getAppid() {
return appid;
}
@XmlElement(name = "appid")
public void setAppid(String appid) {
this.appid = appid;
}
public String getMch_id() {
return mch_id;
}
@XmlElement(name = "mch_id")
public void setMch_id(String mch_id) {
this.mch_id = mch_id;
}
public String getNonce_str() {
return nonce_str;
}
@XmlElement(name = "nonce_str")
public void setNonce_str(String nonce_str) {
this.nonce_str = nonce_str;
}
public String getSign() {
return sign;
}
@XmlElement(name = "sign")
public void setSign(String sign) {
this.sign = sign;
}
public String getResult_code() {
return result_code;
}
@XmlElement(name = "result_code")
public void setResult_code(String result_code) {
this.result_code = result_code;
}
public String getErr_code() {
return err_code;
}
@XmlElement(name = "err_code")
public void setErr_code(String err_code) {
this.err_code = err_code;
}
public String getErr_code_des() {
return err_code_des;
}
@XmlElement(name = "err_code_des")
public void setErr_code_des(String err_code_des) {
this.err_code_des = err_code_des;
}
public String getDevice_info() {
return device_info;
}
@XmlElement(name = "device_info")
public void setDevice_info(String device_info) {
this.device_info = device_info;
}
public String getOpenid() {
return openid;
}
@XmlElement(name = "openid")
public void setOpenid(String openid) {
this.openid = openid;
}
public String getIs_subscribe() {
return is_subscribe;
}
@XmlElement(name = "is_subscribe")
public void setIs_subscribe(String is_subscribe) {
this.is_subscribe = is_subscribe;
}
public String getTrade_type() {
return trade_type;
}
@XmlElement(name = "trade_type")
public void setTrade_type(String trade_type) {
this.trade_type = trade_type;
}
public String getTrade_state() {
return trade_state;
}
@XmlElement(name = "trade_state")
public void setTrade_state(String trade_state) {
this.trade_state = trade_state;
}
public String getBank_type() {
return bank_type;
}
@XmlElement(name = "bank_type")
public void setBank_type(String bank_type) {
this.bank_type = bank_type;
}
public int getTotal_fee() {
return total_fee;
}
@XmlElement(name = "total_fee")
public void setTotal_fee(int total_fee) {
this.total_fee = total_fee;
}
public int getSettlement_total_fee() {
return settlement_total_fee;
}
@XmlElement(name = "settlement_total_fee")
public void setSettlement_total_fee(int settlement_total_fee) {
this.settlement_total_fee = settlement_total_fee;
}
public String getFee_type() {
return fee_type;
}
@XmlElement(name = "fee_type")
public void setFee_type(String fee_type) {
this.fee_type = fee_type;
}
public int getCash_fee() {
return cash_fee;
}
@XmlElement(name = "cash_fee")
public void setCash_fee(int cash_fee) {
this.cash_fee = cash_fee;
}
public String getCash_fee_type() {
return cash_fee_type;
}
@XmlElement(name = "cash_fee_type")
public void setCash_fee_type(String cash_fee_type) {
this.cash_fee_type = cash_fee_type;
}
public int getCoupon_fee() {
return coupon_fee;
}
@XmlElement(name = "coupon_fee")
public void setCoupon_fee(int coupon_fee) {
this.coupon_fee = coupon_fee;
}
public int getCoupon_count() {
return coupon_count;
}
@XmlElement(name = "coupon_count")
public void setCoupon_count(int coupon_count) {
this.coupon_count = coupon_count;
}
public String getTransaction_id() {
return transaction_id;
}
@XmlElement(name = "transaction_id")
public void setTransaction_id(String transaction_id) {
this.transaction_id = transaction_id;
}
public String getAttach() {
return attach;
}
@XmlElement(name = "attach")
public void setAttach(String attach) {
this.attach = attach;
}
public String getOut_trade_no() {
return out_trade_no;
}
@XmlElement(name = "out_trade_no")
public void setOut_trade_no(String out_trade_no) {
this.out_trade_no = out_trade_no;
}
public String getTime_end() {
return time_end;
}
@XmlElement(name = "time_end")
public void setTime_end(String time_end) {
this.time_end = time_end;
}
public String getTrade_state_desc() {
return trade_state_desc;
}
@XmlElement(name = "trade_state_desc")
public void setTrade_state_desc(String trade_state_desc) {
this.trade_state_desc = trade_state_desc;
}
}
| java | Apache-2.0 | f5e7a60e0c377f7420866b229a9ac79e687d5ac5 | 2026-01-05T02:42:41.143783Z | false |
ansitech/weixin4j | https://github.com/ansitech/weixin4j/blob/f5e7a60e0c377f7420866b229a9ac79e687d5ac5/src/main/java/org/weixin4j/model/pay/PayNotifyResult.java | src/main/java/org/weixin4j/model/pay/PayNotifyResult.java | /*
* 微信公众平台(JAVA) SDK
*
* Copyright (c) 2014, Ansitech Network Technology Co.,Ltd All rights reserved.
*
* http://www.weixin4j.org/
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.weixin4j.model.pay;
import java.util.HashMap;
import java.util.Map;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
/**
* 支付结果通用通知
*
* http://pay.weixin.qq.com/wiki/doc/api/index.php?chapter=9_7
*
* @author yangqisheng
* @since 0.0.4
*/
@XmlRootElement(name = "xml")
public class PayNotifyResult {
/**
* SUCCESS/FAIL
*
* 此字段是通信标识,非交易标识,交易是否成功需要查看result_code来判断
*/
private String return_code; //返回状态码
/**
* 返回信息,如非空,为错误原因
*
* 签名失败
*
* 参数格式校验错误
*/
private String return_msg; //返回信息
private String appid;
private String mch_id;
private String device_info;
private String nonce_str;
private String sign;
private String result_code;
private String err_code;
private String err_code_des;
private String openid;
private String is_subscribe;
private String trade_type;
private String bank_type;
private String total_fee;
private String fee_type;
private String cash_fee;
private String cash_fee_type;
private String coupon_fee;
private String coupon_count;
private String transaction_id;
private String out_trade_no;
private String attach;
private String time_end;
public Map<String, String> toMap() {
Map<String, String> map = new HashMap<String, String>();
map.put("return_code", return_code);
map.put("return_msg", return_msg);
map.put("appid", appid);
map.put("mch_id", mch_id);
map.put("device_info", device_info);
map.put("nonce_str", nonce_str);
map.put("sign", sign);
map.put("result_code", result_code);
map.put("err_code", err_code);
map.put("err_code_des", err_code_des);
map.put("openid", openid);
map.put("is_subscribe", is_subscribe);
map.put("trade_type", trade_type);
map.put("bank_type", bank_type);
map.put("total_fee", total_fee);
map.put("fee_type", fee_type);
map.put("cash_fee", cash_fee);
map.put("cash_fee_type", cash_fee_type);
map.put("coupon_fee", coupon_fee);
map.put("coupon_count", coupon_count);
map.put("transaction_id", transaction_id);
map.put("out_trade_no", out_trade_no);
map.put("attach", attach);
map.put("time_end", time_end);
return map;
}
public String getReturn_code() {
return return_code;
}
@XmlElement(name = "return_code")
public void setReturn_code(String return_code) {
this.return_code = return_code;
}
public String getReturn_msg() {
return return_msg;
}
@XmlElement(name = "return_msg")
public void setReturn_msg(String return_msg) {
this.return_msg = return_msg;
}
public String getAppid() {
return appid;
}
@XmlElement(name = "appid")
public void setAppid(String appid) {
this.appid = appid;
}
public String getMch_id() {
return mch_id;
}
@XmlElement(name = "mch_id")
public void setMch_id(String mch_id) {
this.mch_id = mch_id;
}
public String getDevice_info() {
return device_info;
}
@XmlElement(name = "device_info")
public void setDevice_info(String device_info) {
this.device_info = device_info;
}
public String getNonce_str() {
return nonce_str;
}
@XmlElement(name = "nonce_str")
public void setNonce_str(String nonce_str) {
this.nonce_str = nonce_str;
}
public String getSign() {
return sign;
}
@XmlElement(name = "sign")
public void setSign(String sign) {
this.sign = sign;
}
public String getResult_code() {
return result_code;
}
@XmlElement(name = "result_code")
public void setResult_code(String result_code) {
this.result_code = result_code;
}
public String getErr_code() {
return err_code;
}
@XmlElement(name = "err_code")
public void setErr_code(String err_code) {
this.err_code = err_code;
}
public String getErr_code_des() {
return err_code_des;
}
@XmlElement(name = "err_code_des")
public void setErr_code_des(String err_code_des) {
this.err_code_des = err_code_des;
}
public String getOpenid() {
return openid;
}
@XmlElement(name = "openid")
public void setOpenid(String openid) {
this.openid = openid;
}
public String getIs_subscribe() {
return is_subscribe;
}
@XmlElement(name = "is_subscribe")
public void setIs_subscribe(String is_subscribe) {
this.is_subscribe = is_subscribe;
}
public String getTrade_type() {
return trade_type;
}
@XmlElement(name = "trade_type")
public void setTrade_type(String trade_type) {
this.trade_type = trade_type;
}
public String getBank_type() {
return bank_type;
}
@XmlElement(name = "bank_type")
public void setBank_type(String bank_type) {
this.bank_type = bank_type;
}
public String getTotal_fee() {
return total_fee;
}
@XmlElement(name = "total_fee")
public void setTotal_fee(String total_fee) {
this.total_fee = total_fee;
}
public String getFee_type() {
return fee_type;
}
@XmlElement(name = "fee_type")
public void setFee_type(String fee_type) {
this.fee_type = fee_type;
}
public String getCash_fee() {
return cash_fee;
}
@XmlElement(name = "cash_fee")
public void setCash_fee(String cash_fee) {
this.cash_fee = cash_fee;
}
public String getCash_fee_type() {
return cash_fee_type;
}
@XmlElement(name = "cash_fee_type")
public void setCash_fee_type(String cash_fee_type) {
this.cash_fee_type = cash_fee_type;
}
public String getCoupon_fee() {
return coupon_fee;
}
@XmlElement(name = "coupon_fee")
public void setCoupon_fee(String coupon_fee) {
this.coupon_fee = coupon_fee;
}
public String getCoupon_count() {
return coupon_count;
}
@XmlElement(name = "coupon_count")
public void setCoupon_count(String coupon_count) {
this.coupon_count = coupon_count;
}
public String getTransaction_id() {
return transaction_id;
}
@XmlElement(name = "transaction_id")
public void setTransaction_id(String transaction_id) {
this.transaction_id = transaction_id;
}
public String getOut_trade_no() {
return out_trade_no;
}
@XmlElement(name = "out_trade_no")
public void setOut_trade_no(String out_trade_no) {
this.out_trade_no = out_trade_no;
}
public String getAttach() {
return attach;
}
@XmlElement(name = "attach")
public void setAttach(String attach) {
this.attach = attach;
}
public String getTime_end() {
return time_end;
}
@XmlElement(name = "time_end")
public void setTime_end(String time_end) {
this.time_end = time_end;
}
}
| java | Apache-2.0 | f5e7a60e0c377f7420866b229a9ac79e687d5ac5 | 2026-01-05T02:42:41.143783Z | false |
ansitech/weixin4j | https://github.com/ansitech/weixin4j/blob/f5e7a60e0c377f7420866b229a9ac79e687d5ac5/src/main/java/org/weixin4j/model/pay/OrderQuery.java | src/main/java/org/weixin4j/model/pay/OrderQuery.java | /*
* 微信公众平台(JAVA) SDK
*
* Copyright (c) 2014, Ansitech Network Technology Co.,Ltd All rights reserved.
*
* http://www.weixin4j.org/
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.weixin4j.model.pay;
import java.util.HashMap;
import java.util.Map;
/**
* 查询订单
*
* 接口文档:https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_2
*
* <b>应用场景</b>
*
* 该接口提供所有微信支付订单的查询,商户可以通过查询订单接口主动查询订单状态,完成下一步的业务逻辑。
*
* 需要调用查询接口的情况:
*
* ◆ 当商户后台、网络、服务器等出现异常,商户系统最终未接收到支付通知;
*
* ◆ 调用支付接口后,返回系统错误或未知交易状态情况;
*
* ◆ 调用刷卡支付API,返回USERPAYING的状态;
*
* ◆ 调用关单或撤销接口API之前,需确认支付状态;
*
* <b>是否需要证书</b>
*
* 不需要
*
* @author yangqisheng
* @since 0.1.1
*/
public class OrderQuery {
private String appid; //公众账号ID
private String mch_id; //商户号
private String transaction_id; //微信订单号(二选一,优先)
private String out_trade_no; //商户订单号(二选一)
private String nonce_str; //随机字符串
private String sign; //签名
private String sign_type; //签名类型
public Map<String, String> toMap() {
Map<String, String> map = new HashMap<String, String>();
map.put("appid", appid);
map.put("mch_id", mch_id);
if (transaction_id != null && !transaction_id.equals("")) {
map.put("transaction_id", transaction_id);
} else {
map.put("out_trade_no", out_trade_no);
}
map.put("nonce_str", nonce_str);
return map;
}
public String toXML() {
StringBuilder sb = new StringBuilder();
sb.append("<xml>");
sb.append("<appid><![CDATA[").append(appid).append("]]></appid>");
sb.append("<mch_id><![CDATA[").append(mch_id).append("]]></mch_id>");
sb.append("<nonce_str><![CDATA[").append(nonce_str).append("]]></nonce_str>");
if (transaction_id != null && !transaction_id.equals("")) {
sb.append("<transaction_id><![CDATA[").append(transaction_id).append("]]></transaction_id>");
} else {
sb.append("<out_trade_no><![CDATA[").append(out_trade_no).append("]]></out_trade_no>");
}
sb.append("<sign><![CDATA[").append(sign).append("]]></sign>");
sb.append("</xml>");
return sb.toString();
}
public String getAppid() {
return appid;
}
public void setAppid(String appid) {
this.appid = appid;
}
public String getMch_id() {
return mch_id;
}
public void setMch_id(String mch_id) {
this.mch_id = mch_id;
}
public String getTransaction_id() {
return transaction_id;
}
public void setTransaction_id(String transaction_id) {
this.transaction_id = transaction_id;
}
public String getOut_trade_no() {
return out_trade_no;
}
public void setOut_trade_no(String out_trade_no) {
this.out_trade_no = out_trade_no;
}
public String getNonce_str() {
return nonce_str;
}
public void setNonce_str(String nonce_str) {
this.nonce_str = nonce_str;
}
public String getSign() {
return sign;
}
public void setSign(String sign) {
this.sign = sign;
}
public String getSign_type() {
return sign_type;
}
public void setSign_type(String sign_type) {
this.sign_type = sign_type;
}
}
| java | Apache-2.0 | f5e7a60e0c377f7420866b229a9ac79e687d5ac5 | 2026-01-05T02:42:41.143783Z | false |
ansitech/weixin4j | https://github.com/ansitech/weixin4j/blob/f5e7a60e0c377f7420866b229a9ac79e687d5ac5/src/main/java/org/weixin4j/model/pay/PayNotifySLResult.java | src/main/java/org/weixin4j/model/pay/PayNotifySLResult.java | /*
* 微信公众平台(JAVA) SDK
*
* Copyright (c) 2014, Ansitech Network Technology Co.,Ltd All rights reserved.
*
* http://www.weixin4j.org/
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.weixin4j.model.pay;
import java.util.HashMap;
import java.util.Map;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
/**
* 支付结果通用通知
*
* http://pay.weixin.qq.com/wiki/doc/api/index.php?chapter=9_7
*
* @author yangqisheng
* @since 0.1.5
*/
@XmlRootElement(name = "xml")
public class PayNotifySLResult {
//通知参数
private String return_code; //返回状态码
private String return_msg; //返回信息
//以下字段在return_code为SUCCESS的时候有返回
private String appid; //公众账号ID
private String mch_id; //商户号
private String sub_appid; //子商户公众账号ID
private String sub_mch_id; //子商户号
private String device_info; //设备号
private String is_subscribe; //是否关注公众账号,用户是否关注公众账号,Y-关注,N-未关注(机构商户不返回)
private String nonce_str; //随机字符串
private String sub_is_subscribe;//是否关注子公众账号
private String sign; //签名
private String result_code; //业务结果
private String err_code; //错误代码
private String err_code_des; //错误代码描述
private String openid; //用户标识
private String sub_openid; //用户子标识
private String trade_type; //交易类型
private String bank_type; //付款银行
private String total_fee; //总金额
private String fee_type; //货币种类
private String cash_fee; //现金支付金额
private String cash_fee_type; //现金支付货币类型
private String settlement_total_fee; //应结订单金额=订单金额-非充值代金券金额,应结订单金额<=订单金额。
private String coupon_fee; //代金券金额
private String coupon_count; //代金券使用数量
private String transaction_id; //微信支付订单号
private String out_trade_no; //商户订单号
private String attach; //商家数据包
private String time_end; //支付完成时间
public Map<String, String> toMap() {
Map<String, String> map = new HashMap<String, String>();
map.put("return_code", return_code);
map.put("return_msg", return_msg);
map.put("appid", appid);
map.put("mch_id", mch_id);
map.put("sub_mch_id", sub_mch_id);
map.put("device_info", device_info);
map.put("nonce_str", nonce_str);
map.put("sub_is_subscribe", sub_is_subscribe);
map.put("sign", sign);
map.put("result_code", result_code);
map.put("err_code", err_code);
map.put("err_code_des", err_code_des);
map.put("openid", openid);
map.put("sub_openid", sub_openid);
map.put("is_subscribe", is_subscribe);
map.put("trade_type", trade_type);
map.put("bank_type", bank_type);
map.put("total_fee", total_fee);
map.put("fee_type", fee_type);
map.put("cash_fee", cash_fee);
map.put("cash_fee_type", cash_fee_type);
map.put("settlement_total_fee", settlement_total_fee);
map.put("coupon_fee", coupon_fee);
map.put("coupon_count", coupon_count);
map.put("transaction_id", transaction_id);
map.put("out_trade_no", out_trade_no);
map.put("attach", attach);
map.put("time_end", time_end);
return map;
}
public String getReturn_code() {
return return_code;
}
@XmlElement(name = "return_code")
public void setReturn_code(String return_code) {
this.return_code = return_code;
}
public String getReturn_msg() {
return return_msg;
}
@XmlElement(name = "return_msg")
public void setReturn_msg(String return_msg) {
this.return_msg = return_msg;
}
public String getAppid() {
return appid;
}
@XmlElement(name = "appid")
public void setAppid(String appid) {
this.appid = appid;
}
public String getMch_id() {
return mch_id;
}
@XmlElement(name = "mch_id")
public void setMch_id(String mch_id) {
this.mch_id = mch_id;
}
public String getDevice_info() {
return device_info;
}
@XmlElement(name = "device_info")
public void setDevice_info(String device_info) {
this.device_info = device_info;
}
public String getNonce_str() {
return nonce_str;
}
@XmlElement(name = "nonce_str")
public void setNonce_str(String nonce_str) {
this.nonce_str = nonce_str;
}
public String getSign() {
return sign;
}
@XmlElement(name = "sign")
public void setSign(String sign) {
this.sign = sign;
}
public String getResult_code() {
return result_code;
}
@XmlElement(name = "result_code")
public void setResult_code(String result_code) {
this.result_code = result_code;
}
public String getErr_code() {
return err_code;
}
@XmlElement(name = "err_code")
public void setErr_code(String err_code) {
this.err_code = err_code;
}
public String getErr_code_des() {
return err_code_des;
}
@XmlElement(name = "err_code_des")
public void setErr_code_des(String err_code_des) {
this.err_code_des = err_code_des;
}
public String getOpenid() {
return openid;
}
@XmlElement(name = "openid")
public void setOpenid(String openid) {
this.openid = openid;
}
public String getIs_subscribe() {
return is_subscribe;
}
@XmlElement(name = "is_subscribe")
public void setIs_subscribe(String is_subscribe) {
this.is_subscribe = is_subscribe;
}
public String getTrade_type() {
return trade_type;
}
@XmlElement(name = "trade_type")
public void setTrade_type(String trade_type) {
this.trade_type = trade_type;
}
public String getBank_type() {
return bank_type;
}
@XmlElement(name = "bank_type")
public void setBank_type(String bank_type) {
this.bank_type = bank_type;
}
public String getTotal_fee() {
return total_fee;
}
@XmlElement(name = "total_fee")
public void setTotal_fee(String total_fee) {
this.total_fee = total_fee;
}
public String getFee_type() {
return fee_type;
}
@XmlElement(name = "fee_type")
public void setFee_type(String fee_type) {
this.fee_type = fee_type;
}
public String getCash_fee() {
return cash_fee;
}
@XmlElement(name = "cash_fee")
public void setCash_fee(String cash_fee) {
this.cash_fee = cash_fee;
}
public String getCash_fee_type() {
return cash_fee_type;
}
@XmlElement(name = "cash_fee_type")
public void setCash_fee_type(String cash_fee_type) {
this.cash_fee_type = cash_fee_type;
}
public String getCoupon_fee() {
return coupon_fee;
}
@XmlElement(name = "coupon_fee")
public void setCoupon_fee(String coupon_fee) {
this.coupon_fee = coupon_fee;
}
public String getCoupon_count() {
return coupon_count;
}
@XmlElement(name = "coupon_count")
public void setCoupon_count(String coupon_count) {
this.coupon_count = coupon_count;
}
public String getTransaction_id() {
return transaction_id;
}
@XmlElement(name = "transaction_id")
public void setTransaction_id(String transaction_id) {
this.transaction_id = transaction_id;
}
public String getOut_trade_no() {
return out_trade_no;
}
@XmlElement(name = "out_trade_no")
public void setOut_trade_no(String out_trade_no) {
this.out_trade_no = out_trade_no;
}
public String getAttach() {
return attach;
}
@XmlElement(name = "attach")
public void setAttach(String attach) {
this.attach = attach;
}
public String getTime_end() {
return time_end;
}
@XmlElement(name = "time_end")
public void setTime_end(String time_end) {
this.time_end = time_end;
}
public String getSub_appid() {
return sub_appid;
}
@XmlElement(name = "sub_appid")
public void setSub_appid(String sub_appid) {
this.sub_appid = sub_appid;
}
public String getSub_is_subscribe() {
return sub_is_subscribe;
}
@XmlElement(name = "sub_is_subscribe")
public void setSub_is_subscribe(String sub_is_subscribe) {
this.sub_is_subscribe = sub_is_subscribe;
}
public String getSub_openid() {
return sub_openid;
}
@XmlElement(name = "sub_openid")
public void setSub_openid(String sub_openid) {
this.sub_openid = sub_openid;
}
public String getSettlement_total_fee() {
return settlement_total_fee;
}
@XmlElement(name = "settlement_total_fee")
public void setSettlement_total_fee(String settlement_total_fee) {
this.settlement_total_fee = settlement_total_fee;
}
public String getSub_mch_id() {
return sub_mch_id;
}
public void setSub_mch_id(String sub_mch_id) {
this.sub_mch_id = sub_mch_id;
}
}
| java | Apache-2.0 | f5e7a60e0c377f7420866b229a9ac79e687d5ac5 | 2026-01-05T02:42:41.143783Z | false |
ansitech/weixin4j | https://github.com/ansitech/weixin4j/blob/f5e7a60e0c377f7420866b229a9ac79e687d5ac5/src/main/java/org/weixin4j/model/pay/UnifiedOrderSLResult.java | src/main/java/org/weixin4j/model/pay/UnifiedOrderSLResult.java | /*
* 微信公众平台(JAVA) SDK
*
* Copyright (c) 2014, Ansitech Network Technology Co.,Ltd All rights reserved.
*
* http://www.weixin4j.org/
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.weixin4j.model.pay;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
/**
* 服务商统一下单结果
*
* @author yangqisheng
* @since 0.1.5
*/
@XmlRootElement(name = "xml")
public class UnifiedOrderSLResult {
//返回结果
private String return_code; //返回状态码
private String return_msg; //返回信息
//*** 以下字段在return_code为SUCCESS的时候有返回 ***//
private String appid; //公众账号ID
private String mch_id; //商户号
private String sub_appid; //子商户公众账号ID
private String sub_mch_id; //子商户号
private String device_info; //设备号
private String nonce_str; //随机字符串
private String sign; //签名
private String result_code; //业务结果 SUCCESS/FAIL
private String err_code; //错误代码
private String err_code_des; //错误代码描述
//*** 以下字段在return_code 和result_code都为SUCCESS的时候有返回 ***//
private String trade_type; //交易类型
private String prepay_id; //预支付交易会话标识
private String code_url; //二维码链接
/**
* 通信是否成功
*
* @return 成功返回True,否则返回false
*/
public boolean isSuccess() {
if (return_code == null || return_code.equals("")) {
return false;
}
return return_code.toUpperCase().equals("SUCCESS");
}
public String getReturn_code() {
return return_code;
}
@XmlElement(name = "return_code")
public void setReturn_code(String return_code) {
this.return_code = return_code;
}
public String getReturn_msg() {
return return_msg;
}
@XmlElement(name = "return_msg")
public void setReturn_msg(String return_msg) {
this.return_msg = return_msg;
}
public String getAppid() {
return appid;
}
@XmlElement(name = "appid")
public void setAppid(String appid) {
this.appid = appid;
}
public String getMch_id() {
return mch_id;
}
@XmlElement(name = "mch_id")
public void setMch_id(String mch_id) {
this.mch_id = mch_id;
}
@XmlElement(name = "sub_appid")
public String getSub_appid() {
return sub_appid;
}
public void setSub_appid(String sub_appid) {
this.sub_appid = sub_appid;
}
@XmlElement(name = "sub_mch_id")
public String getSub_mch_id() {
return sub_mch_id;
}
public void setSub_mch_id(String sub_mch_id) {
this.sub_mch_id = sub_mch_id;
}
public String getDevice_info() {
return device_info;
}
@XmlElement(name = "device_info")
public void setDevice_info(String device_info) {
this.device_info = device_info;
}
public String getNonce_str() {
return nonce_str;
}
@XmlElement(name = "nonce_str")
public void setNonce_str(String nonce_str) {
this.nonce_str = nonce_str;
}
public String getSign() {
return sign;
}
@XmlElement(name = "sign")
public void setSign(String sign) {
this.sign = sign;
}
public String getResult_code() {
return result_code;
}
@XmlElement(name = "result_code")
public void setResult_code(String result_code) {
this.result_code = result_code;
}
public String getErr_code() {
return err_code;
}
@XmlElement(name = "err_code")
public void setErr_code(String err_code) {
this.err_code = err_code;
}
public String getErr_code_des() {
return err_code_des;
}
@XmlElement(name = "err_code_des")
public void setErr_code_des(String err_code_des) {
this.err_code_des = err_code_des;
}
public String getTrade_type() {
return trade_type;
}
@XmlElement(name = "trade_type")
public void setTrade_type(String trade_type) {
this.trade_type = trade_type;
}
public String getPrepay_id() {
return prepay_id;
}
@XmlElement(name = "prepay_id")
public void setPrepay_id(String prepay_id) {
this.prepay_id = prepay_id;
}
public String getCode_url() {
return code_url;
}
@XmlElement(name = "code_url")
public void setCode_url(String code_url) {
this.code_url = code_url;
}
}
| java | Apache-2.0 | f5e7a60e0c377f7420866b229a9ac79e687d5ac5 | 2026-01-05T02:42:41.143783Z | false |
ansitech/weixin4j | https://github.com/ansitech/weixin4j/blob/f5e7a60e0c377f7420866b229a9ac79e687d5ac5/src/main/java/org/weixin4j/model/pay/UnifiedOrderResult.java | src/main/java/org/weixin4j/model/pay/UnifiedOrderResult.java | /*
* 微信公众平台(JAVA) SDK
*
* Copyright (c) 2014, Ansitech Network Technology Co.,Ltd All rights reserved.
*
* http://www.weixin4j.org/
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.weixin4j.model.pay;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
/**
* 统一下单结果
*
* @author yangqisheng
* @since 0.0.4
*/
@XmlRootElement(name = "xml")
public class UnifiedOrderResult {
/**
* 字段名:返回状态码
*
* 必填:是
*
* 类型:String(16)
*
* 描述:SUCCESS/FAIL
*
* 此字段是通信标识,非交易标识,交易是否成功需要查看result_code来判断
*/
private String return_code;
/**
* 字段名:返回信息
*
* 必填:否
*
* 类型:String(128)
*
* 描述:返回信息,如非空,为错误原因
*
* 签名失败、参数格式校验错误等
*/
private String return_msg;
//*** 以下字段在return_code为SUCCESS的时候有返回 ***//
private String appid; //公众账号ID
private String mch_id; //商户号
private String device_info; //设备号
private String nonce_str; //随机字符串
private String sign; //签名
private String result_code; //业务结果 SUCCESS/FAIL
private String err_code; //错误代码
private String err_code_des; //错误代码描述
//*** 以下字段在return_code 和result_code都为SUCCESS的时候有返回 ***//
private String trade_type; //交易类型
private String prepay_id; //预支付交易会话标识
private String code_url; //二维码链接
/**
* 通信是否成功
*
* @return 成功返回True,否则返回false
*/
public boolean isSuccess() {
if (return_code == null || return_code.equals("")) {
return false;
}
return return_code.toUpperCase().equals("SUCCESS");
}
public String getReturn_code() {
return return_code;
}
@XmlElement(name = "return_code")
public void setReturn_code(String return_code) {
this.return_code = return_code;
}
public String getReturn_msg() {
return return_msg;
}
@XmlElement(name = "return_msg")
public void setReturn_msg(String return_msg) {
this.return_msg = return_msg;
}
public String getAppid() {
return appid;
}
@XmlElement(name = "appid")
public void setAppid(String appid) {
this.appid = appid;
}
public String getMch_id() {
return mch_id;
}
@XmlElement(name = "mch_id")
public void setMch_id(String mch_id) {
this.mch_id = mch_id;
}
public String getDevice_info() {
return device_info;
}
@XmlElement(name = "device_info")
public void setDevice_info(String device_info) {
this.device_info = device_info;
}
public String getNonce_str() {
return nonce_str;
}
@XmlElement(name = "nonce_str")
public void setNonce_str(String nonce_str) {
this.nonce_str = nonce_str;
}
public String getSign() {
return sign;
}
@XmlElement(name = "sign")
public void setSign(String sign) {
this.sign = sign;
}
public String getResult_code() {
return result_code;
}
@XmlElement(name = "result_code")
public void setResult_code(String result_code) {
this.result_code = result_code;
}
public String getErr_code() {
return err_code;
}
@XmlElement(name = "err_code")
public void setErr_code(String err_code) {
this.err_code = err_code;
}
public String getErr_code_des() {
return err_code_des;
}
@XmlElement(name = "err_code_des")
public void setErr_code_des(String err_code_des) {
this.err_code_des = err_code_des;
}
public String getTrade_type() {
return trade_type;
}
@XmlElement(name = "trade_type")
public void setTrade_type(String trade_type) {
this.trade_type = trade_type;
}
public String getPrepay_id() {
return prepay_id;
}
@XmlElement(name = "prepay_id")
public void setPrepay_id(String prepay_id) {
this.prepay_id = prepay_id;
}
public String getCode_url() {
return code_url;
}
@XmlElement(name = "code_url")
public void setCode_url(String code_url) {
this.code_url = code_url;
}
}
| java | Apache-2.0 | f5e7a60e0c377f7420866b229a9ac79e687d5ac5 | 2026-01-05T02:42:41.143783Z | false |
ansitech/weixin4j | https://github.com/ansitech/weixin4j/blob/f5e7a60e0c377f7420866b229a9ac79e687d5ac5/src/main/java/org/weixin4j/model/pay/UnifiedOrderSL.java | src/main/java/org/weixin4j/model/pay/UnifiedOrderSL.java | /*
* 微信公众平台(JAVA) SDK
*
* Copyright (c) 2014, Ansitech Network Technology Co.,Ltd All rights reserved.
*
* http://www.weixin4j.org/
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.weixin4j.model.pay;
import java.util.HashMap;
import java.util.Map;
/**
* 服务商统一下单
*
* 接口文档:https://pay.weixin.qq.com/wiki/doc/api/jsapi_sl.php?chapter=9_1
*
* <b>应用场景</b>
*
* 除付款码支付场景以外,商户系统先调用该接口在微信支付服务后台生成预支付交易单,返回正确的预支付交易会话标识后再按Native、JSAPI、APP等不同场景生成交易串调起支付。
*
* <b>是否需要证书</b>
*
* 不需要
*
* @author yangqisheng
* @since 0.1.5
*/
public class UnifiedOrderSL {
private String appid; //公众账号ID
private String mch_id; //商户号
private String nonce_str; //随机字符串
private String sign; //签名
private String body; //商品描述
private String out_trade_no; //商户订单号
private String total_fee; //总金额
private String spbill_create_ip; //终端IP
private String notify_url; //通知地址
private String trade_type; //交易类型 取值如下:JSAPI,NATIVE,APP
private String product_id; //商品ID,trade_type=NATIVE时,此参数必传。此id为二维码中包含的商品ID,商户自行定义。
private String openid; //用户标识
//服务商扩展字段
private String sub_appid; //子商户公众账号ID
private String sub_mch_id; //子商户号
private String sub_openid; //用户子标识
public Map<String, String> toMap() {
Map<String, String> map = new HashMap<String, String>();
map.put("appid", appid);
map.put("body", body);
map.put("mch_id", mch_id);
map.put("nonce_str", nonce_str);
map.put("notify_url", notify_url);
if ("JSAPI".equals(trade_type)) {
map.put("openid", openid);
}
map.put("out_trade_no", out_trade_no);
if ("NATIVE".equals(trade_type)) {
map.put("product_id", product_id);
}
map.put("spbill_create_ip", spbill_create_ip);
if (sub_appid != null) {
map.put("sub_appid", sub_appid);
}
map.put("sub_mch_id", sub_mch_id);
if (sub_openid != null) {
map.put("sub_openid", sub_openid);
}
map.put("total_fee", total_fee);
map.put("trade_type", trade_type);
return map;
}
public String toXML() {
StringBuilder sb = new StringBuilder();
sb.append("<xml>");
sb.append("<appid><![CDATA[").append(appid).append("]]></appid>");
sb.append("<body><![CDATA[").append(body).append("]]></body>");
sb.append("<mch_id><![CDATA[").append(mch_id).append("]]></mch_id>");
sb.append("<nonce_str><![CDATA[").append(nonce_str).append("]]></nonce_str>");
sb.append("<notify_url><![CDATA[").append(notify_url).append("]]></notify_url>");
if ("JSAPI".equals(trade_type)) {
sb.append("<openid><![CDATA[").append(openid).append("]]></openid>");
}
sb.append("<out_trade_no><![CDATA[").append(out_trade_no).append("]]></out_trade_no>");
if ("NATIVE".equals(trade_type)) {
sb.append("<product_id><![CDATA[").append(product_id).append("]]></product_id>");
}
sb.append("<spbill_create_ip><![CDATA[").append(spbill_create_ip).append("]]></spbill_create_ip>");
if (sub_appid != null) {
sb.append("<sub_appid><![CDATA[").append(sub_appid).append("]]></sub_appid>");
}
sb.append("<sub_mch_id><![CDATA[").append(sub_mch_id).append("]]></sub_mch_id>");
if (sub_openid != null) {
sb.append("<sub_openid><![CDATA[").append(sub_openid).append("]]></sub_openid>");
}
sb.append("<total_fee><![CDATA[").append(total_fee).append("]]></total_fee>");
sb.append("<trade_type><![CDATA[").append(trade_type).append("]]></trade_type>");
sb.append("<sign><![CDATA[").append(sign).append("]]></sign>");
sb.append("</xml>");
return sb.toString();
}
public String getAppid() {
return appid;
}
public void setAppid(String appid) {
this.appid = appid;
}
public String getMch_id() {
return mch_id;
}
public void setMch_id(String mch_id) {
this.mch_id = mch_id;
}
public String getSub_appid() {
return sub_appid;
}
public void setSub_appid(String sub_appid) {
this.sub_appid = sub_appid;
}
public String getSub_mch_id() {
return sub_mch_id;
}
public void setSub_mch_id(String sub_mch_id) {
this.sub_mch_id = sub_mch_id;
}
public String getNonce_str() {
return nonce_str;
}
public void setNonce_str(String nonce_str) {
this.nonce_str = nonce_str;
}
public String getSign() {
return sign;
}
public void setSign(String sign) {
this.sign = sign;
}
public String getBody() {
return body;
}
public void setBody(String body) {
this.body = body;
}
public String getOut_trade_no() {
return out_trade_no;
}
public void setOut_trade_no(String out_trade_no) {
this.out_trade_no = out_trade_no;
}
public String getTotal_fee() {
return total_fee;
}
public void setTotal_fee(String total_fee) {
this.total_fee = total_fee;
}
public String getSpbill_create_ip() {
return spbill_create_ip;
}
public void setSpbill_create_ip(String spbill_create_ip) {
this.spbill_create_ip = spbill_create_ip;
}
public String getNotify_url() {
return notify_url;
}
public void setNotify_url(String notify_url) {
this.notify_url = notify_url;
}
public String getTrade_type() {
return trade_type;
}
public void setTrade_type(String trade_type) {
this.trade_type = trade_type;
}
public String getOpenid() {
return openid;
}
public void setOpenid(String openid) {
this.openid = openid;
}
public String getSub_openid() {
return sub_openid;
}
public void setSub_openid(String sub_openid) {
this.sub_openid = sub_openid;
}
}
| java | Apache-2.0 | f5e7a60e0c377f7420866b229a9ac79e687d5ac5 | 2026-01-05T02:42:41.143783Z | false |
ansitech/weixin4j | https://github.com/ansitech/weixin4j/blob/f5e7a60e0c377f7420866b229a9ac79e687d5ac5/src/main/java/org/weixin4j/model/pay/WXPay.java | src/main/java/org/weixin4j/model/pay/WXPay.java | /*
* 微信公众平台(JAVA) SDK
*
* Copyright (c) 2014, Ansitech Network Technology Co.,Ltd All rights reserved.
*
* http://www.weixin4j.org/
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.weixin4j.model.pay;
import org.weixin4j.util.SignUtil;
import java.util.HashMap;
import java.util.Map;
import org.apache.commons.codec.digest.DigestUtils;
import org.weixin4j.Configuration;
import org.weixin4j.util.MapUtil;
/**
* JS API 微信支付
*
* @author yangqisheng
* @since 0.0.1
*/
public class WXPay {
private final String appId; //公众号Id
private final String timestamp; //支付签名时间戳
private final String nonceStr; //支付签名随机串
private final String packages; //订单详情扩展字符串
private final String signType = "MD5"; //签名方式,默认为'SHA1',使用新版支付需传入'MD5'
private final String paySign; //支付签名
private final String signature; //jsapi授权签名
/**
* chooseWXPay
*
* @param appId 公众号Id
* @param jsapi_ticket jsapi验证票据
* @param prepay_id 预下单Id
* @param url 发起请求的url地址
* @param paternerKey 商户密钥
*/
public WXPay(String appId, String jsapi_ticket, String prepay_id, String url, String paternerKey) {
this.appId = appId;
this.timestamp = System.currentTimeMillis() / 1000 + "";
this.nonceStr = java.util.UUID.randomUUID().toString().substring(0, 15);
//生成订单详情扩展字符串
this.packages = "prepay_id=" + prepay_id;
//生成jsapi授权签名
this.signature = SignUtil.getSignature(jsapi_ticket, this.nonceStr, this.timestamp, url);
//对提交的参数进行签名
Map<String, String> paySignMap = new HashMap<String, String>();
paySignMap.put("appId", this.appId);
paySignMap.put("timeStamp", timestamp);
paySignMap.put("nonceStr", this.nonceStr);
paySignMap.put("package", this.packages);
paySignMap.put("signType", this.signType);
//生成支付签名
this.paySign = SignUtil.getSign(paySignMap, paternerKey);
}
/**
* 生成package单详情扩展字符串
*
* package 生成方法:
*
* 由于package中携带了生成订单的详细信息, 因此在微信将对package里面的内容进行鉴权,
* 确定package携带的信息是真实、有效、合理的。 因此,这里将定义生成package字符 串的方法。
*
* 1.对所有传入参数按照字段名的ASCII码从小到大排序(字典序)后,
* 使用URL键值对的格式(即key1=value1&key2=value2…)拼接成字符串string1, 注意:值为空的参数不参与签名;
*
* 2.在string1最后拼接上key=paternerKey得到stringSignTemp字符串,
* 并对stringSignTemp进行md5运算,再将得到的字符串所有字符转换为大写, 得到sign值signValue。
*
* 3.对传入参数中所有键值对的value进行urlencode转码后重新拼接成字符串string2。
* 对于JS前端程序,一定要使用函数encodeURIComponent进行urlencode编码
* (注意!进行urlencode时要将空格转化为%20而不是+)。
*
* 4.将sign=signValue拼接到string2后面得到最终的package字符串。
*
* @param M 参数详情对象
* @param paternerKey 商户密钥
* @return 返回订单详情package
*/
private static String getPackage(Map<String, String> M, String paternerKey) {
//1.1 将packages参数进行字典序排序
Map<String, String> sortParams = MapUtil.sortAsc(M);
//1.2 使用URL键值对的格式
String string1 = MapUtil.mapJoin(sortParams, false);
//2.1 接上key=paternerKey
String stringSignTemp = string1 + "&key=" + paternerKey;
//2.2 MD5加密
String sign = DigestUtils.md5Hex(stringSignTemp).toUpperCase();
if (Configuration.isDebug()) {
System.out.println("sign = " + sign);
}
//3 对传入参数中所有键值对的value进行urlencode转码
String string2 = MapUtil.mapJoin(sortParams, true);
if (Configuration.isDebug()) {
System.out.println("string2 = " + string2);
}
//4 将sign=signValue拼接到string2后面得到最终的package字符串。
return string2 + "&sign=" + sign;
}
public String getTimeStamp() {
return timestamp;
}
public String getNonceStr() {
return nonceStr;
}
public String getPackage() {
return packages;
}
public String getPaySign() {
return paySign;
}
public String getSignature() {
return signature;
}
public String getAppId() {
return appId;
}
public String getSignType() {
return signType;
}
}
| java | Apache-2.0 | f5e7a60e0c377f7420866b229a9ac79e687d5ac5 | 2026-01-05T02:42:41.143783Z | false |
ansitech/weixin4j | https://github.com/ansitech/weixin4j/blob/f5e7a60e0c377f7420866b229a9ac79e687d5ac5/src/main/java/org/weixin4j/model/tags/Tag.java | src/main/java/org/weixin4j/model/tags/Tag.java | /*
* 微信公众平台(JAVA) SDK
*
* Copyright (c) 2014, Ansitech Network Technology Co.,Ltd All rights reserved.
*
* http://www.weixin4j.org/
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.weixin4j.model.tags;
/**
* 用户标签管理
*
* <p>
* 通过<tt>Weixin</tt>产生一个请求对象,通过<code>getUserTags()</code>生成一个<tt>Tags</tt>,集合</p>
*
* @author yangqisheng
* @since 0.0.7
*/
public class Tag {
private int id; //标签id,由微信分配
private String name; //标签名,UTF8编码(30个字符以内)
private int count; //此标签下粉丝数
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getCount() {
return count;
}
public void setCount(int count) {
this.count = count;
}
}
| java | Apache-2.0 | f5e7a60e0c377f7420866b229a9ac79e687d5ac5 | 2026-01-05T02:42:41.143783Z | false |
ansitech/weixin4j | https://github.com/ansitech/weixin4j/blob/f5e7a60e0c377f7420866b229a9ac79e687d5ac5/src/main/java/org/weixin4j/model/js/Ticket.java | src/main/java/org/weixin4j/model/js/Ticket.java | /*
* 微信公众平台(JAVA) SDK
*
* Copyright (c) 2014, Ansitech Network Technology Co.,Ltd All rights reserved.
*
* http://www.weixin4j.org/
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.weixin4j.model.js;
import java.io.Serializable;
import java.util.Date;
/**
* 凭证
*
* @author yangqisheng
* @since 0.1.0
*/
public final class Ticket implements Serializable {
/**
* 凭证字符串
*/
private String ticket;
/**
* 凭证类型
*/
private TicketType ticketType;
/**
* 有效时间(s)
*/
private int expires_in;
/**
* 过期时间
*/
private long exprexpired_time;
/**
* 创建时间
*/
private long create_time;
public Ticket(TicketType ticketType, String ticket, int expires_in) {
this(ticketType, ticket, expires_in, System.currentTimeMillis());
}
public Ticket(TicketType ticketType, String ticket, int expires_in, long create_time) {
this.ticketType = ticketType;
this.ticket = ticket;
this.expires_in = expires_in;
//获取当前时间毫秒数
this.create_time = create_time - 60000;
//设置下次过期时间 = 当前时间 + (凭证有效时间(秒) * 1000)
this.exprexpired_time = this.create_time + (expires_in * 1000);
}
public String getTicket() {
return ticket;
}
public void setTicket(String ticket) {
this.ticket = ticket;
}
public TicketType getTicketType() {
return ticketType;
}
public void setTicketType(TicketType ticketType) {
this.ticketType = ticketType;
}
/**
* 判断凭证是否过期
*
* @return 过期返回 true,否则返回false
*/
public boolean isExprexpired() {
Date now = new Date();
long nowLong = now.getTime();
return nowLong >= exprexpired_time;
}
public int getExpires_in() {
return expires_in;
}
public long getCreate_time() {
return create_time + 60000;
}
/**
* 将数据转换为JSON数据包
*
* @return JSON数据包
*/
@Override
public String toString() {
//对外的时间 需要加上扣掉的 60秒
return "{\"ticket\":\"" + this.getTicket() + "\",\"expires_in\":" + this.getExpires_in() + ",\"create_time\" : " + this.getCreate_time() + "}";
}
}
| java | Apache-2.0 | f5e7a60e0c377f7420866b229a9ac79e687d5ac5 | 2026-01-05T02:42:41.143783Z | false |
ansitech/weixin4j | https://github.com/ansitech/weixin4j/blob/f5e7a60e0c377f7420866b229a9ac79e687d5ac5/src/main/java/org/weixin4j/model/js/WxConfig.java | src/main/java/org/weixin4j/model/js/WxConfig.java | /*
* 微信公众平台(JAVA) SDK
*
* Copyright (c) 2014, Ansitech Network Technology Co.,Ltd All rights reserved.
*
* http://www.weixin4j.org/
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.weixin4j.model.js;
import java.io.Serializable;
/**
* 微信js接口config配置
*
* @author yangqisheng
* @since 0.0.1
*/
public class WxConfig implements Serializable {
private String appId;
private String timestamp;
private String nonceStr;
private String signature;
public String getAppId() {
return appId;
}
public void setAppId(String appId) {
this.appId = appId;
}
public String getTimestamp() {
return timestamp;
}
public void setTimestamp(String timestamp) {
this.timestamp = timestamp;
}
public String getNonceStr() {
return nonceStr;
}
public void setNonceStr(String nonceStr) {
this.nonceStr = nonceStr;
}
public String getSignature() {
return signature;
}
public void setSignature(String signature) {
this.signature = signature;
}
@Override
public String toString() {
return "{appId:\"" + this.getAppId() + "\",\n"
+ "timestamp: \"" + this.getTimestamp() + "\",\n"
+ "nonceStr: \"" + this.getNonceStr() + "\",\n"
+ "signature: \"" + this.getSignature() + "\",}";
}
}
| java | Apache-2.0 | f5e7a60e0c377f7420866b229a9ac79e687d5ac5 | 2026-01-05T02:42:41.143783Z | false |
ansitech/weixin4j | https://github.com/ansitech/weixin4j/blob/f5e7a60e0c377f7420866b229a9ac79e687d5ac5/src/main/java/org/weixin4j/model/js/TicketType.java | src/main/java/org/weixin4j/model/js/TicketType.java | /*
* 微信公众平台(JAVA) SDK
*
* Copyright (c) 2014, Ansitech Network Technology Co.,Ltd All rights reserved.
*
* http://www.weixin4j.org/
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.weixin4j.model.js;
/**
* 临时票据类型
*
* @author yangqisheng
* @since 0.0.1
*/
public enum TicketType {
/**
* 用于调用微信JSSDK的临时票据
*/
JSAPI("jsapi"),
/**
* 用于调用微信卡券相关接口的临时票据
*/
WX_CARD("wx_card");
private String value = "";
TicketType(String value) {
this.value = value;
}
@Override
public String toString() {
return value;
}
}
| java | Apache-2.0 | f5e7a60e0c377f7420866b229a9ac79e687d5ac5 | 2026-01-05T02:42:41.143783Z | false |
ansitech/weixin4j | https://github.com/ansitech/weixin4j/blob/f5e7a60e0c377f7420866b229a9ac79e687d5ac5/src/main/java/org/weixin4j/model/groups/Group.java | src/main/java/org/weixin4j/model/groups/Group.java | /*
* 微信公众平台(JAVA) SDK
*
* Copyright (c) 2014, Ansitech Network Technology Co.,Ltd All rights reserved.
*
* http://www.weixin4j.org/
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.weixin4j.model.groups;
/**
* 微信平台分组对象
*
* @author yangqisheng
* @since 0.0.4
*/
public class Group implements java.io.Serializable {
private int id; //分组id,由微信分配
private String name; //分组名字,UTF8编码(30个字符以内)
private int count; //分组内用户数量
/**
* 获取 分组id
*
* @return 分组id
*/
public int getId() {
return id;
}
/**
* 设置 分组id
*
* @param id 分组id
*/
public void setId(int id) {
this.id = id;
}
/**
* 获取 分组名字
*
* @return 分组名字
*/
public String getName() {
return name;
}
/**
* 设置 分组名字
*
* <p>30个字符以内</p>
*
* @param name 分组名字
*/
public void setName(String name) {
this.name = name;
}
/**
* 获取 用户数量
*
* @return 用户数量
*/
public int getCount() {
return count;
}
/**
* 设置 用户数量
*
* @param count 用户数量
*/
public void setCount(int count) {
this.count = count;
}
}
| java | Apache-2.0 | f5e7a60e0c377f7420866b229a9ac79e687d5ac5 | 2026-01-05T02:42:41.143783Z | false |
ansitech/weixin4j | https://github.com/ansitech/weixin4j/blob/f5e7a60e0c377f7420866b229a9ac79e687d5ac5/src/main/java/org/weixin4j/model/sns/SnsUser.java | src/main/java/org/weixin4j/model/sns/SnsUser.java | /*
* 微信公众平台(JAVA) SDK
*
* Copyright (c) 2014, Ansitech Network Technology Co.,Ltd All rights reserved.
*
* http://www.weixin4j.org/
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.weixin4j.model.sns;
import java.io.Serializable;
/**
* 网页授权用户信息
*
* @author yangqisheng
* @since 0.1.0
*/
public class SnsUser implements Serializable{
private String openid; //用户的标识,对当前公众号唯一
private String nickname; //用户的昵称
private int sex; //用户的性别,值为1时是男性,值为2时是女性,值为0时是未知
private String province; //用户所在省份
private String city; //用户所在城市
private String country; //用户所在国家
private String headimgurl; //用户头像,最后一个数值代表正方形头像大小(有0、46、64、96、132数值可选,0代表640*640正方形头像),用户没有头像时该项为空
private String[] privilege; //用户特权信息,json 数组,如微信沃卡用户为(chinaunicom)
private String unionid; //只有在用户将公众号绑定到微信开放平台帐号后,才会出现该字段。
public String getOpenid() {
return openid;
}
public void setOpenid(String openid) {
this.openid = openid;
}
public String getNickname() {
return nickname;
}
public void setNickname(String nickname) {
this.nickname = nickname;
}
public int getSex() {
return sex;
}
public void setSex(int sex) {
this.sex = sex;
}
public String getProvince() {
return province;
}
public void setProvince(String province) {
this.province = province;
}
public String getCity() {
return city;
}
public void setCity(String city) {
this.city = city;
}
public String getCountry() {
return country;
}
public void setCountry(String country) {
this.country = country;
}
public String getHeadimgurl() {
return headimgurl;
}
public void setHeadimgurl(String headimgurl) {
this.headimgurl = headimgurl;
}
public String[] getPrivilege() {
return privilege;
}
public void setPrivilege(String[] privilege) {
this.privilege = privilege;
}
public String getUnionid() {
return unionid;
}
public void setUnionid(String unionid) {
this.unionid = unionid;
}
}
| java | Apache-2.0 | f5e7a60e0c377f7420866b229a9ac79e687d5ac5 | 2026-01-05T02:42:41.143783Z | false |
ansitech/weixin4j | https://github.com/ansitech/weixin4j/blob/f5e7a60e0c377f7420866b229a9ac79e687d5ac5/src/main/java/org/weixin4j/model/sns/SnsAccessToken.java | src/main/java/org/weixin4j/model/sns/SnsAccessToken.java | /*
* 微信公众平台(JAVA) SDK
*
* Copyright (c) 2014, Ansitech Network Technology Co.,Ltd All rights reserved.
*
* http://www.weixin4j.org/
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.weixin4j.model.sns;
import com.alibaba.fastjson.JSONObject;
import org.weixin4j.WeixinException;
import java.util.Date;
import org.weixin4j.http.Response;
/**
* 网页授权对象
*
* @author yangqisheng
* @since 0.1.0
*/
public final class SnsAccessToken {
private String access_token;
private int expires_in = 7200;
private String refresh_token;
private long expired_time;
private String openid;
private String scope;
/**
* 通过输出对象,从输出对象转换为JSON对象,后获取JSON数据包
*
* <p>
* 正常情况下,微信会返回下述JSON数据包给公众号:
* {"scope":"snsapi_base","openid":"oK4ipw98o-ngjWfSE5WTZmu1hFT0","expires_in":7200,"refresh_token":"5_1wek3jV4FWN9G2HRPb-jjOfy5RQB-neSOAk1l25BogAxfm7G6ELOmxw2xARSYtbg4F3u2hHylqA9O-Um_cv46Q","access_token":"5_g9mZD7zzUGzqtqQjXDBP4BXL1mzvCfl7PvJNc-OGKBq8xwNV_iMEm47fQaj1KhoUrEAhu5VkSXLlICEzt9Zg-A"}</p>
*
* @param response 输出对象
* @throws org.weixin4j.WeixinException 微信操作异常
*/
public SnsAccessToken(Response response) throws WeixinException {
this(response.asJSONObject());
}
/**
* 通过微信公众平台返回JSON对象创建凭证对象
*
* <p>
* 正常情况下,微信会返回下述JSON数据包给公众号:
* {"scope":"snsapi_base","openid":"oK4ipw98o-ngjWfSE5WTZmu1hFT0","expires_in":7200,"refresh_token":"5_1wek3jV4FWN9G2HRPb-jjOfy5RQB-neSOAk1l25BogAxfm7G6ELOmxw2xARSYtbg4F3u2hHylqA9O-Um_cv46Q","access_token":"5_g9mZD7zzUGzqtqQjXDBP4BXL1mzvCfl7PvJNc-OGKBq8xwNV_iMEm47fQaj1KhoUrEAhu5VkSXLlICEzt9Zg-A"}</p>
*
* @param jsonObj JSON数据包
* @throws org.weixin4j.WeixinException 微信操作异常
*/
public SnsAccessToken(JSONObject jsonObj) throws WeixinException {
this.access_token = jsonObj.getString("access_token");
this.expires_in = jsonObj.getIntValue("expires_in");
this.refresh_token = jsonObj.getString("refresh_token");
this.openid = jsonObj.getString("openid");
this.scope = jsonObj.getString("scope");
//设置下次过期时间 = 当前时间 + (凭证有效时间(秒) * 1000)
this.expired_time = System.currentTimeMillis() + (this.expires_in * 1000);
}
public String getAccess_token() {
return access_token;
}
public void setAccess_token(String access_token) {
this.access_token = access_token;
}
/**
* 判断用户凭证是否过期
*
* @return 过期返回 true,否则返回false
*/
public boolean isExprexpired() {
return System.currentTimeMillis() > expired_time;
}
/**
* 将数据转换为JSON数据包
*
* @return JSON数据包
*/
@Override
public String toString() {
return "{\"scope\":\"" + this.getScope()
+ "\",\"openid\":\"" + this.getOpenid()
+ "\",\"expires_in\":" + this.getExpires_in()
+ ",\"refresh_token\":\"" + this.getRefresh_token()
+ "\",\"access_token\":\"" + this.getAccess_token() + "\"}";
}
public int getExpires_in() {
return expires_in;
}
public void setExpires_in(int expires_in) {
this.expires_in = expires_in;
}
public String getRefresh_token() {
return refresh_token;
}
public void setRefresh_token(String refresh_token) {
this.refresh_token = refresh_token;
}
public String getOpenid() {
return openid;
}
public void setOpenid(String openid) {
this.openid = openid;
}
public String getScope() {
return scope;
}
public void setScope(String scope) {
this.scope = scope;
}
}
| java | Apache-2.0 | f5e7a60e0c377f7420866b229a9ac79e687d5ac5 | 2026-01-05T02:42:41.143783Z | false |
ansitech/weixin4j | https://github.com/ansitech/weixin4j/blob/f5e7a60e0c377f7420866b229a9ac79e687d5ac5/src/main/java/org/weixin4j/model/message/PicList.java | src/main/java/org/weixin4j/model/message/PicList.java | /*
* 微信公众平台(JAVA) SDK
*
* Copyright (c) 2014, Ansitech Network Technology Co.,Ltd All rights reserved.
*
* http://www.weixin4j.org/
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.weixin4j.model.message;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
/**
* 图片
*
* @author yangqisheng
* @since 0.0.1
*/
@XmlRootElement(name = "item")
public class PicList {
//图片的MD5值,开发者若需要,可用于验证接收到图片
private String PicMd5Sum;
public String getPicMd5Sum() {
return PicMd5Sum;
}
@XmlElement(name = "PicMd5Sum")
public void setPicMd5Sum(String PicMd5Sum) {
this.PicMd5Sum = PicMd5Sum;
}
}
| java | Apache-2.0 | f5e7a60e0c377f7420866b229a9ac79e687d5ac5 | 2026-01-05T02:42:41.143783Z | false |
ansitech/weixin4j | https://github.com/ansitech/weixin4j/blob/f5e7a60e0c377f7420866b229a9ac79e687d5ac5/src/main/java/org/weixin4j/model/message/Voice.java | src/main/java/org/weixin4j/model/message/Voice.java | /*
* 微信公众平台(JAVA) SDK
*
* Copyright (c) 2014, Ansitech Network Technology Co.,Ltd All rights reserved.
*
* http://www.weixin4j.org/
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.weixin4j.model.message;
/**
* 回复语音消息中的语音对象
*
* <p>提供了获取语音Id<code>getMediaId()</code>等主要方法.</p>
*
* @author yangqisheng
* @since 0.0.1
*/
public class Voice implements java.io.Serializable {
private String MediaId; //通过上传多媒体文件,得到的id
/**
* 获取 通过上传多媒体文件,得到的id
*
* @return 通过上传多媒体文件,得到的id
*/
public String getMediaId() {
return MediaId;
}
/**
* 设置 通过上传多媒体文件,得到的id
*
* @param mediaId 通过上传多媒体文件,得到的id
*/
public void setMediaId(String mediaId) {
this.MediaId = mediaId;
}
} | java | Apache-2.0 | f5e7a60e0c377f7420866b229a9ac79e687d5ac5 | 2026-01-05T02:42:41.143783Z | false |
ansitech/weixin4j | https://github.com/ansitech/weixin4j/blob/f5e7a60e0c377f7420866b229a9ac79e687d5ac5/src/main/java/org/weixin4j/model/message/MediaType.java | src/main/java/org/weixin4j/model/message/MediaType.java | /*
* 微信公众平台(JAVA) SDK
*
* Copyright (c) 2014, Ansitech Network Technology Co.,Ltd All rights reserved.
*
* http://www.weixin4j.org/
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.weixin4j.model.message;
/**
*
* 素材类型
*
* @author yangqisheng
* @since 0.0.1
*/
public enum MediaType {
/**
* 图片
*/
Image("image"),
/**
* 语音
*/
Voice("voice"),
/**
* 视频
*/
Video("video"),
/**
* 缩略图
*/
Thumb("thumb");
private String value = "";
MediaType(String value) {
this.value = value;
}
// /**
// * 根据媒体类型字符串,返回媒体类型枚举对象
// *
// * @param mediaType 媒体类型字符串
// * @return 媒体类型枚举对象
// */
// public MediaType valueOf(String mediaType) {
// if (mediaType.equals(Voice.toString())) {
// return Voice;
// }
// if (mediaType.equals(Image.toString())) {
// return Image;
// }
// if (mediaType.equals(Video.toString())) {
// return Image;
// }
// if (mediaType.equals(Thumb.toString())) {
// return Image;
// }
// return null;
// }
@Override
public String toString() {
return value;
}
}
| java | Apache-2.0 | f5e7a60e0c377f7420866b229a9ac79e687d5ac5 | 2026-01-05T02:42:41.143783Z | false |
ansitech/weixin4j | https://github.com/ansitech/weixin4j/blob/f5e7a60e0c377f7420866b229a9ac79e687d5ac5/src/main/java/org/weixin4j/model/message/Image.java | src/main/java/org/weixin4j/model/message/Image.java | /*
* 微信公众平台(JAVA) SDK
*
* Copyright (c) 2014, Ansitech Network Technology Co.,Ltd All rights reserved.
*
* http://www.weixin4j.org/
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.weixin4j.model.message;
/**
* 回复图片消息中的图片对象
*
* <p>
* 提供了获取图片Id<code>getMediaId()</code>等主要方法.</p>
*
* @author yangqisheng
* @since 0.0.1
*/
public class Image implements java.io.Serializable {
private String MediaId; //通过上传多媒体文件,得到的id
/**
* 获取 通过上传多媒体文件,得到的id
*
* @return 通过上传多媒体文件,得到的id
*/
public String getMediaId() {
return MediaId;
}
/**
* 设置 通过上传多媒体文件,得到的id
*
* @param mediaId 通过上传多媒体文件,得到的id
*/
public void setMediaId(String mediaId) {
this.MediaId = mediaId;
}
}
| java | Apache-2.0 | f5e7a60e0c377f7420866b229a9ac79e687d5ac5 | 2026-01-05T02:42:41.143783Z | false |
ansitech/weixin4j | https://github.com/ansitech/weixin4j/blob/f5e7a60e0c377f7420866b229a9ac79e687d5ac5/src/main/java/org/weixin4j/model/message/InputMessage.java | src/main/java/org/weixin4j/model/message/InputMessage.java | /*
* 微信公众平台(JAVA) SDK
*
* Copyright (c) 2014, Ansitech Network Technology Co.,Ltd All rights reserved.
*
* http://www.weixin4j.org/
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.weixin4j.model.message;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import org.weixin4j.model.message.event.ClickEventMessage;
import org.weixin4j.model.message.event.EventMessage;
import org.weixin4j.model.message.event.LocationEventMessage;
import org.weixin4j.model.message.event.LocationSelectEventMessage;
import org.weixin4j.model.message.event.PicPhotoOrAlbumEventMessage;
import org.weixin4j.model.message.event.PicSysPhotoEventMessage;
import org.weixin4j.model.message.event.PicWeixinEventMessage;
import org.weixin4j.model.message.event.QrsceneScanEventMessage;
import org.weixin4j.model.message.event.QrsceneSubscribeEventMessage;
import org.weixin4j.model.message.event.ScanCodePushEventMessage;
import org.weixin4j.model.message.event.ScanCodeWaitMsgEventMessage;
import org.weixin4j.model.message.event.SubscribeEventMessage;
import org.weixin4j.model.message.event.UnSubscribeEventMessage;
import org.weixin4j.model.message.event.ViewEventMessage;
import org.weixin4j.model.message.normal.ImageInputMessage;
import org.weixin4j.model.message.normal.LinkInputMessage;
import org.weixin4j.model.message.normal.LocationInputMessage;
import org.weixin4j.model.message.normal.NormalMessage;
import org.weixin4j.model.message.normal.ShortVideoInputMessage;
import org.weixin4j.model.message.normal.TextInputMessage;
import org.weixin4j.model.message.normal.VideoInputMessage;
import org.weixin4j.model.message.normal.VoiceInputMessage;
/**
* POST的XML数据包转换为消息接受对象
*
* <p>
* 由于POST的是XML数据包,所以不确定为哪种接受消息,
* 所以直接将所有字段都进行转换,最后根据<tt>MsgType</tt>字段来判断取何种数据</p>
*
* @author yangqisheng
* @since 0.0.1
*/
@XmlRootElement(name = "xml")
public class InputMessage extends NormalMessage {
private String MsgType = "text";
// 文本消息
private String Content;
// 图片消息
private String PicUrl;
// 位置消息
private String Location_X;
private String Location_Y;
private Long Scale;
private String Label;
// 链接消息
private String Title;
private String Description;
private String Url;
// 语音信息 视频消息
private String MediaId;
private String Format;
private String Recognition;
//视频消息 视频消息缩略图的媒体id,可以调用多媒体文件下载接口拉取数据。
private String ThumbMediaId;
// 事件
private String Event;
private String EventKey;
private String Ticket;
private String MenuId;
//上报地理位置事件
private String Latitude;
private String Longitude;
private String Precision;
//群发消息事件
private String MsgID;
private String Status;
private int TotalCount;
private int FilterCount;
private int SentCount;
private int ErrorCount;
//扫码推事件
private ScanCodeInfo ScanCodeInfo;
//拍照发图
private SendPicsInfo SendPicsInfo;
//发送地理位置
private SendLocationInfo SendLocationInfo;
@Override
public String getMsgType() {
return MsgType;
}
@XmlElement(name = "MsgType")
public void setMsgType(String msgType) {
MsgType = msgType;
}
public String getContent() {
return Content;
}
@XmlElement(name = "Content")
public void setContent(String content) {
Content = content;
}
public String getPicUrl() {
return PicUrl;
}
@XmlElement(name = "PicUrl")
public void setPicUrl(String picUrl) {
PicUrl = picUrl;
}
public String getLocation_X() {
return Location_X;
}
@XmlElement(name = "Location_X")
public void setLocation_X(String locationX) {
Location_X = locationX;
}
public String getLocation_Y() {
return Location_Y;
}
@XmlElement(name = "Location_Y")
public void setLocationY(String location_Y) {
Location_Y = location_Y;
}
public Long getScale() {
return Scale;
}
@XmlElement(name = "Scale")
public void setScale(Long scale) {
Scale = scale;
}
public String getLabel() {
return Label;
}
@XmlElement(name = "Label")
public void setLabel(String label) {
Label = label;
}
public String getTitle() {
return Title;
}
@XmlElement(name = "Title")
public void setTitle(String title) {
Title = title;
}
public String getDescription() {
return Description;
}
@XmlElement(name = "Description")
public void setDescription(String description) {
Description = description;
}
public String getUrl() {
return Url;
}
@XmlElement(name = "Url")
public void setUrl(String url) {
Url = url;
}
public String getEvent() {
//转成小写
return Event.toLowerCase();
}
@XmlElement(name = "Event")
public void setEvent(String event) {
Event = event;
}
public String getEventKey() {
return EventKey;
}
@XmlElement(name = "EventKey")
public void setEventKey(String eventKey) {
EventKey = eventKey;
}
public String getMediaId() {
return MediaId;
}
@XmlElement(name = "MediaId")
public void setMediaId(String mediaId) {
MediaId = mediaId;
}
public String getThumbMediaId() {
return ThumbMediaId;
}
@XmlElement(name = "ThumbMediaId")
public void setThumbMediaId(String ThumbMediaId) {
this.ThumbMediaId = ThumbMediaId;
}
public String getFormat() {
return Format;
}
@XmlElement(name = "Format")
public void setFormat(String format) {
Format = format;
}
public String getRecognition() {
return Recognition;
}
@XmlElement(name = "Recognition")
public void setRecognition(String recognition) {
Recognition = recognition;
}
public String getTicket() {
return Ticket;
}
@XmlElement(name = "Ticket")
public void setTicket(String ticket) {
Ticket = ticket;
}
public String getLatitude() {
return Latitude;
}
@XmlElement(name = "Latitude")
public void setLatitude(String Latitude) {
this.Latitude = Latitude;
}
public String getLongitude() {
return Longitude;
}
@XmlElement(name = "Longitude")
public void setLongitude(String Longitude) {
this.Longitude = Longitude;
}
public String getPrecision() {
return Precision;
}
@XmlElement(name = "Precision")
public void setPrecision(String Precision) {
this.Precision = Precision;
}
public String getStatus() {
return Status;
}
@XmlElement(name = "Status")
public void setStatus(String Status) {
this.Status = Status;
}
public int getTotalCount() {
return TotalCount;
}
@XmlElement(name = "TotalCount")
public void setTotalCount(int TotalCount) {
this.TotalCount = TotalCount;
}
public int getFilterCount() {
return FilterCount;
}
@XmlElement(name = "FilterCount")
public void setFilterCount(int FilterCount) {
this.FilterCount = FilterCount;
}
public int getSentCount() {
return SentCount;
}
@XmlElement(name = "SentCount")
public void setSentCount(int SentCount) {
this.SentCount = SentCount;
}
public int getErrorCount() {
return ErrorCount;
}
@XmlElement(name = "ErrorCount")
public void setErrorCount(int ErrorCount) {
this.ErrorCount = ErrorCount;
}
public String getMsgID() {
return MsgID;
}
@XmlElement(name = "MsgID")
public void setMsgID(String MsgID) {
this.MsgID = MsgID;
}
public ScanCodeInfo getScanCodeInfo() {
return ScanCodeInfo;
}
@XmlElement(name = "ScanCodeInfo")
public void setScanCodeInfo(ScanCodeInfo ScanCodeInfo) {
this.ScanCodeInfo = ScanCodeInfo;
}
public SendLocationInfo getSendLocationInfo() {
return SendLocationInfo;
}
@XmlElement(name = "SendLocationInfo")
public void setSendLocationInfo(SendLocationInfo SendLocationInfo) {
this.SendLocationInfo = SendLocationInfo;
}
public SendPicsInfo getSendPicsInfo() {
return SendPicsInfo;
}
@XmlElement(name = "SendPicsInfo")
public void setSendPicsInfo(SendPicsInfo SendPicsInfo) {
this.SendPicsInfo = SendPicsInfo;
}
public TextInputMessage toTextInputMessage() {
TextInputMessage inputMessage = new TextInputMessage(Content);
initNormalMessage(inputMessage);
return inputMessage;
}
public ImageInputMessage toImageInputMessage() {
ImageInputMessage inputMessage = new ImageInputMessage();
inputMessage.setPicUrl(PicUrl);
inputMessage.setMediaId(MediaId);
initNormalMessage(inputMessage);
return inputMessage;
}
public VoiceInputMessage toVoiceInputMessage() {
VoiceInputMessage inputMessage = new VoiceInputMessage();
inputMessage.setFormat(Format);
inputMessage.setMediaId(MediaId);
inputMessage.setRecognition(Recognition);
initNormalMessage(inputMessage);
return inputMessage;
}
public VideoInputMessage toVideoInputMessage() {
VideoInputMessage inputMessage = new VideoInputMessage();
inputMessage.setMediaId(MediaId);
inputMessage.setThumbMediaId(ThumbMediaId);
initNormalMessage(inputMessage);
return inputMessage;
}
public ShortVideoInputMessage toShortVideoInputMessage() {
ShortVideoInputMessage inputMessage = new ShortVideoInputMessage();
inputMessage.setMediaId(MediaId);
inputMessage.setThumbMediaId(ThumbMediaId);
initNormalMessage(inputMessage);
return inputMessage;
}
public LocationInputMessage toLocationInputMessage() {
LocationInputMessage inputMessage = new LocationInputMessage();
inputMessage.setLocation_X(Location_X);
inputMessage.setLocation_Y(Location_Y);
inputMessage.setLabel(Label);
inputMessage.setScale(Scale);
initNormalMessage(inputMessage);
return inputMessage;
}
public LinkInputMessage toLinkInputMessage() {
LinkInputMessage inputMessage = new LinkInputMessage();
inputMessage.setTitle(Title);
inputMessage.setDescription(Description);
inputMessage.setUrl(Url);
initNormalMessage(inputMessage);
return inputMessage;
}
public SubscribeEventMessage toSubscribeEventMessage() {
SubscribeEventMessage eventMessage = new SubscribeEventMessage();
initEventMessage(eventMessage);
return eventMessage;
}
public UnSubscribeEventMessage toUnSubscribeEventMessage() {
UnSubscribeEventMessage eventMessage = new UnSubscribeEventMessage();
initEventMessage(eventMessage);
return eventMessage;
}
public QrsceneScanEventMessage toQrsceneScanEventMessage() {
QrsceneScanEventMessage eventMessage = new QrsceneScanEventMessage();
eventMessage.setEventKey(EventKey);
eventMessage.setTicket(Ticket);
initEventMessage(eventMessage);
return eventMessage;
}
public QrsceneSubscribeEventMessage toQrsceneSubscribeEventMessage() {
QrsceneSubscribeEventMessage eventMessage = new QrsceneSubscribeEventMessage();
eventMessage.setEventKey(EventKey);
eventMessage.setTicket(Ticket);
initEventMessage(eventMessage);
return eventMessage;
}
public LocationEventMessage toLocationEventMessage() {
LocationEventMessage eventMessage = new LocationEventMessage();
eventMessage.setLatitude(Latitude);
eventMessage.setLongitude(Longitude);
eventMessage.setPrecision(Precision);
initEventMessage(eventMessage);
return eventMessage;
}
public ClickEventMessage toClickEventMessage() {
ClickEventMessage eventMessage = new ClickEventMessage();
eventMessage.setEventKey(EventKey);
initEventMessage(eventMessage);
return eventMessage;
}
public ViewEventMessage toViewEventMessage() {
ViewEventMessage eventMessage = new ViewEventMessage();
eventMessage.setEventKey(EventKey);
eventMessage.setMenuId(MenuId);
initEventMessage(eventMessage);
return eventMessage;
}
public ScanCodePushEventMessage toScanCodePushEventMessage() {
ScanCodePushEventMessage eventMessage = new ScanCodePushEventMessage();
eventMessage.setEventKey(EventKey);
eventMessage.setScanCodeInfo(ScanCodeInfo);
initEventMessage(eventMessage);
return eventMessage;
}
public ScanCodeWaitMsgEventMessage toScanCodeWaitMsgEventMessage() {
ScanCodeWaitMsgEventMessage eventMessage = new ScanCodeWaitMsgEventMessage();
eventMessage.setEventKey(EventKey);
eventMessage.setScanCodeInfo(ScanCodeInfo);
initEventMessage(eventMessage);
return eventMessage;
}
public PicSysPhotoEventMessage toPicSysPhotoEventMessage() {
PicSysPhotoEventMessage eventMessage = new PicSysPhotoEventMessage();
eventMessage.setEventKey(EventKey);
eventMessage.setSendPicsInfo(SendPicsInfo);
initEventMessage(eventMessage);
return eventMessage;
}
public PicPhotoOrAlbumEventMessage toPicPhotoOrAlbumEventMessage() {
PicPhotoOrAlbumEventMessage eventMessage = new PicPhotoOrAlbumEventMessage();
eventMessage.setEventKey(EventKey);
eventMessage.setSendPicsInfo(SendPicsInfo);
initEventMessage(eventMessage);
return eventMessage;
}
public PicWeixinEventMessage toPicWeixinEventMessage() {
PicWeixinEventMessage eventMessage = new PicWeixinEventMessage();
eventMessage.setEventKey(EventKey);
eventMessage.setSendPicsInfo(SendPicsInfo);
initEventMessage(eventMessage);
return eventMessage;
}
public LocationSelectEventMessage toLocationSelectEventMessage() {
LocationSelectEventMessage eventMessage = new LocationSelectEventMessage();
eventMessage.setEventKey(EventKey);
eventMessage.setSendLocationInfo(SendLocationInfo);
initEventMessage(eventMessage);
return eventMessage;
}
private void initNormalMessage(NormalMessage inputMessage) {
inputMessage.setToUserName(this.getToUserName());
inputMessage.setFromUserName(this.getFromUserName());
inputMessage.setMsgId(this.getMsgId());
inputMessage.setCreateTime(this.getCreateTime());
}
private void initEventMessage(EventMessage eventMessage) {
eventMessage.setToUserName(this.getToUserName());
eventMessage.setFromUserName(this.getFromUserName());
eventMessage.setCreateTime(this.getCreateTime());
}
public String getMenuId() {
return MenuId;
}
@XmlElement(name = "MenuId")
public void setMenuId(String MenuId) {
this.MenuId = MenuId;
}
}
| java | Apache-2.0 | f5e7a60e0c377f7420866b229a9ac79e687d5ac5 | 2026-01-05T02:42:41.143783Z | false |
ansitech/weixin4j | https://github.com/ansitech/weixin4j/blob/f5e7a60e0c377f7420866b229a9ac79e687d5ac5/src/main/java/org/weixin4j/model/message/EventType.java | src/main/java/org/weixin4j/model/message/EventType.java | /*
* 微信公众平台(JAVA) SDK
*
* Copyright (c) 2014, Ansitech Network Technology Co.,Ltd All rights reserved.
*
* http://www.weixin4j.org/
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.weixin4j.model.message;
/**
* 事件类型
*
* @author yangqisheng
* @since 0.0.1
*/
public enum EventType {
/**
* 订阅
*/
Subscribe("subscribe"),
/**
* 取消订阅
*/
Unsubscribe("unsubscribe"),
/**
* 已关注用户扫描带参数二维码
*/
Scan("scan"),
/**
* 上报地理位置
*/
Location("location"),
/**
* 点击自定义菜单
*/
Click("click"),
/**
* 查看菜单
*/
View("view"),
/**
* 扫码推事件
*/
Scancode_Push("scancode_push"),
/**
* 扫码推事件
*/
Scancode_Waitmsg("scancode_waitmsg"),
/**
* 弹出系统拍照发图的事件
*/
Pic_Sysphoto("pic_sysphoto"),
/**
* 弹出拍照或者相册发图的事件
*/
Pic_Photo_OR_Album("pic_photo_or_album"),
/**
* 弹出微信相册发图器的事件
*/
Pic_Weixin("pic_weixin"),
/**
* 弹出地理位置选择器的事件
*/
Location_Select("location_select");
private String value = "";
EventType(String value) {
this.value = value;
}
/**
* @return the msgType
*/
@Override
public String toString() {
return value;
}
}
| java | Apache-2.0 | f5e7a60e0c377f7420866b229a9ac79e687d5ac5 | 2026-01-05T02:42:41.143783Z | false |
ansitech/weixin4j | https://github.com/ansitech/weixin4j/blob/f5e7a60e0c377f7420866b229a9ac79e687d5ac5/src/main/java/org/weixin4j/model/message/SendLocationInfo.java | src/main/java/org/weixin4j/model/message/SendLocationInfo.java | /*
* 微信公众平台(JAVA) SDK
*
* Copyright (c) 2014, Ansitech Network Technology Co.,Ltd All rights reserved.
*
* http://www.weixin4j.org/
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.weixin4j.model.message;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
/**
* 发送的位置信息
*
* @author yangqisheng
* @since 0.0.1
*/
@XmlRootElement(name = "SendLocationInfo")
public class SendLocationInfo {
//X坐标信息
private double Location_X;
//Y坐标信息
private double Location_Y;
//精度,可理解为精度或者比例尺、越精细的话 scale越高
private int Scale;
//地理位置的字符串信息
private String Label;
//朋友圈POI的名字,可能为空
private String Poiname;
public double getLocation_X() {
return Location_X;
}
@XmlElement(name = "Location_X")
public void setLocation_X(double Location_X) {
this.Location_X = Location_X;
}
public double getLocation_Y() {
return Location_Y;
}
@XmlElement(name = "Location_Y")
public void setLocation_Y(double Location_Y) {
this.Location_Y = Location_Y;
}
public int getScale() {
return Scale;
}
@XmlElement(name = "Scale")
public void setScale(int Scale) {
this.Scale = Scale;
}
public String getLabel() {
return Label;
}
@XmlElement(name = "Label")
public void setLabel(String Label) {
this.Label = Label;
}
public String getPoiname() {
return Poiname;
}
@XmlElement(name = "Poiname")
public void setPoiname(String Poiname) {
this.Poiname = Poiname;
}
}
| java | Apache-2.0 | f5e7a60e0c377f7420866b229a9ac79e687d5ac5 | 2026-01-05T02:42:41.143783Z | false |
ansitech/weixin4j | https://github.com/ansitech/weixin4j/blob/f5e7a60e0c377f7420866b229a9ac79e687d5ac5/src/main/java/org/weixin4j/model/message/Video.java | src/main/java/org/weixin4j/model/message/Video.java | /*
* 微信公众平台(JAVA) SDK
*
* Copyright (c) 2014, Ansitech Network Technology Co.,Ltd All rights reserved.
*
* http://www.weixin4j.org/
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.weixin4j.model.message;
/**
* 回复视频消息中的视频对象
*
* <p>提供了获取视频Id<code>getMediaId()</code>等主要方法.</p>
*
* @author yangqisheng
* @since 0.0.1
*/
public class Video implements java.io.Serializable {
private String MediaId; //通过上传多媒体文件,得到的id
private String Title; //视频消息的标题
private String Description; //视频消息的描述
/**
* 获取 通过上传多媒体文件,得到的id
*
* @return 通过上传多媒体文件,得到的id
*/
public String getMediaId() {
return MediaId;
}
/**
* 设置 通过上传多媒体文件,得到的id
*
* @param mediaId 通过上传多媒体文件,得到的id
*/
public void setMediaId(String mediaId) {
this.MediaId = mediaId;
}
/**
* @return the Title
*/
public String getTitle() {
return Title;
}
/**
* @param Title the Title to set
*/
public void setTitle(String Title) {
this.Title = Title;
}
/**
* @return the Description
*/
public String getDescription() {
return Description;
}
/**
* @param Description the Description to set
*/
public void setDescription(String Description) {
this.Description = Description;
}
}
| java | Apache-2.0 | f5e7a60e0c377f7420866b229a9ac79e687d5ac5 | 2026-01-05T02:42:41.143783Z | false |
ansitech/weixin4j | https://github.com/ansitech/weixin4j/blob/f5e7a60e0c377f7420866b229a9ac79e687d5ac5/src/main/java/org/weixin4j/model/message/Music.java | src/main/java/org/weixin4j/model/message/Music.java | /*
* 微信公众平台(JAVA) SDK
*
* Copyright (c) 2014, Ansitech Network Technology Co.,Ltd All rights reserved.
*
* http://www.weixin4j.org/
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.weixin4j.model.message;
/**
* 回复音乐消息中的音乐对象
*
* @author yangqisheng
* @since 0.0.1
*/
public class Music implements java.io.Serializable {
private String Title; //音乐标题
private String Description; //音乐描述
private String MusicUrl; //音乐链接
private String HQMusicUrl; //高质量音乐链接,WIFI环境优先使用该链接播放音乐
private String ThumbMediaId; //缩略图的媒体id,通过上传多媒体文件,得到的id
public String getTitle() {
return Title;
}
public void setTitle(String Title) {
this.Title = Title;
}
public String getDescription() {
return Description;
}
public void setDescription(String Description) {
this.Description = Description;
}
public String getMusicUrl() {
return MusicUrl;
}
public void setMusicUrl(String MusicUrl) {
this.MusicUrl = MusicUrl;
}
public String getHQMusicUrl() {
return HQMusicUrl;
}
public void setHQMusicUrl(String HQMusicUrl) {
this.HQMusicUrl = HQMusicUrl;
}
public String getThumbMediaId() {
return ThumbMediaId;
}
public void setThumbMediaId(String ThumbMediaId) {
this.ThumbMediaId = ThumbMediaId;
}
}
| java | Apache-2.0 | f5e7a60e0c377f7420866b229a9ac79e687d5ac5 | 2026-01-05T02:42:41.143783Z | false |
ansitech/weixin4j | https://github.com/ansitech/weixin4j/blob/f5e7a60e0c377f7420866b229a9ac79e687d5ac5/src/main/java/org/weixin4j/model/message/MsgType.java | src/main/java/org/weixin4j/model/message/MsgType.java | /*
* 微信公众平台(JAVA) SDK
*
* Copyright (c) 2014, Ansitech Network Technology Co.,Ltd All rights reserved.
*
* http://www.weixin4j.org/
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.weixin4j.model.message;
/**
* 消息类型
*
* @author yangqisheng
* @since 0.0.1
*/
public enum MsgType {
/**
* 1 文本消息
*/
Text("text"),
/**
* 2 图片消息
*/
Image("image"),
/**
* 3 语音消息
*/
Voice("voice"),
/**
* 4 视频消息
*/
Video("video"),
/**
* 5 小视频消息
*/
ShortVideo("shortvideo"),
/**
* 6 地理位置消息
*/
Location("location"),
/**
* 7 链接消息
*/
Link("link"),
/**
* 事件消息
*/
Event("event"),
/**
* 音乐消息
*/
Music("music"),
/**
* 图文消息
*/
News("news");
private String value = "";
MsgType(String value) {
this.value = value;
}
/**
* @return the msgType
*/
@Override
public String toString() {
return value;
}
}
| java | Apache-2.0 | f5e7a60e0c377f7420866b229a9ac79e687d5ac5 | 2026-01-05T02:42:41.143783Z | false |
ansitech/weixin4j | https://github.com/ansitech/weixin4j/blob/f5e7a60e0c377f7420866b229a9ac79e687d5ac5/src/main/java/org/weixin4j/model/message/Articles.java | src/main/java/org/weixin4j/model/message/Articles.java | /*
* 微信公众平台(JAVA) SDK
*
* Copyright (c) 2014, Ansitech Network Technology Co.,Ltd All rights reserved.
*
* http://www.weixin4j.org/
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.weixin4j.model.message;
/**
* 实体类对象,用来接受<tt>NewsOutputMessage</tt>中的条目
*
* @author yangqisheng
* @since 0.0.1
*/
public class Articles {
/**
* 图文消息标题
*/
private String Title;
/**
* 图文消息描述
*/
private String Description;
/**
* 发送被动响应时设置的图片url
* 图片链接,支持JPG、PNG格式,较好的效果为大图360*200,小图200*200
*/
private String PicUrl;
/**
* 发送客服消息时设置的图片URL
*/
private String picurl;
/**
* 点击图文消息跳转链接
*/
private String Url;
/**
* 获取 图文消息的标题
*
* @return 图文消息的标题
*/
public String getTitle() {
return Title;
}
/**
* 设置 图文消息的标题
*
* @param Title 图文消息的标题
*/
public void setTitle(String Title) {
this.Title = Title;
}
/**
* 获取 图文消息的描述
*
* @return 图文消息的描述
*/
public String getDescription() {
return Description;
}
/**
* 设置 图文消息的描述
*
* @param Description 图文消息的描述
*/
public void setDescription(String Description) {
this.Description = Description;
}
/**
* 获取 图片链接
*
* @return 图片链接
*/
public String getPicUrl() {
return PicUrl;
}
/**
* 设置 图片链接
*
* @param PicUrl 图片链接,支持JPG、PNG格式,较好的效果为大图360*200,小图200*200
*/
public void setPicUrl(String PicUrl) {
this.PicUrl = PicUrl;
}
/**
* 获取 点击图文消息跳转链接
*
* @return 点击图文消息跳转链接
*/
public String getUrl() {
return Url;
}
/**
* 设置 点击图文消息跳转链接
*
* @param Url 点击图文消息跳转链接
*/
public void setUrl(String Url) {
this.Url = Url;
}
/**
* @return the picurl
*/
public String getPicurl() {
return picurl;
}
/**
* @param picurl the picurl to set
*/
public void setPicurl(String picurl) {
this.picurl = picurl;
}
}
| java | Apache-2.0 | f5e7a60e0c377f7420866b229a9ac79e687d5ac5 | 2026-01-05T02:42:41.143783Z | false |
ansitech/weixin4j | https://github.com/ansitech/weixin4j/blob/f5e7a60e0c377f7420866b229a9ac79e687d5ac5/src/main/java/org/weixin4j/model/message/OutputMessage.java | src/main/java/org/weixin4j/model/message/OutputMessage.java | /*
* 微信公众平台(JAVA) SDK
*
* Copyright (c) 2014, Ansitech Network Technology Co.,Ltd All rights reserved.
*
* http://www.weixin4j.org/
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.weixin4j.model.message;
/**
* 微信发送被动响应消息的抽象类
*
* <p>
* 应用程序需要定义一个子类,来实现具体方法</p>
*
* @author yangqisheng
* @since 0.0.1
*/
public abstract class OutputMessage implements java.io.Serializable {
/**
* 接收方帐号(收到的OpenID)
*/
private String ToUserName;
/**
* 开发者微信号
*/
private String FromUserName;
/**
* 消息创建时间 (整型)
*/
private Long CreateTime;
/**
* 获取 接收方帐号(收到的OpenID)
*
* @return 接收方帐号(收到的OpenID)
*/
public String getToUserName() {
return ToUserName;
}
/**
* 设置 接收方帐号(收到的OpenID)
*
* @return 接收方帐号(收到的OpenID)
*/
public String getFromUserName() {
return FromUserName;
}
/**
* 获取 消息创建时间 (整型)
*
* @return 消息创建时间 (整型)
*/
public Long getCreateTime() {
return CreateTime;
}
/**
* 获取 消息类型
*
* @return 消息类型
*/
public abstract String getMsgType();
/**
* 将对象转换为xml字符串
*
* @return 对象xml字符串
*/
public abstract String toXML();
public void setToUserName(String ToUserName) {
this.ToUserName = ToUserName;
}
public void setFromUserName(String FromUserName) {
this.FromUserName = FromUserName;
}
public void setCreateTime(Long CreateTime) {
this.CreateTime = CreateTime;
}
}
| java | Apache-2.0 | f5e7a60e0c377f7420866b229a9ac79e687d5ac5 | 2026-01-05T02:42:41.143783Z | false |
ansitech/weixin4j | https://github.com/ansitech/weixin4j/blob/f5e7a60e0c377f7420866b229a9ac79e687d5ac5/src/main/java/org/weixin4j/model/message/SendPicsInfo.java | src/main/java/org/weixin4j/model/message/SendPicsInfo.java | /*
* 微信公众平台(JAVA) SDK
*
* Copyright (c) 2014, Ansitech Network Technology Co.,Ltd All rights reserved.
*
* http://www.weixin4j.org/
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.weixin4j.model.message;
import java.util.List;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlElementWrapper;
import javax.xml.bind.annotation.XmlRootElement;
/**
* 发送的图片信息
*
* @author yangqisheng
* @since 0.0.1
*/
@XmlRootElement(name = "SendPicsInfo")
public class SendPicsInfo {
//发送的图片数量
private int Count;
//图片列表
private List<PicList> PicList;
public int getCount() {
return Count;
}
@XmlElement(name = "Count")
public void setCount(int Count) {
this.Count = Count;
}
public List<PicList> getPicList() {
return PicList;
}
@XmlElementWrapper(name = "PicList")
@XmlElement(name = "item")
public void setPicList(List<PicList> PicList) {
this.PicList = PicList;
}
}
| java | Apache-2.0 | f5e7a60e0c377f7420866b229a9ac79e687d5ac5 | 2026-01-05T02:42:41.143783Z | false |
ansitech/weixin4j | https://github.com/ansitech/weixin4j/blob/f5e7a60e0c377f7420866b229a9ac79e687d5ac5/src/main/java/org/weixin4j/model/message/ScanCodeInfo.java | src/main/java/org/weixin4j/model/message/ScanCodeInfo.java | /*
* 微信公众平台(JAVA) SDK
*
* Copyright (c) 2014, Ansitech Network Technology Co.,Ltd All rights reserved.
*
* http://www.weixin4j.org/
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.weixin4j.model.message;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
/**
* 扫描信息
*
* @author yangqisheng
* @since 0.0.1
*/
@XmlRootElement(name = "ScanCodeInfo")
public class ScanCodeInfo {
//扫描类型,一般是qrcode
private String ScanType;
//扫描结果,即二维码对应的字符串信息
private String ScanResult;
public String getScanType() {
return ScanType;
}
@XmlElement(name = "ScanType")
public void setScanType(String ScanType) {
this.ScanType = ScanType;
}
public String getScanResult() {
return ScanResult;
}
@XmlElement(name = "ScanResult")
public void setScanResult(String ScanResult) {
this.ScanResult = ScanResult;
}
}
| java | Apache-2.0 | f5e7a60e0c377f7420866b229a9ac79e687d5ac5 | 2026-01-05T02:42:41.143783Z | false |
ansitech/weixin4j | https://github.com/ansitech/weixin4j/blob/f5e7a60e0c377f7420866b229a9ac79e687d5ac5/src/main/java/org/weixin4j/model/message/normal/LocationInputMessage.java | src/main/java/org/weixin4j/model/message/normal/LocationInputMessage.java | /*
* 微信公众平台(JAVA) SDK
*
* Copyright (c) 2014, Ansitech Network Technology Co.,Ltd All rights reserved.
*
* http://www.weixin4j.org/
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.weixin4j.model.message.normal;
import org.weixin4j.model.message.MsgType;
/**
* 地理位置消息
*
* @author yangqisheng
* @since 0.0.1
*/
public class LocationInputMessage extends NormalMessage {
//地理位置维度
private String Location_X;
//地理位置经度
private String Location_Y;
//地图缩放大小
private Long Scale;
//地理位置信息
private String Label;
@Override
public String getMsgType() {
return MsgType.Location.toString();
}
public String getLocation_X() {
return Location_X;
}
public void setLocation_X(String Location_X) {
this.Location_X = Location_X;
}
public String getLocation_Y() {
return Location_Y;
}
public void setLocation_Y(String Location_Y) {
this.Location_Y = Location_Y;
}
public Long getScale() {
return Scale;
}
public void setScale(Long Scale) {
this.Scale = Scale;
}
public String getLabel() {
return Label;
}
public void setLabel(String Label) {
this.Label = Label;
}
}
| java | Apache-2.0 | f5e7a60e0c377f7420866b229a9ac79e687d5ac5 | 2026-01-05T02:42:41.143783Z | false |
ansitech/weixin4j | https://github.com/ansitech/weixin4j/blob/f5e7a60e0c377f7420866b229a9ac79e687d5ac5/src/main/java/org/weixin4j/model/message/normal/TextInputMessage.java | src/main/java/org/weixin4j/model/message/normal/TextInputMessage.java | /*
* 微信公众平台(JAVA) SDK
*
* Copyright (c) 2014, Ansitech Network Technology Co.,Ltd All rights reserved.
*
* http://www.weixin4j.org/
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.weixin4j.model.message.normal;
import org.weixin4j.model.message.MsgType;
/**
* 文本消息
*
* @author yangqisheng
* @since 0.0.1
*/
public class TextInputMessage extends NormalMessage {
//文本消息内容
private String Content;
public TextInputMessage(String Content) {
this.Content = Content;
}
@Override
public String getMsgType() {
return MsgType.Text.toString();
}
public String getContent() {
return Content;
}
public void setContent(String Content) {
this.Content = Content;
}
}
| java | Apache-2.0 | f5e7a60e0c377f7420866b229a9ac79e687d5ac5 | 2026-01-05T02:42:41.143783Z | false |
ansitech/weixin4j | https://github.com/ansitech/weixin4j/blob/f5e7a60e0c377f7420866b229a9ac79e687d5ac5/src/main/java/org/weixin4j/model/message/normal/NormalMessage.java | src/main/java/org/weixin4j/model/message/normal/NormalMessage.java | /*
* 微信公众平台(JAVA) SDK
*
* Copyright (c) 2014, Ansitech Network Technology Co.,Ltd All rights reserved.
*
* http://www.weixin4j.org/
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.weixin4j.model.message.normal;
import javax.xml.bind.annotation.XmlElement;
/**
* 普通消息
*
* @author yangqisheng
* @since 0.0.1
*/
public abstract class NormalMessage {
/**
* 开发者微信号
*/
private String ToUserName;
/**
* 发送方帐号(一个OpenID)
*/
private String FromUserName;
/**
* 消息创建时间 (整型)
*/
private Long CreateTime;
/**
* 消息id,64位整型
*/
private Long MsgId;
/**
* 获取 消息类型
*
* @return 消息类型
*/
public abstract String getMsgType();
public String getToUserName() {
return ToUserName;
}
@XmlElement(name = "ToUserName")
public void setToUserName(String ToUserName) {
this.ToUserName = ToUserName;
}
public String getFromUserName() {
return FromUserName;
}
@XmlElement(name = "FromUserName")
public void setFromUserName(String FromUserName) {
this.FromUserName = FromUserName;
}
public Long getCreateTime() {
return CreateTime;
}
@XmlElement(name = "CreateTime")
public void setCreateTime(Long CreateTime) {
this.CreateTime = CreateTime;
}
public Long getMsgId() {
return MsgId;
}
@XmlElement(name = "MsgId")
public void setMsgId(Long MsgId) {
this.MsgId = MsgId;
}
}
| java | Apache-2.0 | f5e7a60e0c377f7420866b229a9ac79e687d5ac5 | 2026-01-05T02:42:41.143783Z | false |
ansitech/weixin4j | https://github.com/ansitech/weixin4j/blob/f5e7a60e0c377f7420866b229a9ac79e687d5ac5/src/main/java/org/weixin4j/model/message/normal/VideoInputMessage.java | src/main/java/org/weixin4j/model/message/normal/VideoInputMessage.java | /*
* 微信公众平台(JAVA) SDK
*
* Copyright (c) 2014, Ansitech Network Technology Co.,Ltd All rights reserved.
*
* http://www.weixin4j.org/
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.weixin4j.model.message.normal;
import org.weixin4j.model.message.MsgType;
/**
* 视频消息
*
* @author yangqisheng
* @since 0.0.1
*/
public class VideoInputMessage extends NormalMessage {
//视频消息媒体id,可以调用多媒体文件下载接口拉取数据。
private String MediaId;
//视频消息 视频消息缩略图的媒体id,可以调用多媒体文件下载接口拉取数据。
private String ThumbMediaId;
@Override
public String getMsgType() {
return MsgType.Video.toString();
}
public String getMediaId() {
return MediaId;
}
public void setMediaId(String MediaId) {
this.MediaId = MediaId;
}
public String getThumbMediaId() {
return ThumbMediaId;
}
public void setThumbMediaId(String ThumbMediaId) {
this.ThumbMediaId = ThumbMediaId;
}
}
| java | Apache-2.0 | f5e7a60e0c377f7420866b229a9ac79e687d5ac5 | 2026-01-05T02:42:41.143783Z | false |
ansitech/weixin4j | https://github.com/ansitech/weixin4j/blob/f5e7a60e0c377f7420866b229a9ac79e687d5ac5/src/main/java/org/weixin4j/model/message/normal/VoiceInputMessage.java | src/main/java/org/weixin4j/model/message/normal/VoiceInputMessage.java | /*
* 微信公众平台(JAVA) SDK
*
* Copyright (c) 2014, Ansitech Network Technology Co.,Ltd All rights reserved.
*
* http://www.weixin4j.org/
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.weixin4j.model.message.normal;
import org.weixin4j.model.message.MsgType;
/**
* 语音消息
*
* @author yangqisheng
* @since 0.0.1
*/
public class VoiceInputMessage extends NormalMessage {
//语音消息媒体id,可以调用多媒体文件下载接口拉取数据。
private String MediaId;
//语音格式,如amr,speex等
private String Format;
//语音识别结果,使用UTF8编码
private String Recognition;
@Override
public String getMsgType() {
return MsgType.Voice.toString();
}
public String getMediaId() {
return MediaId;
}
public void setMediaId(String MediaId) {
this.MediaId = MediaId;
}
public String getFormat() {
return Format;
}
public void setFormat(String Format) {
this.Format = Format;
}
public String getRecognition() {
return Recognition;
}
public void setRecognition(String Recognition) {
this.Recognition = Recognition;
}
}
| java | Apache-2.0 | f5e7a60e0c377f7420866b229a9ac79e687d5ac5 | 2026-01-05T02:42:41.143783Z | false |
ansitech/weixin4j | https://github.com/ansitech/weixin4j/blob/f5e7a60e0c377f7420866b229a9ac79e687d5ac5/src/main/java/org/weixin4j/model/message/normal/LinkInputMessage.java | src/main/java/org/weixin4j/model/message/normal/LinkInputMessage.java | /*
* 微信公众平台(JAVA) SDK
*
* Copyright (c) 2014, Ansitech Network Technology Co.,Ltd All rights reserved.
*
* http://www.weixin4j.org/
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.weixin4j.model.message.normal;
import org.weixin4j.model.message.MsgType;
/**
* 链接消息
*
* @author yangqisheng
* @since 0.0.1
*/
public class LinkInputMessage extends NormalMessage {
//消息标题
private String Title;
//消息描述
private String Description;
//消息链接
private String Url;
@Override
public String getMsgType() {
return MsgType.Link.toString();
}
public String getTitle() {
return Title;
}
public void setTitle(String Title) {
this.Title = Title;
}
public String getDescription() {
return Description;
}
public void setDescription(String Description) {
this.Description = Description;
}
public String getUrl() {
return Url;
}
public void setUrl(String Url) {
this.Url = Url;
}
}
| java | Apache-2.0 | f5e7a60e0c377f7420866b229a9ac79e687d5ac5 | 2026-01-05T02:42:41.143783Z | false |
ansitech/weixin4j | https://github.com/ansitech/weixin4j/blob/f5e7a60e0c377f7420866b229a9ac79e687d5ac5/src/main/java/org/weixin4j/model/message/normal/ShortVideoInputMessage.java | src/main/java/org/weixin4j/model/message/normal/ShortVideoInputMessage.java | /*
* 微信公众平台(JAVA) SDK
*
* Copyright (c) 2014, Ansitech Network Technology Co.,Ltd All rights reserved.
*
* http://www.weixin4j.org/
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.weixin4j.model.message.normal;
import org.weixin4j.model.message.MsgType;
/**
* 小视频消息
*
* @author yangqisheng
* @since 0.0.7
*/
public class ShortVideoInputMessage extends NormalMessage {
//视频消息媒体id,可以调用多媒体文件下载接口拉取数据。
private String MediaId;
//视频消息 视频消息缩略图的媒体id,可以调用多媒体文件下载接口拉取数据。
private String ThumbMediaId;
@Override
public String getMsgType() {
return MsgType.ShortVideo.toString();
}
public String getMediaId() {
return MediaId;
}
public void setMediaId(String MediaId) {
this.MediaId = MediaId;
}
public String getThumbMediaId() {
return ThumbMediaId;
}
public void setThumbMediaId(String ThumbMediaId) {
this.ThumbMediaId = ThumbMediaId;
}
}
| java | Apache-2.0 | f5e7a60e0c377f7420866b229a9ac79e687d5ac5 | 2026-01-05T02:42:41.143783Z | false |
ansitech/weixin4j | https://github.com/ansitech/weixin4j/blob/f5e7a60e0c377f7420866b229a9ac79e687d5ac5/src/main/java/org/weixin4j/model/message/normal/ImageInputMessage.java | src/main/java/org/weixin4j/model/message/normal/ImageInputMessage.java | /*
* 微信公众平台(JAVA) SDK
*
* Copyright (c) 2014, Ansitech Network Technology Co.,Ltd All rights reserved.
*
* http://www.weixin4j.org/
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.weixin4j.model.message.normal;
import org.weixin4j.model.message.MsgType;
/**
* 图片消息
*
* @author yangqisheng
* @since 0.0.1
*/
public class ImageInputMessage extends NormalMessage {
//图片链接
private String PicUrl;
//图片消息媒体id,可以调用多媒体文件下载接口拉取数据。
private String MediaId;
@Override
public String getMsgType() {
return MsgType.Image.toString();
}
public String getPicUrl() {
return PicUrl;
}
public void setPicUrl(String PicUrl) {
this.PicUrl = PicUrl;
}
public String getMediaId() {
return MediaId;
}
public void setMediaId(String MediaId) {
this.MediaId = MediaId;
}
}
| java | Apache-2.0 | f5e7a60e0c377f7420866b229a9ac79e687d5ac5 | 2026-01-05T02:42:41.143783Z | false |
ansitech/weixin4j | https://github.com/ansitech/weixin4j/blob/f5e7a60e0c377f7420866b229a9ac79e687d5ac5/src/main/java/org/weixin4j/model/message/event/EventMessage.java | src/main/java/org/weixin4j/model/message/event/EventMessage.java | /*
* 微信公众平台(JAVA) SDK
*
* Copyright (c) 2014, Ansitech Network Technology Co.,Ltd All rights reserved.
*
* http://www.weixin4j.org/
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.weixin4j.model.message.event;
/**
* 事件消息
*
* @author yangqisheng
* @since 0.0.1
*/
public abstract class EventMessage {
//开发者微信号
private String ToUserName;
//发送方帐号(一个OpenID)
private String FromUserName;
//消息创建时间 (整型)
private Long CreateTime;
//消息类型,event
private final String MsgType = "event";
/**
* 获取 事件类型
*
* @return 事件类型
*/
public abstract String getEvent();
public String getToUserName() {
return ToUserName;
}
public void setToUserName(String ToUserName) {
this.ToUserName = ToUserName;
}
public String getFromUserName() {
return FromUserName;
}
public void setFromUserName(String FromUserName) {
this.FromUserName = FromUserName;
}
public Long getCreateTime() {
return CreateTime;
}
public void setCreateTime(Long CreateTime) {
this.CreateTime = CreateTime;
}
public String getMsgType() {
return MsgType;
}
}
| java | Apache-2.0 | f5e7a60e0c377f7420866b229a9ac79e687d5ac5 | 2026-01-05T02:42:41.143783Z | false |
ansitech/weixin4j | https://github.com/ansitech/weixin4j/blob/f5e7a60e0c377f7420866b229a9ac79e687d5ac5/src/main/java/org/weixin4j/model/message/event/QrsceneScanEventMessage.java | src/main/java/org/weixin4j/model/message/event/QrsceneScanEventMessage.java | /*
* 微信公众平台(JAVA) SDK
*
* Copyright (c) 2014, Ansitech Network Technology Co.,Ltd All rights reserved.
*
* http://www.weixin4j.org/
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.weixin4j.model.message.event;
import org.weixin4j.model.message.EventType;
/**
* 扫描带参数二维码事件
*
* 用户已关注
*
* @author yangqisheng
* @since 0.0.1
*/
public class QrsceneScanEventMessage extends EventMessage {
//事件KEY值,是一个32位无符号整数,即创建二维码时的二维码scene_id
private String EventKey;
//二维码的ticket,可用来换取二维码图片
private String Ticket;
@Override
public String getEvent() {
return EventType.Scan.toString();
}
public String getEventKey() {
return EventKey;
}
public void setEventKey(String EventKey) {
this.EventKey = EventKey;
}
public String getTicket() {
return Ticket;
}
public void setTicket(String Ticket) {
this.Ticket = Ticket;
}
}
| java | Apache-2.0 | f5e7a60e0c377f7420866b229a9ac79e687d5ac5 | 2026-01-05T02:42:41.143783Z | false |
ansitech/weixin4j | https://github.com/ansitech/weixin4j/blob/f5e7a60e0c377f7420866b229a9ac79e687d5ac5/src/main/java/org/weixin4j/model/message/event/UnSubscribeEventMessage.java | src/main/java/org/weixin4j/model/message/event/UnSubscribeEventMessage.java | /*
* 微信公众平台(JAVA) SDK
*
* Copyright (c) 2014, Ansitech Network Technology Co.,Ltd All rights reserved.
*
* http://www.weixin4j.org/
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.weixin4j.model.message.event;
import org.weixin4j.model.message.EventType;
/**
* 取消关注事件
*
* @author yangqisheng
* @since 0.0.1
*/
public class UnSubscribeEventMessage extends EventMessage {
@Override
public String getEvent() {
return EventType.Unsubscribe.toString();
}
}
| java | Apache-2.0 | f5e7a60e0c377f7420866b229a9ac79e687d5ac5 | 2026-01-05T02:42:41.143783Z | false |
ansitech/weixin4j | https://github.com/ansitech/weixin4j/blob/f5e7a60e0c377f7420866b229a9ac79e687d5ac5/src/main/java/org/weixin4j/model/message/event/ScanCodePushEventMessage.java | src/main/java/org/weixin4j/model/message/event/ScanCodePushEventMessage.java | /*
* 微信公众平台(JAVA) SDK
*
* Copyright (c) 2014, Ansitech Network Technology Co.,Ltd All rights reserved.
*
* http://www.weixin4j.org/
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.weixin4j.model.message.event;
import org.weixin4j.model.message.EventType;
import org.weixin4j.model.message.ScanCodeInfo;
/**
* 自定义菜单事件
*
* 扫码推事件的事件推送
*
* @author yangqisheng
* @since 0.0.1
*/
public class ScanCodePushEventMessage extends EventMessage {
//事件KEY值,与自定义菜单接口中KEY值对应
private String EventKey;
//扫描信息
private ScanCodeInfo ScanCodeInfo;
@Override
public String getEvent() {
return EventType.Scancode_Push.toString();
}
public String getEventKey() {
return EventKey;
}
public void setEventKey(String EventKey) {
this.EventKey = EventKey;
}
public ScanCodeInfo getScanCodeInfo() {
return ScanCodeInfo;
}
public void setScanCodeInfo(ScanCodeInfo ScanCodeInfo) {
this.ScanCodeInfo = ScanCodeInfo;
}
}
| java | Apache-2.0 | f5e7a60e0c377f7420866b229a9ac79e687d5ac5 | 2026-01-05T02:42:41.143783Z | false |
ansitech/weixin4j | https://github.com/ansitech/weixin4j/blob/f5e7a60e0c377f7420866b229a9ac79e687d5ac5/src/main/java/org/weixin4j/model/message/event/LocationSelectEventMessage.java | src/main/java/org/weixin4j/model/message/event/LocationSelectEventMessage.java | /*
* 微信公众平台(JAVA) SDK
*
* Copyright (c) 2014, Ansitech Network Technology Co.,Ltd All rights reserved.
*
* http://www.weixin4j.org/
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.weixin4j.model.message.event;
import org.weixin4j.model.message.EventType;
import org.weixin4j.model.message.SendLocationInfo;
/**
* 自定义菜单事件
*
* 弹出地理位置选择器的事件推送
*
* @author yangqisheng
* @since 0.0.1
*/
public class LocationSelectEventMessage extends EventMessage {
//事件KEY值,与自定义菜单接口中KEY值对应
private String EventKey;
//发送的位置信息
private SendLocationInfo SendLocationInfo;
@Override
public String getEvent() {
return EventType.Location_Select.toString();
}
public String getEventKey() {
return EventKey;
}
public void setEventKey(String EventKey) {
this.EventKey = EventKey;
}
public SendLocationInfo getSendLocationInfo() {
return SendLocationInfo;
}
public void setSendLocationInfo(SendLocationInfo SendLocationInfo) {
this.SendLocationInfo = SendLocationInfo;
}
}
| java | Apache-2.0 | f5e7a60e0c377f7420866b229a9ac79e687d5ac5 | 2026-01-05T02:42:41.143783Z | false |
ansitech/weixin4j | https://github.com/ansitech/weixin4j/blob/f5e7a60e0c377f7420866b229a9ac79e687d5ac5/src/main/java/org/weixin4j/model/message/event/PicWeixinEventMessage.java | src/main/java/org/weixin4j/model/message/event/PicWeixinEventMessage.java | /*
* 微信公众平台(JAVA) SDK
*
* Copyright (c) 2014, Ansitech Network Technology Co.,Ltd All rights reserved.
*
* http://www.weixin4j.org/
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.weixin4j.model.message.event;
import org.weixin4j.model.message.EventType;
import org.weixin4j.model.message.SendPicsInfo;
/**
* 自定义菜单事件
*
* 弹出微信相册发图器的事件推送
*
* @author yangqisheng
* @since 0.0.1
*/
public class PicWeixinEventMessage extends EventMessage {
//事件KEY值,与自定义菜单接口中KEY值对应
private String EventKey;
//发送的图片信息
private SendPicsInfo SendPicsInfo;
@Override
public String getEvent() {
return EventType.Pic_Weixin.toString();
}
public String getEventKey() {
return EventKey;
}
public void setEventKey(String EventKey) {
this.EventKey = EventKey;
}
public SendPicsInfo getSendPicsInfo() {
return SendPicsInfo;
}
public void setSendPicsInfo(SendPicsInfo SendPicsInfo) {
this.SendPicsInfo = SendPicsInfo;
}
}
| java | Apache-2.0 | f5e7a60e0c377f7420866b229a9ac79e687d5ac5 | 2026-01-05T02:42:41.143783Z | false |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.