jsp二维码收款_java实现支付之扫码支付
jsp⼆维码收款_java实现⽀付之扫码⽀付
public classPayCommonUtil {public static Logger log = Logger(PayCommonUtil.class);/*** 是否签名正确,规则是:按参数名称a-z排序,遇到空值的参数不参加签名。
*@returnboolean*/
public static boolean isTenpaySign(String characterEncoding, SortedMappackageParams, String API_KEY) {
StringBuffer sb= newStringBuffer();
Set Set();
Iterator it=es.iterator();while(it.hasNext()) {
Map.Entry entry=(Map.();
String k=(Key();
String v=(Value();if(!"sign".equals(k) && null != v && !"".equals(v)) {
sb.append(k+ "=" + v + "&");
}
}
qq牧场神马
sb.append("key=" +API_KEY);//算出摘要
String mysign =MD5.String(), characterEncoding).toLowerCase();
String tenpaySign= ((("sign")).toLowerCase();//System.out.println(tenpaySign + " " + mysign);
returntenpaySign.equals(mysign);
}/***@author* @date 2016-4-22
* @Description:sign签名
*@paramcharacterEncoding
* 编码格式
*@paramparameters
* 请求参数
*@return
*/
public static String createSign(String characterEncoding, SortedMappackageParams, String API_KEY) {
StringBuffer sb= newStringBuffer();
Set Set();
Iterator it=es.iterator();while(it.hasNext()) {
Map.Entry entry=(Map.Entry) it.next();
String k=(String) Key();
String v= "";try{
v=(String) Value();
}catch(Exception e) {//TODO: handle exception
v = Value() + "";
}if (null != v && !"".equals(v) && !"sign".equals(k) && !"key".equals(k)) {
sb.append(k+ "=" + v + "&");
}
}
sb.append("key=" +API_KEY);
String sign=MD5.String(), characterEncoding).toUpperCase();returnsign;
}/***@author* @date 2016-4-22
* @Description:将请求参数转换为xml格式的string
*@paramparameters
* 请求参数
*@return
*/
public static String getRequestXml(SortedMapparameters) {
StringBuffer sb= newStringBuffer();
sb.append("");
Set Set();
Iterator it=es.iterator();while(it.hasNext()) {
Map.Entry entry=(Map.Entry) it.next();
String k=(String) Key();
String v= "";try{
v=(String) Value();
}catch(Exception e) {//TODO: handle exception
v = Value() + "";
}if ("attach".equalsIgnoreCase(k) || "body".equalsIgnoreCase(k) || "sign".equalsIgnoreCase(k)) { sb.append("" + "" + k + ">");
}else{
sb.append("" + v + "" + k + ">");
}
}国歌的歌词
sb.append("");String();
}/*** 取出⼀个指定长度⼤⼩的随机正整数.
*
*@paramlength
* int 设定所取出随机数的长度。length⼩于11
*@returnint 返回⽣成的随机数。*/
public static int buildRandom(intlength) {int num = 1;double random =Math.random();if (random < 0.1) { random= random + 0.1;
}for (int i = 0; i < length; i++) {
num= num * 10;
}return (int) ((random *num));
}/*** 获取当前时间 yyyyMMddHHmmss
*
*@returnString*/
3.8女神节祝福语public staticString getCurrTime() {
Date now= newDate();
SimpleDateFormat outFormat= new SimpleDateFormat("yyyyMMddHHmmss");
String s=outFormat.format(now);returns;
}public staticJSONObject httpsRequestToJsonObject(String requestUrl,
String requestMethod, String outputStr) {
JSONObject jsonObject= null;try{
关于爱情的名人名言StringBuffer buffer=httpsRequest(requestUrl, requestMethod,
outputStr);
jsonObject=JSONObject.String());
}catch(ConnectException ce) {
<("连接超时:" +ce.getMessage());
}catch(Exception e) {国产婴儿奶粉品牌
<("https请求异常:" +e.getMessage());
}returnjsonObject;
}private staticStringBuffer httpsRequest(String requestUrl,
String requestMethod, String output)throwsNoSuchAlgorithmException, NoSuchProviderException, KeyManagementException, MalformedURLException, IOException,
ProtocolException, UnsupportedEncodingException {
URL url= newURL(requestUrl);
HttpsURLConnection connection=(HttpsURLConnection) url
.openConnection();
connection.setDoOutput(true);
connection.setDoInput(true);
connection.setUseCaches(false);
connection.setRequestMethod(requestMethod);if (null !=output) {
OutputStream OutputStream();
关于教师节的手抄报内容outputStream.Bytes("UTF-8"));
outputStream.close();
}//从输⼊流读取返回内容
InputStream inputStream =InputStream();
InputStreamReader inputStreamReader= newInputStreamReader(
inputStream,"utf-8");
BufferedReader bufferedReader= newBufferedReader(inputStreamReader);
String str= null;
StringBuffer buffer= newStringBuffer();while ((str = adLine()) != null) { buffer.append(str);
}
bufferedReader.close();
inputStreamReader.close();
inputStream.close();
inputStream= null;
connection.disconnect();returnbuffer;
}
}

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。