key.equalsIgnoreCase("sign_type")) { continue;
}
result.put(key, value);
} return result;
} /**
* 把数组所有元素排序,并按照“参数=参数值”的模式用“&”字符拼接成字符串
* @param params 需要排序并参与字符拼接的参数组
* @return 拼接后字符串
*/
public static String createLinkString(Map<String, String> params) {
List<String> keys = new ArrayList<String>(params.keySet());
Collections.sort(keys);
String prestr = ""; for (int i = 0; i < keys.size(); i++) {
String key = keys.get(i);
String value = params.get(key); if (i == keys.size() - 1) {// 拼接时,不包括最后一个&字符
prestr = prestr + key + "=" + value;
} else {
prestr = prestr + key + "=" + value + "&";
}
} return prestr;
} /**
*
* @param requestUrl请求地址
* @param requestMethod请求方法
* @param outputStr参数
*/
public static String httpRequest(String requestUrl,String requestMethod,String outputStr){ // 创建SSLContext
StringBuffer buffer=null; try{
URL url = new URL(requestUrl);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod(requestMethod);
conn.setDoOutput(true);
conn.setDoInput(true);
conn.connect(); //往服务器端写内容
if(null !=outputStr){
OutputStream os=conn.getOutputStream();
os.write(outputStr.getBytes("utf-8"));
os.close();
} // 读取服务器端返回的内容
InputStream is = conn.getInputStream();
InputStreamReader isr = new InputStreamReader(is, "utf-8");
BufferedReader br = new BufferedReader(isr);
buffer = new StringBuffer();
String line = null; while ((line = br.readLine()) != null) {
buffer.append(line);
}
}catch(Exception e){
e.printStackTrace();
} return buffer.toString();
}
public static String urlEncodeUTF8(String source){
String result=source; try {
result=java.net.URLEncoder.encode(source, "UTF-8");
} catch (UnsupportedEncodingException e) { // TODO Auto-generated catch block
e.printStackTrace();
} return result;
}
}
UUIDHexGeneratorpackage cn.it.shop.util;import java.net.InetAddress;/**
* @author
* @version 创建时间:2017年1月17日 下午7:45:06 类说明
*/public class UUIDHexGenerator {
private static String sep = ""; private static final int IP; private static short counter = (short) 0; private static final int JVM = (int) (System.currentTimeMillis() >>> 8); private static UUIDHexGenerator uuidgen = new UUIDHexGenerator(); static { int ipadd; try {
ipadd = toInt(InetAddress.getLocalHost().getAddress());
} catch (Exception e) {
ipadd = 0;
}
IP = ipadd;
} public static UUIDHexGenerator getInstance() { return uuidgen;
} public static int toInt(byte[] bytes) { int result = 0; for (int i = 0; i < 4; i++) {
result = (result << 8) - Byte.MIN_VALUE + (int) bytes[i];
} return result;
} protected static String format(int intval) {
String formatted = Integer.toHexString(intval);
StringBuffer buf = new StringBuffer("00000000");
buf.replace(8 - formatted.length(), 8, formatted); return buf.toString();
} protected static String format(short shortval) {
String formatted = Integer.toHexString(shortval);
StringBuffer buf = new StringBuffer("0000");
buf.replace(4 - formatted.length(), 4, formatted); return buf.toString();
} protected static int getJVM() { return JVM;
} protected synchronized static short getCount() { if (counter < 0) {
counter = 0;
} return counter++;
} protected static int getIP() { return IP;
} protected static short getHiTime() { return (short) (System.currentTimeMillis() >>> 32);
} protected static int getLoTime() { return (int) System.currentTimeMillis();
} public static String generate() { return new StringBuffer(36).append(format(getIP())).append(sep).append(format(getJVM())).append(sep)
.append(format(getHiTime())).append(sep).append(format(getLoTime())).append(sep)
.append(format(getCount())).toString();
} /**
* @param args
*/
public static void main(String[] args) {
String id="";
UUIDHexGenerator uuid = UUIDHexGenerator.getInstance(); /*
for (int i = 0; i < 100; i++) {
id = uuid.generate();
}*/
id = uuid.generate();
System.out.println(id);
}
}
第一次写,写的不是太完整,希望同大家多多交流,一起进步。
以上就是微信小程序支付接口的实例详解的详细内容,更多请关注php中文网其它相关文章!
小程序是一种不需要下载安装即可使用的应用,它实现了应用“触手可及”的梦想,用户扫一扫或者搜一下即可打开应用。
关键词:微信小程序支付接口的案例详细说明