1,servlet程序中加幾句system.out語句看看有沒有輸出,
成都創(chuàng)新互聯(lián)專注于尉犁網(wǎng)站建設(shè)服務(wù)及定制,我們擁有豐富的企業(yè)做網(wǎng)站經(jīng)驗(yàn)。 熱誠為您提供尉犁營銷型網(wǎng)站建設(shè),尉犁網(wǎng)站制作、尉犁網(wǎng)頁設(shè)計(jì)、尉犁網(wǎng)站官網(wǎng)定制、小程序定制開發(fā)服務(wù),打造尉犁網(wǎng)絡(luò)公司原創(chuàng)品牌,更為您提供尉犁網(wǎng)站排名全網(wǎng)營銷落地服務(wù)。
2,用瀏覽器打開,然后打開開發(fā)者工具看看提示。有時(shí)候eclipse自帶的web browse顯示網(wǎng)頁有問題,
html
head
meta?http-equiv="Content-Type"?content="text/html;?charset=utf-8"
title購物與結(jié)算/title
style?type="text/css"
/style
link?rel="stylesheet"?href="
script?src="
script?src="
script?src="
script?src="
(beta4)/IE9.js"/script
script?src="?
script?type="text/javascript"
function?pay()
{
var?link?=?document.getElementById("a1");
link.click();
var?a?=?new?Array();
a[0]="html教程";
a[1]=12;
a[2]=1;
a[3]=a[1]*a[2];
var?a1?=?new?Array();
a1[0]="java詳解";
a1[1]=25;
a1[2]=2;
a1[3]=a1[1]*a1[2];
var?b?=?new?Array();
b[0]=a;
b[1]=a1;
var?amount?=0;
for(var?i=0;ib.length;i++)
{
var?c?=?new?Array();
c=b[i];
amount?=?amount+c[3];
var?tr?="tr";
for(var?j=0;jc.length;j++)
{
tr+="td"+c[j]+"/td";
}
tr+="/tr";
$("#list").append(tr);
$("#all").html("b總計(jì):/bfont?color=\"red\""+amount+"/font")
}
}
function?goon()
{
var?link?=?document.getElementById("a2");
link.click();
$("#news").html("支付成功??!");
}
/script
/head
body
input?type="button"?class="btn?btn-danger"?value="點(diǎn)擊結(jié)算"?onclick="pay()"
a?href="#myModaltishi"?role="button"?class="btn"?data-toggle="modal"?id="a1"?style="display:?none"/a?
div?id="myModaltishi"?class="modal?hide?fade"?tabindex="-1"?role="dialog"?aria-labelledby="myModalLabel"?aria-hidden="true"??
div?class="modal-header"??
button?type="button"?class="close"?data-dismiss="modal"?aria-hidden="true"×/button??
h3?id="myModalLabel"購物車/h3??
/div??
div?class="modal-body"??
div
table?id="list"?style="width:?95%;"?class="table"
th商品名稱/th
th單價(jià)/th
th數(shù)量/th
th金額/th
/table
/div
div?align="right"?id="all"/div
/div??
div?class="modal-footer"??
button?class="btn"?data-dismiss="modal"?aria-hidden="true"繼續(xù)挑選/button??
button?class="btn?btn-primary"?data-dismiss="modal"?onclick="goon()"支付/button??
/div??
/div?
a?href="#myModaltishi1"?role="button"?class="btn"?data-toggle="modal"?id="a2"?style="display:?none"/a?
div?id="myModaltishi1"?class="modal?hide?fade"?tabindex="-1"?role="dialog"?aria-labelledby="myModalLabel"?aria-hidden="true"??
div?class="modal-header"??
button?type="button"?class="close"?data-dismiss="modal"?aria-hidden="true"×/button??
h3?id="myModalLabel"系統(tǒng)提示/h3??
/div??
div?class="modal-body"??
h3?id="news"?align="center"/h3
/div??
div?class="modal-footer"??
button?class="btn?btn-primary"?data-dismiss="modal"知道了/button??
/div??
/div?
/body
!--?瀏覽器打開可查看效果,
另外由于頁面使用了bootstrap框架建議使用渲染較高的瀏覽器,例如:火狐?--
/html
java調(diào)用微信支付接口方法:
RequestHandler requestHandler = new RequestHandler(super.getRequest(),super.getResponse());
//獲取token //兩小時(shí)內(nèi)有效,兩小時(shí)后重新獲取
Token = requestHandler.GetToken();
//更新token 到應(yīng)用中
requestHandler.getTokenReal();
System.out.println("微信支付獲取token=======================:" +Token);
//requestHandler 初始化
requestHandler.init();
requestHandler.init(appid,appsecret, appkey,partnerkey, key);
// --------------------------------本地系統(tǒng)生成訂單-------------------------------------
// 設(shè)置package訂單參數(shù)
SortedMapString, String packageParams = new TreeMapString, String();
packageParams.put("bank_type", "WX"); // 支付類型
packageParams.put("body", "xxxx"); // 商品描述
packageParams.put("fee_type", "1"); // 銀行幣種
packageParams.put("input_charset", "UTF-8"); // 字符集
packageParams.put("notify_url", ""); // 通知地址 這里的通知地址使用外網(wǎng)地址測(cè)試,注意80端口是否打開。
packageParams.put("out_trade_no", no); // 商戶訂單號(hào)
packageParams.put("partner", partenerid); // 設(shè)置商戶號(hào)
packageParams.put("spbill_create_ip", super.getRequest().getRemoteHost()); // 訂單生成的機(jī)器IP,指用戶瀏覽器端IP
packageParams.put("total_fee", String.valueOf(rstotal)); // 商品總金額,以分為單位
// 設(shè)置支付參數(shù)
SortedMapString, String signParams = new TreeMapString, String();
signParams.put("appid", appid);
signParams.put("noncestr", noncestr);
signParams.put("traceid", PropertiesUtils.getOrderNO());
signParams.put("timestamp", timestamp);
signParams.put("package", packageValue);
signParams.put("appkey", this.appkey);
// 生成支付簽名,要采用URLENCODER的原始值進(jìn)行SHA1算法!
String sign ="";
try {
sign = Sha1Util.createSHA1Sign(signParams);
} catch (Exception e) {
e.printStackTrace();
}
// 增加非參與簽名的額外參數(shù)
signParams.put("sign_method", "sha1");
signParams.put("app_signature", sign);
// api支付拼包結(jié)束------------------------------------
//獲取prepayid
String prepayid = requestHandler.sendPrepay(signParams);
System.out.println("prepayid :" + prepayid);
// --------------------------------生成完成---------------------------------------------
//生成預(yù)付快訂單完成,返回給android,ios 掉起微信所需要的參數(shù)。
SortedMapString, String payParams = new TreeMapString, String();
payParams.put("appid", appid);
payParams.put("noncestr", noncestr);
payParams.put("package", "Sign=WXPay");
payParams.put("partnerid", partenerid);
payParams.put("prepayid", prepayid);
payParams.put("appkey", this.appkey);
//這里除1000 是因?yàn)閰?shù)長度限制。
int time = (int) (System.currentTimeMillis() / 1000);
payParams.put("timestamp",String.valueOf(time));
System.out.println("timestamp:" + time);
//簽名
String paysign ="";
try {
paysign = Sha1Util.createSHA1Sign(payParams);
} catch (Exception e) {
e.printStackTrace();
}
payParams.put("sign", paysign);
//拼json 數(shù)據(jù)返回給客戶端
BasicDBObject backObject = new BasicDBObject();
backObject.put("appid", appid);
backObject.put("noncestr", payParams.get("noncestr"));
backObject.put("package", "Sign=WXPay");
backObject.put("partnerid", payParams.get("partnerid"));
backObject.put("prepayid", payParams.get("prepayid"));
backObject.put("appkey", this.appkey);
backObject.put("timestamp",payParams.get("timestamp"));
backObject.put("sign",payParams.get("sign"));
String backstr = dataObject.toString();
System.out.println("backstr:" + backstr);
return backstr;
====================到此為止,預(yù)付款訂單已生成,并且已返回客戶端====================
//坐等微信服務(wù)器通知,通知的地址就是生成預(yù)付款訂單的notify_url
ResponseHandler resHandler = new ResponseHandler(request, response);
resHandler.setKey(partnerkey);
//創(chuàng)建請(qǐng)求對(duì)象
//RequestHandler queryReq = new RequestHandler(request, response);
//queryReq.init();
if (resHandler.isTenpaySign() == true) {
//商戶訂單號(hào)
String out_trade_no = resHandler.getParameter("out_trade_no");
System.out.println("out_trade_no:" + out_trade_no);
//財(cái)付通訂單號(hào)
String transaction_id = resHandler.getParameter("transaction_id");
System.out.println("transaction_id:" + transaction_id);
//金額,以分為單位
String total_fee = resHandler.getParameter("total_fee");
//如果有使用折扣券,discount有值,total_fee+discount=原請(qǐng)求的total_fee
String discount = resHandler.getParameter("discount");
//支付結(jié)果
String trade_state = resHandler.getParameter("trade_state");
//判斷簽名及結(jié)果
if ("0".equals(trade_state)) {
//------------------------------
//即時(shí)到賬處理業(yè)務(wù)開始
//------------------------------
System.out.println("----------------業(yè)務(wù)邏輯執(zhí)行-----------------");
//——請(qǐng)根據(jù)您的業(yè)務(wù)邏輯來編寫程序(以上代碼僅作參考)——
System.out.println("----------------業(yè)務(wù)邏輯執(zhí)行完畢-----------------");
System.out.println("success"); // 請(qǐng)不要修改或刪除
System.out.println("即時(shí)到賬支付成功");
//給財(cái)付通系統(tǒng)發(fā)送成功信息,財(cái)付通系統(tǒng)收到此結(jié)果后不再進(jìn)行后續(xù)通知
resHandler.sendToCFT("success");
//給微信服務(wù)器返回success 否則30分鐘通知8次
return "success";
}else{
System.out.println("通知簽名驗(yàn)證失敗");
resHandler.sendToCFT("fail");
response.setCharacterEncoding("utf-8");
}
}else {
System.out.println("fail -Md5 failed");
具體方法步驟:
一、準(zhǔn)備階段:已認(rèn)證微信號(hào),且通過微信支付認(rèn)證,這個(gè)可以看微信文檔,很詳細(xì),這里就不再重復(fù)。
二、配置授權(quán)目錄,官方推薦使用https類型的url,不知道http能不能行,個(gè)人也推薦使用https的保證不會(huì)錯(cuò)。
配置授權(quán)域名
三、微信支付二次開發(fā)所需要的參數(shù):
APP_ID,APP_KEY,PARTNER,PARTNER_KEY(AppSecret)
APP_ID和PARTNER_KEY(AppSecret)
PARTNER
APP_KEY(自行設(shè)置32位字符)
四、具體編程
1、通過頁面跳轉(zhuǎn)到確認(rèn)支付頁面,其中的redirect_uri必須是配置授權(quán)目錄下的。
2、獲取到openid,再經(jīng)服務(wù)器向微信請(qǐng)求獲取prepay_id,封裝字段并進(jìn)行簽名后通過jsapi調(diào)起微信支付
3、測(cè)試結(jié)果
? ?
import com.capinfo.crypt.*;
public class RsaTest
{
public RsaTest(){
}
public static void main(String[] args){
//首信公鑰文件
String publicKey = "d:/Public1024.key";
//簽名信息
String SignString = "3e5671bc4f91c3d055b18c1e5e22dd9db157380c7ee8facf0b1117082fbf398d7113c2df7e3219fc28dd88dd26cb096cabe607f3e397dfc2dcdb3349351a5f025ea0761da6e39e2d2fd311294a6076e777fe2ab8911f22113c435b89d63ae4f2aff2f333f7ebd40cc89601d58fb37b16596b5c94eb8b64cd52e12b9679248e6a";
//原信息
String strSource = "abcde12345";
try{
//公鑰驗(yàn)證
RSA_MD5 rsaMD5 = new RSA_MD5();
int k = rsaMD5.PublicVerifyMD5(publicKey,SignString,strSource);
if(k==0)
System.out.println("驗(yàn)證成功.");
else
System.out.println("驗(yàn)證失敗.");
}catch(Exception e){
System.out.println("驗(yàn)證異常.\n"+e);
}
}
}
哎,我還是自己代碼黏貼給你吧!免得總通不過!裝不下這么多字,詳情自己找我。 連接數(shù)據(jù)庫類(添加修改會(huì)員信息) package com.to.java; import java.util.Scanner; import java.sql.*; public class Vds { Scanner Input=new Scanner(System.in); ZhuCK1 zhuck1=new ZhuCK1(); public void x(){ try{ Connection con=null; Statement stmt=null; ResultSet rs=null; Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); String ur1="jdbc:odbc:gg"; con=DriverManager.getConnection(ur1); stmt=con.createStatement(); String sqlstmt="select id,mm from gg"; rs=stmt.executeQuery(sqlstmt); System.out.println("----------查詢結(jié)果---------"); System.out.println(); System.out.println("會(huì)員號(hào)--密碼"); while(rs.next()){ String id=rs.getString("id"); String mm=rs.getString("mm"); System.out.println(id+" "+mm); } con.close(); stmt.close(); }catch(Exception e){ System.out.println(e);} System.out.println("是否返回上級(jí)菜單"); System.out.println("1.是"); System.out.println("2.否"); int m=Input.nextInt(); switch(m){ case 1: zhuck1.ZhucK1(); break; case 2: { System.out.println("歡迎下次再次使用");System.exit(-1);}; break; }} public void j(){ try{ Connection con=null; Statement stmt=null; ResultSet rs=null; Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); String ur1="jdbc:odbc:gg"; con=DriverManager.getConnection(ur1); stmt=con.createStatement(); String sqlstmt="select id,mm from gg"; rs=stmt.executeQuery(sqlstmt); while(rs.next()){ String id=rs.getString("id"); String mm=rs.getString("mm"); System.out.println(id+" "+mm); } Scanner input=new Scanner(System.in); System.out.println("請(qǐng)輸入會(huì)員信息:"); System.out.println("請(qǐng)輸入會(huì)員號(hào):"); String f=input.next(); System.out.println("請(qǐng)輸入密碼:"); String q=input.next(); String sqlst="insert into gg values('"+f+"','"+q+"')"; Statement tatement=con.createStatement(); int result=tatement.executeUpdate(sqlst); System.out.println("操作成功!"); con.close(); stmt.close(); }catch(Exception e){ System.out.println(e); } System.out.println("是否返回上級(jí)菜單"); System.out.println("1.是"); System.out.println("2.否"); int m=Input.nextInt(); switch(m){ case 1: zhuck1.ZhucK1(); break; case 2: { System.out.println("歡迎下次再次使用");System.exit(-1);}; break; } } public void xg(){ try{ Connection con=null; Statement stmt=null; ResultSet rs=null; Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); String ur1="jdbc:odbc:gg"; con=DriverManager.getConnection(ur1); stmt=con.createStatement(); String sqlstmt="select id,mm from gg"; rs=stmt.executeQuery(sqlstmt); while(rs.next()){ String id=rs.getString("id"); String mm=rs.getString("mm"); System.out.println(id+" "+mm); } Scanner input=new Scanner(System.in); System.out.println("請(qǐng)輸入會(huì)員信息:"); System.out.println("請(qǐng)輸入要修改的會(huì)員號(hào):"); String f=input.next(); System.out.println("請(qǐng)輸入修改的密碼:"); String q=input.next(); String sqlst="update gg set mm='"+q+"' where id='"+f+"'"; Statement tatement=con.createStatement(); int result=tatement.executeUpdate(sqlst); System.out.println("操作成功!"); con.close(); stmt.close(); }catch(Exception e){ System.out.println(e); } System.out.println("是否返回上級(jí)菜單"); System.out.println("1.是"); System.out.println("2.否"); int m=Input.nextInt(); switch(m){ case 1: zhuck1.ZhucK1(); break; case 2: { System.out.println("歡迎下次再次使用");System.exit(-1);}; break; } } } package com.to.java; import java.util.Scanner; public class KeHu { Vds sj=new Vds(); public void kehu1(){ Scanner Input=new Scanner(System.in); ZhuCK1 zhuck1=new ZhuCK1(); System.out.println("******************************************************"+"\n\n"); System.out.println("1.顯示所有客戶信息"); System.out.println("2.添加客戶信息"); System.out.println("3.修改客戶信息"); System.out.println("4.查詢客戶信息"); System.out.println("5.返回上級(jí)菜單"); System.out.println("******************************************************"+"\n\n"); System.out.println("請(qǐng)輸入數(shù)字:"); int a=Input.nextInt(); switch(a){ case 1: sj.x(); break; case 2: sj.j(); break; case 3: sj.xg(); break; case 4: sj.x();break; case 5: zhuck1.ZhucK1();break; } } } package com.to.java; public class GouWuXiTong { public static void main(String[] args){ ZhuCK zhuck=new ZhuCK(); zhuck.ZhucK(); } } package com.to.java; import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.Statement; import java.util.Scanner; public class ZhuCK { Scanner Input=new Scanner(System.in); public void ZhucK(){ ZhuCK1 zhuck1=new ZhuCK1(); System.out.println("\t\t"+"歡迎使用我心我素購物系統(tǒng)"); System.out.println("******************************************************"+"\n\n"); System.out.println("\t\t"+"1.登陸系統(tǒng)"); System.out.println(); System.out.println("\t\t"+"2.退出"+"\n\n"); System.out.println("******************************************************"); int d=1; while(d!=2){ System.out.println("請(qǐng)輸入會(huì)員號(hào):"); String p=Input.next(); System.out.println("請(qǐng)輸入密碼:"); String f=Input.next(); try{ Connection con=null; Statement stmt=null; ResultSet rs=null; Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); String ur1="jdbc:odbc:gg"; con=DriverManager.getConnection(ur1); stmt=con.createStatement(); String sqlstmt="select * from gg"; rs=stmt.executeQuery(sqlstmt); while(rs.next()){ String id=rs.getString("id"); String mm=rs.getString("mm"); if(id.equals(p)mm.equals(f)){ { System.out.println("請(qǐng)輸入數(shù)字:"); int a=Input.nextInt(); switch(a){ case 1: zhuck1.ZhucK1(); break; case 2: break; }d=2; } } } }catch(Exception e){ System.out.println(e);} {System.out.println("輸入錯(cuò)誤請(qǐng)?jiān)俅屋斎耄?);d=1;} } }} }