-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* update readme * Create README.md * update readme * publish jcenter * add pay
- Loading branch information
Showing
21 changed files
with
193 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* | ||
* Copyright 2016 jeasonlzy(廖子尧) | ||
* | ||
* 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 com.lzy.demo; | ||
|
||
import android.os.Bundle; | ||
import android.view.LayoutInflater; | ||
import android.view.View; | ||
import android.view.ViewGroup; | ||
|
||
import com.lzy.demo.base.BaseFragment; | ||
|
||
/** | ||
* ================================================ | ||
* 作 者:jeasonlzy(廖子尧)Github地址:https://github.com/jeasonlzy | ||
* 版 本:1.0 | ||
* 创建日期:2017/6/9 | ||
* 描 述: | ||
* 修订历史: | ||
* ================================================ | ||
*/ | ||
public class PayFragment extends BaseFragment { | ||
|
||
@Override | ||
protected View initView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { | ||
return inflater.inflate(R.layout.fragment_pay, container, false); | ||
} | ||
|
||
@Override | ||
protected void initData() { | ||
|
||
} | ||
} |
80 changes: 80 additions & 0 deletions
80
demo/src/main/java/com/lzy/demo/callback/EncryptCallback.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
package com.lzy.demo.callback; | ||
|
||
import com.lzy.demo.utils.MD5Utils; | ||
import com.lzy.okgo.model.HttpParams; | ||
import com.lzy.okgo.request.Request; | ||
|
||
import java.util.Comparator; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Random; | ||
import java.util.TreeMap; | ||
|
||
/** | ||
* ================================================ | ||
* 作 者:jeasonlzy(廖子尧)Github地址:https://github.com/jeasonlzy | ||
* 版 本:1.0 | ||
* 创建日期:2017/6/11 | ||
* 描 述: | ||
* 修订历史: | ||
* ================================================ | ||
*/ | ||
public abstract class EncryptCallback<T> extends JsonCallback<T> { | ||
|
||
private static final Random RANDOM = new Random(); | ||
private static final String CHARS = "0123456789abcdefghijklmnopqrstuvwxyz"; | ||
|
||
@Override | ||
public void onStart(Request<T, ? extends Request> request) { | ||
super.onStart(request); | ||
//以下是示例加密代码,根据自己的业务需求和服务器的配合,算法自行决定,这里只是demo,不能用于商业项目 | ||
sign(request.getParams()); | ||
} | ||
|
||
/** | ||
* 针对URL进行签名,关于这几个参数的作用,详细请看 | ||
* http://www.cnblogs.com/bestzrz/archive/2011/09/03/2164620.html | ||
*/ | ||
private void sign(HttpParams params) { | ||
params.put("nonce", getRndStr(6 + RANDOM.nextInt(8))); | ||
params.put("timestamp", "" + (System.currentTimeMillis() / 1000L)); | ||
StringBuilder sb = new StringBuilder(); | ||
Map<String, String> map = new HashMap<>(); | ||
for (Map.Entry<String, List<String>> entry : params.urlParamsMap.entrySet()) { | ||
map.put(entry.getKey(), entry.getValue().get(0)); | ||
} | ||
for (Map.Entry<String, String> entry : getSortedMapByKey(map).entrySet()) { | ||
sb.append(entry.getKey()).append("=").append(entry.getValue()).append("&"); | ||
} | ||
sb.delete(sb.length() - 1, sb.length()); | ||
String sign = MD5Utils.encode(sb.toString()); | ||
params.put("sign", sign); | ||
} | ||
|
||
/** 获取随机数 */ | ||
private String getRndStr(int length) { | ||
StringBuilder sb = new StringBuilder(); | ||
char ch; | ||
for (int i = 0; i < length; i++) { | ||
ch = CHARS.charAt(RANDOM.nextInt(CHARS.length())); | ||
sb.append(ch); | ||
} | ||
return sb.toString(); | ||
} | ||
|
||
/** 按照key的自然顺序进行排序,并返回 */ | ||
private Map<String, String> getSortedMapByKey(Map<String, String> map) { | ||
Comparator<String> comparator = new Comparator<String>() { | ||
@Override | ||
public int compare(String lhs, String rhs) { | ||
return lhs.compareTo(rhs); | ||
} | ||
}; | ||
Map<String, String> treeMap = new TreeMap<>(comparator); | ||
for (Map.Entry<String, String> entry : map.entrySet()) { | ||
treeMap.put(entry.getKey(), entry.getValue()); | ||
} | ||
return treeMap; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<!-- | ||
Copyright 2016 jeasonlzy(廖子尧) | ||
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. | ||
--> | ||
<android.support.v4.widget.NestedScrollView | ||
android:id="@+id/refreshLayout" | ||
xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent"> | ||
|
||
<LinearLayout | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:orientation="vertical"> | ||
|
||
<TextView | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:background="@color/colorPrimary" | ||
android:padding="10dp" | ||
android:text="如果你觉得好,对你有过帮助,请给我一点打赏鼓励吧,一分也是爱呀!" | ||
android:textColor="#FFF" | ||
android:textSize="16sp"/> | ||
|
||
<ImageView | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:src="@mipmap/pay"/> | ||
</LinearLayout> | ||
</android.support.v4.widget.NestedScrollView> | ||
|
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters