import java.io.IOException;
成都创新互联公司主要从事网站设计、网站制作、网页设计、企业做网站、公司建网站等业务。立足成都服务临夏,十多年网站建设经验,价格优惠、服务专业,欢迎来电咨询建站服务: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//两小时内有效,两小时后重新获取\x0d\x0a\x0d\x0aToken=requestHandler.GetToken();\x0d\x0a\x0d\x0a//更新token到应用中\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//--------------------------------本地系统生成订单-------------------------------------\x0d\x0a\x0d\x0a//设置package订单参数\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","");//通知地址这里的通知地址使用外网地址测试,注意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//设置支付参数\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//增加非参与签名的额外参数\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掉起微信所需要的参数。\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是因为参数长度限制。\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数据返回给客户端\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//创建请求对象\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//即时到账处理业务开始\x0d\x0a\x0d\x0a//------------------------------\x0d\x0a\x0d\x0a\x0d\x0a\x0d\x0aSystem.out.println("----------------业务逻辑执行-----------------");\x0d\x0a\x0d\x0a\x0d\x0a\x0d\x0a//——请根据您的业务逻辑来编写程序(以上代码仅作参考)——\x0d\x0a\x0d\x0aSystem.out.println("----------------业务逻辑执行完毕-----------------");\x0d\x0a\x0d\x0aSystem.out.println("success");//请不要修改或删除\x0d\x0a\x0d\x0a\x0d\x0a\x0d\x0aSystem.out.println("即时到账支付成功");\x0d\x0a\x0d\x0a//给财付通系统发送成功信息,财付通系统收到此结果后不再进行后续通知\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");