資源簡介
1.配置PayConfig的參數(shù)就能用(里面注釋寫的很清楚。)。
2.通過填寫訂單號(hào),商品名稱、價(jià)格,生成二維碼。掃碼即可付款。
3.如發(fā)現(xiàn)商品名稱中文亂碼問題,請(qǐng)?jiān)O(shè)置項(xiàng)目編碼為utf-8。因?yàn)橐呀?jīng)解決了中文亂碼的其他問題。

代碼片段和文件信息
package?com.pangxie.controller;
import?java.io.IOException;
import?java.util.Map;
import?java.util.SortedMap;
import?java.util.TreeMap;
import?javax.servlet.ServletException;
import?javax.servlet.annotation.WebServlet;
import?javax.servlet.http.HttpServlet;
import?javax.servlet.http.HttpServletRequest;
import?javax.servlet.http.HttpServletResponse;
import?org.dom4j.Document;
import?org.dom4j.DocumentException;
import?org.dom4j.Element;
import?org.dom4j.io.SAXReader;
import?org.jdom.JDOMException;
import?com.pangxie.utils.HttpUtil;
import?com.pangxie.utils.PayCommonUtil;
import?com.pangxie.utils.PayConfigUtil;
import?com.pangxie.utils.xmlUtil;
/**
?*?Servlet?implementation?class?PayController
?*/
@WebServlet(“/PayController“)
public?class?PayController?extends?HttpServlet?{
private?static?final?long?serialVersionUID?=?1L;
???????
????/**
?????*?@see?HttpServlet#HttpServlet()
?????*/
????public?PayController()?{
????????super();
????????//?TODO?Auto-generated?constructor?stub
????}
/**
?*?@see?HttpServlet#service(HttpServletRequest?request?HttpServletResponse?response)
?*/
protected?void?service(HttpServletRequest?request?HttpServletResponse?response)?throws?ServletException?IOException?{
SortedMapjectobject>?packageParams?=?new?TreeMapjectobject>();?
????packageParams.put(“appid“?PayConfigUtil.APP_ID);?
????packageParams.put(“mch_id“?PayConfigUtil.MCH_ID);
????packageParams.put(“nonce_str“?String.valueOf(PayCommonUtil.buildRandom(30)));
????packageParams.put(“body“?new?String(request.getParameter(“body“).getBytes(“ISO-8859-1“)“utf-8“));//商品描述
????packageParams.put(“out_trade_no“?request.getParameter(“out_trade_no“));?//商品訂單
????packageParams.put(“total_fee“?request.getParameter(“total_fee“));?//商品價(jià)格
????packageParams.put(“spbill_create_ip“?PayCommonUtil.getHostIP());?//終端IP
????packageParams.put(“notify_url“?PayConfigUtil.NOTIFY_URL);?
????packageParams.put(“trade_type“?PayConfigUtil.TRADE_TYPE);
????
????String?sign?=?PayCommonUtil.createSign(“UTF-8“?packageParamsPayConfigUtil.API_KEY);?
????packageParams.put(“sign“?sign);?
// ????System.out.println(request.getParameter(“body“));
// ????String?username=request.getParameter(“body“);
// ????String?username1=new?String(username.getBytes(“ISO-8859-1“)“utf-8“);
// ????System.out.println(username1);
????String?requestxml?=?PayCommonUtil.getRequestxml(packageParams);?
??
????String?resxml?=?HttpUtil.postData(PayConfigUtil.API_URL?requestxml);?
?
????Map?map?=?null;
try?{
map?=?xmlUtil.doxmlParse(resxml);
}?catch?(JDOMException?e)?{
//?TODO?Auto-generated?catch?block
e.printStackTrace();
}?
????//String?return_code?=?(String)?map.get(“return_code“);?
????//String?prepay_id?=?(String)?map.get(“prepay_id“);
????String?urlCode?=?(String)?map.get(“code_url“);
????request.getSession().setAttribute(“code_url“?urlCode);
????request.getRequestDispatcher(“pay.
?屬性????????????大小?????日期????時(shí)間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2017-04-27?14:54??weixin_pay\
?????文件?????????953??2017-04-27?14:56??weixin_pay\.classpath
?????文件????????1052??2017-04-27?14:58??weixin_pay\.project
?????目錄???????????0??2017-04-27?17:32??weixin_pay\.settings\
?????文件?????????567??2016-12-16?10:10??weixin_pay\.settings\.jsdtscope
?????文件?????????109??2017-04-27?17:37??weixin_pay\.settings\org.eclipse.core.resources.prefs
?????文件?????????364??2017-04-27?14:55??weixin_pay\.settings\org.eclipse.jdt.core.prefs
?????文件?????????482??2016-12-16?10:10??weixin_pay\.settings\org.eclipse.wst.common.component
?????文件?????????345??2016-12-16?10:10??weixin_pay\.settings\org.eclipse.wst.common.project.facet.core.xm
?????文件??????????49??2016-12-16?10:10??weixin_pay\.settings\org.eclipse.wst.jsdt.ui.superType.container
?????文件???????????6??2016-12-16?10:10??weixin_pay\.settings\org.eclipse.wst.jsdt.ui.superType.name
?????目錄???????????0??2017-04-27?14:54??weixin_pay\WebContent\
?????目錄???????????0??2017-04-27?14:54??weixin_pay\WebContent\me
?????文件??????????39??2016-12-16?10:10??weixin_pay\WebContent\me
?????目錄???????????0??2017-04-27?14:54??weixin_pay\WebContent\WEB-INF\
?????目錄???????????0??2017-04-27?14:54??weixin_pay\WebContent\WEB-INF\lib\
?????文件??????255182??2016-12-16?11:49??weixin_pay\WebContent\WEB-INF\lib\catalina-tribes.jar
?????文件??????538199??2016-12-16?13:35??weixin_pay\WebContent\WEB-INF\lib\core-3.0.0.jar
?????文件??????312181??2016-12-16?15:25??weixin_pay\WebContent\WEB-INF\lib\dom4j-2.0.0.jar
?????文件??????151304??2016-12-16?11:54??weixin_pay\WebContent\WEB-INF\lib\jdom-1.1.3.jar
?????文件????????1220??2016-12-16?16:29??weixin_pay\WebContent\WEB-INF\web.xm
?????文件?????????717??2017-04-27?17:11??weixin_pay\WebContent\index.jsp
?????文件?????????417??2016-12-16?16:17??weixin_pay\WebContent\pay.jsp
?????文件?????????393??2016-12-16?16:49??weixin_pay\WebContent\return.jsp
?????目錄???????????0??2017-04-27?14:54??weixin_pay\build\
?????目錄???????????0??2017-04-27?15:49??weixin_pay\build\classes\
?????目錄???????????0??2017-04-27?15:49??weixin_pay\build\classes\com\
?????目錄???????????0??2017-04-27?15:49??weixin_pay\build\classes\com\pangxie\
?????目錄???????????0??2017-04-27?17:43??weixin_pay\build\classes\com\pangxie\controller\
?????文件????????3416??2017-04-27?17:48??weixin_pay\build\classes\com\pangxie\controller\PayController.class
?????文件????????1564??2017-04-27?17:32??weixin_pay\build\classes\com\pangxie\controller\QRCodeController.class
............此處省略24個(gè)文件信息
評(píng)論
共有 條評(píng)論