import?java.io.IOException;
成都創(chuàng)新互聯(lián)公司主要從事網(wǎng)站設計、網(wǎng)站制作、網(wǎng)頁設計、企業(yè)做網(wǎng)站、公司建網(wǎng)站等業(yè)務。立足成都服務臨夏,十多年網(wǎng)站建設經(jīng)驗,價格優(yōu)惠、服務專業(yè),歡迎來電咨詢建站服務:18982081108
import?java.io.InputStream;
import?java.util.ArrayList;
import?java.util.List;
public?class?Change?{
/**
?*?@param?args
?*/
public?static?void?main(String[]?args)?{
System.out.println("請輸入價格:");
double?m?=?Double.parseDouble(getInputLine());
System.out.println("請付款金額:");
double?c?=?Double.parseDouble(getInputLine());
change(m,?c);
}
public?static?String?getInputLine()?{
InputStream?inputStream?=?System.in;
ListByte?cmdBuffer?=?new?ArrayListByte();
int?t;
try?{
while?(true)?{
t?=?inputStream.read();
if?(t?==?'\n')?{
byte[]?bs?=?new?byte[cmdBuffer.size()];
for?(int?i?=?0;?i??cmdBuffer.size();?i++)?{
bs[i]?=?cmdBuffer.get(i);
}
return?new?String(bs).trim();
}?else?{
cmdBuffer.add((byte)?t);
if?(cmdBuffer.size()??1024)?{
return?null;
}
}
}
}?catch?(IOException?e)?{
return?null;
}
}
public?static?double[]?moneys?=?{?0.01,?0.02,?0.05,?0.1,?0.2,?0.5,?1,?2,?5,?10,?20,?50,?100?};
/**
?*?@param?m
?*????????????價格
?*?@param?c
?*????????????付款
?*/
public?static?void?change(double?m,?double?c)?{
double?z?=?c?-?m;
if?(z??0)?{
System.out.println("付款不足!");
}?else?if?(z?==?0)?{
System.out.println("不需要找零。");
}?else?{
System.out.println("找零共:"?+?z?+?"元");
System.out.println("其中:");
for?(int?i?=?moneys.length?-?1;?i?=?0;?i--)?{
double?money?=?moneys[i];
int?count?=?0;
while?((z?-?money)?=?0)?{
z?-=?money;
count++;
}
if?(count??0)?{
System.out.println(money?+?"元:"?+?count?+?"張");
}
}
}
}
}
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{
//公鑰驗證
RSA_MD5 rsaMD5 = new RSA_MD5();
int k = rsaMD5.PublicVerifyMD5(publicKey,SignString,strSource);
if(k==0)
System.out.println("驗證成功.");
else
System.out.println("驗證失敗.");
}catch(Exception e){
System.out.println("驗證異常.\n"+e);
}
}
}
java調用微信支付接口方法:\x0d\x0aRequestHandlerrequestHandler=newRequestHandler(super.getRequest(),super.getResponse());\x0d\x0a\x0d\x0a//獲取token//兩小時內(nèi)有效,兩小時后重新獲取\x0d\x0a\x0d\x0aToken=requestHandler.GetToken();\x0d\x0a\x0d\x0a//更新token到應用中\(zhòng)x0d\x0a\x0d\x0arequestHandler.getTokenReal();\x0d\x0a\x0d\x0aSystem.out.println("微信支付獲取token=======================:"+Token);\x0d\x0a\x0d\x0a\x0d\x0a\x0d\x0a//requestHandler初始化\x0d\x0a\x0d\x0arequestHandler.init();\x0d\x0a\x0d\x0arequestHandler.init(appid,appsecret,appkey,partnerkey,key);\x0d\x0a\x0d\x0a\x0d\x0a\x0d\x0a//--------------------------------本地系統(tǒng)生成訂單-------------------------------------\x0d\x0a\x0d\x0a//設置package訂單參數(shù)\x0d\x0a\x0d\x0aSortedMappackageParams=newTreeMap();\x0d\x0a\x0d\x0apackageParams.put("bank_type","WX");//支付類型\x0d\x0a\x0d\x0apackageParams.put("body","xxxx");//商品描述\x0d\x0a\x0d\x0apackageParams.put("fee_type","1");//銀行幣種\x0d\x0a\x0d\x0apackageParams.put("input_charset","UTF-8");//字符集\x0d\x0a\x0d\x0apackageParams.put("notify_url","");//通知地址這里的通知地址使用外網(wǎng)地址測試,注意80端口是否打開。\x0d\x0a\x0d\x0apackageParams.put("out_trade_no",no);//商戶訂單號\x0d\x0a\x0d\x0apackageParams.put("partner",partenerid);//設置商戶號\x0d\x0a\x0d\x0apackageParams.put("spbill_create_ip",super.getRequest().getRemoteHost());//訂單生成的機器IP,指用戶瀏覽器端IP\x0d\x0a\x0d\x0apackageParams.put("total_fee",String.valueOf(rstotal));//商品總金額,以分為單位\x0d\x0a\x0d\x0a\x0d\x0a\x0d\x0a//設置支付參數(shù)\x0d\x0a\x0d\x0aSortedMapsignParams=newTreeMap();\x0d\x0a\x0d\x0asignParams.put("appid",appid);\x0d\x0a\x0d\x0asignParams.put("noncestr",noncestr);\x0d\x0a\x0d\x0asignParams.put("traceid",PropertiesUtils.getOrderNO());\x0d\x0a\x0d\x0asignParams.put("timestamp",timestamp);\x0d\x0a\x0d\x0asignParams.put("package",packageValue);\x0d\x0a\x0d\x0asignParams.put("appkey",this.appkey);\x0d\x0a\x0d\x0a\x0d\x0a\x0d\x0a//生成支付簽名,要采用URLENCODER的原始值進行SHA1算法!\x0d\x0a\x0d\x0aStringsign="";\x0d\x0a\x0d\x0atry{\x0d\x0a\x0d\x0asign=Sha1Util.createSHA1Sign(signParams);\x0d\x0a\x0d\x0a}catch(Exceptione){\x0d\x0a\x0d\x0ae.printStackTrace();\x0d\x0a\x0d\x0a}\x0d\x0a\x0d\x0a\x0d\x0a\x0d\x0a//增加非參與簽名的額外參數(shù)\x0d\x0a\x0d\x0asignParams.put("sign_method","sha1");\x0d\x0a\x0d\x0asignParams.put("app_signature",sign);\x0d\x0a\x0d\x0a\x0d\x0a\x0d\x0a\x0d\x0a\x0d\x0a//api支付拼包結束------------------------------------\x0d\x0a\x0d\x0a\x0d\x0a\x0d\x0a//獲取prepayid\x0d\x0a\x0d\x0aStringprepayid=requestHandler.sendPrepay(signParams);\x0d\x0a\x0d\x0aSystem.out.println("prepayid:"+prepayid);\x0d\x0a\x0d\x0a\x0d\x0a\x0d\x0a\x0d\x0a\x0d\x0a\x0d\x0a\x0d\x0a//--------------------------------生成完成---------------------------------------------\x0d\x0a\x0d\x0a\x0d\x0a\x0d\x0a//生成預付快訂單完成,返回給android,ios掉起微信所需要的參數(shù)。\x0d\x0a\x0d\x0aSortedMappayParams=newTreeMap();\x0d\x0a\x0d\x0apayParams.put("appid",appid);\x0d\x0a\x0d\x0apayParams.put("noncestr",noncestr);\x0d\x0a\x0d\x0apayParams.put("package","Sign=WXPay");\x0d\x0a\x0d\x0apayParams.put("partnerid",partenerid);\x0d\x0a\x0d\x0apayParams.put("prepayid",prepayid);\x0d\x0a\x0d\x0apayParams.put("appkey",this.appkey);\x0d\x0a\x0d\x0a//這里除1000是因為參數(shù)長度限制。\x0d\x0a\x0d\x0ainttime=(int)(System.currentTimeMillis()/1000);\x0d\x0a\x0d\x0apayParams.put("timestamp",String.valueOf(time));\x0d\x0a\x0d\x0a\x0d\x0a\x0d\x0aSystem.out.println("timestamp:"+time);\x0d\x0a\x0d\x0a\x0d\x0a\x0d\x0a//簽名\x0d\x0a\x0d\x0aStringpaysign="";\x0d\x0a\x0d\x0atry{\x0d\x0a\x0d\x0apaysign=Sha1Util.createSHA1Sign(payParams);\x0d\x0a\x0d\x0a}catch(Exceptione){\x0d\x0a\x0d\x0ae.printStackTrace();\x0d\x0a\x0d\x0a}\x0d\x0a\x0d\x0apayParams.put("sign",paysign);\x0d\x0a\x0d\x0a\x0d\x0a\x0d\x0a//拼json數(shù)據(jù)返回給客戶端\x0d\x0a\x0d\x0aBasicDBObjectbackObject=newBasicDBObject();\x0d\x0a\x0d\x0abackObject.put("appid",appid);\x0d\x0a\x0d\x0abackObject.put("noncestr",payParams.get("noncestr"));\x0d\x0a\x0d\x0abackObject.put("package","Sign=WXPay");\x0d\x0a\x0d\x0abackObject.put("partnerid",payParams.get("partnerid"));\x0d\x0a\x0d\x0abackObject.put("prepayid",payParams.get("prepayid"));\x0d\x0a\x0d\x0abackObject.put("appkey",this.appkey);\x0d\x0a\x0d\x0abackObject.put("timestamp",payParams.get("timestamp"));\x0d\x0a\x0d\x0abackObject.put("sign",payParams.get("sign"));\x0d\x0a\x0d\x0a\x0d\x0a\x0d\x0aStringbackstr=dataObject.toString();\x0d\x0a\x0d\x0aSystem.out.println("backstr:"+backstr);\x0d\x0a\x0d\x0a\x0d\x0a\x0d\x0areturnbackstr;\x0d\x0a\x0d\x0a\x0d\x0a\x0d\x0a====================到此為止,預付款訂單已生成,并且已返回客戶端====================\x0d\x0a\x0d\x0a\x0d\x0a\x0d\x0a//坐等微信服務器通知,通知的地址就是生成預付款訂單的notify_url\x0d\x0a\x0d\x0a\x0d\x0a\x0d\x0aResponseHandlerresHandler=newResponseHandler(request,response);\x0d\x0a\x0d\x0aresHandler.setKey(partnerkey);\x0d\x0a\x0d\x0a//創(chuàng)建請求對象\x0d\x0a\x0d\x0a//RequestHandlerqueryReq=newRequestHandler(request,response);\x0d\x0a\x0d\x0a//queryReq.init();\x0d\x0a\x0d\x0aif(resHandler.isTenpaySign()==true){\x0d\x0a\x0d\x0a//商戶訂單號\x0d\x0a\x0d\x0aStringout_trade_no=resHandler.getParameter("out_trade_no");\x0d\x0a\x0d\x0aSystem.out.println("out_trade_no:"+out_trade_no);\x0d\x0a\x0d\x0a//財付通訂單號\x0d\x0a\x0d\x0aStringtransaction_id=resHandler.getParameter("transaction_id");\x0d\x0a\x0d\x0aSystem.out.println("transaction_id:"+transaction_id);\x0d\x0a\x0d\x0a//金額,以分為單位\x0d\x0a\x0d\x0aStringtotal_fee=resHandler.getParameter("total_fee");\x0d\x0a\x0d\x0a//如果有使用折扣券,discount有值,total_fee+discount=原請求的total_fee\x0d\x0a\x0d\x0aStringdiscount=resHandler.getParameter("discount");\x0d\x0a\x0d\x0a//支付結果\x0d\x0a\x0d\x0aStringtrade_state=resHandler.getParameter("trade_state");\x0d\x0a\x0d\x0a\x0d\x0a\x0d\x0a//判斷簽名及結果\x0d\x0a\x0d\x0aif("0".equals(trade_state)){\x0d\x0a\x0d\x0a//------------------------------\x0d\x0a\x0d\x0a//即時到賬處理業(yè)務開始\x0d\x0a\x0d\x0a//------------------------------\x0d\x0a\x0d\x0a\x0d\x0a\x0d\x0aSystem.out.println("----------------業(yè)務邏輯執(zhí)行-----------------");\x0d\x0a\x0d\x0a\x0d\x0a\x0d\x0a//——請根據(jù)您的業(yè)務邏輯來編寫程序(以上代碼僅作參考)——\x0d\x0a\x0d\x0aSystem.out.println("----------------業(yè)務邏輯執(zhí)行完畢-----------------");\x0d\x0a\x0d\x0aSystem.out.println("success");//請不要修改或刪除\x0d\x0a\x0d\x0a\x0d\x0a\x0d\x0aSystem.out.println("即時到賬支付成功");\x0d\x0a\x0d\x0a//給財付通系統(tǒng)發(fā)送成功信息,財付通系統(tǒng)收到此結果后不再進行后續(xù)通知\x0d\x0a\x0d\x0aresHandler.sendToCFT("success");\x0d\x0a\x0d\x0a\x0d\x0a\x0d\x0a//給微信服務器返回success否則30分鐘通知8次\x0d\x0a\x0d\x0areturn"success";\x0d\x0a\x0d\x0a}else{\x0d\x0a\x0d\x0aSystem.out.println("通知簽名驗證失敗");\x0d\x0a\x0d\x0aresHandler.sendToCFT("fail");\x0d\x0a\x0d\x0aresponse.setCharacterEncoding("utf-8");\x0d\x0a\x0d\x0a}\x0d\x0a\x0d\x0a}else{\x0d\x0a\x0d\x0aSystem.out.println("fail-Md5failed");