Skip to content

Instantly share code, notes, and snippets.

diaolizhi

Block or report user

Report or block diaolizhi

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@diaolizhi
diaolizhi / wxpay-callback.java
Created Jul 16, 2019
微信支付回调接口,接收通知并回复
View wxpay-callback.java
@RequestMapping("callback")
public void callback(HttpServletRequest request, HttpServletResponse response) throws Exception {
InputStream inputStream = request.getInputStream();
//BufferedReader是包装设计模式,性能更搞
BufferedReader in = new BufferedReader(new InputStreamReader(inputStream,"UTF-8"));
StringBuffer sb = new StringBuffer();
String line ;
while ((line = in.readLine()) != null){
sb.append(line);
@diaolizhi
diaolizhi / HttpUtils.java
Created Jul 16, 2019
封装 HTTP 请求(可用户微信登录与支付)
View HttpUtils.java
import com.google.gson.Gson;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
View JwtUtils.java
import io.jsonwebtoken.Claims;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;
import net.xdclass.xdvideo.domain.User;
import java.util.Date;
/**
* jwt工具类
*/
@diaolizhi
diaolizhi / WXPayUtil.java
Created Jul 16, 2019
微信支付工具类:Map、XML 的转换,生成、校验 sign
View WXPayUtil.java
import org.w3c.dom.Entity;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.transform.OutputKeys;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
@diaolizhi
diaolizhi / CommonUtils.java
Created Jul 16, 2019
常用工具类:生成 UUID,对 String 进行 MD5 加密
View CommonUtils.java
import java.security.MessageDigest;
import java.util.UUID;
/**
* 常用工具类的封装,md5,uuid等
*/
public class CommonUtils {
/**
@diaolizhi
diaolizhi / IpUtils.java
Last active Jul 16, 2019
获取请求的 ip 地址
View IpUtils.java
import java.net.InetAddress;
import java.net.UnknownHostException;
import javax.servlet.http.HttpServletRequest;
public class IpUtils {
public static String getIpAddr(HttpServletRequest request) {
String ipAddress = null;
try {
ipAddress = request.getHeader("x-forwarded-for");
@diaolizhi
diaolizhi / getcookies.cs
Created Oct 23, 2018
C# WebBrowser 获取 HttpOnly 的 cookie
View getcookies.cs
//不知道为什么有些 cookie 获取不到,只能通过这种方式解决
//这一次的用法是,先在 WebBrowser 登录贴吧网页版,然后将 http://tieba.baidu.com/mo/ 传给 GetCookie 方法
//就可以获取到所有 cookie
//需要引入 System.Net 并 using System.Net;
//下面这段代码作为内部类,如何使用在后面
internal static class CookieReader
{
/// <summary>
@diaolizhi
diaolizhi / a.js
Created Apr 28, 2019
JavaScript 格式化后端返回的时间
View a.js
new Date(data.updated).toLocaleString();
View a.java
public static String decrypt(String encrypted) {
String KEY = ")O[NB]6,YF}+efcaj{+oESb9d8>Z'e9M";
String IV = "L+\\~f4,Ir)b$=pkf";
try {
IvParameterSpec iv = new IvParameterSpec(IV.getBytes("UTF-8"));
SecretKeySpec skeySpec = new SecretKeySpec(KEY.getBytes("UTF-8"), "AES");
Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5PADDING");
cipher.init(Cipher.DECRYPT_MODE, skeySpec, iv);
@diaolizhi
diaolizhi / a.java
Last active Apr 10, 2019
Map 遍历时删除元素
View a.java
// 创建 Map
Map<String, String> map = new HashMap<>();
// 添加元素
map.put("1", "张三");
map.put("2", "李四");
map.put("3", "王五");
// 获取存放键值的集合
// Map 并没有 iterator 方法,所以不能 map.iterator() 获取迭代器
You can’t perform that action at this time.