| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039 |
- package com.sharemao.web.wx.ctrl;
- import java.io.IOException;
- import java.io.UnsupportedEncodingException;
- import java.math.BigDecimal;
- import java.math.RoundingMode;
- import java.security.PrivateKey;
- import java.security.PublicKey;
- import java.util.HashMap;
- import java.util.Iterator;
- import java.util.Map;
- import java.util.Set;
- import java.util.SortedMap;
- import java.util.TreeMap;
- import javax.servlet.http.HttpSession;
- import com.sharemao.web.wx.syb.SybConstants;
- import com.sharemao.web.wx.syb.SybUtil;
- import org.apache.commons.codec.digest.DigestUtils;
- import org.apache.commons.logging.Log;
- import org.apache.commons.logging.LogFactory;
- import org.apache.http.client.methods.CloseableHttpResponse;
- import org.apache.http.client.methods.HttpPost;
- import org.apache.http.entity.StringEntity;
- import org.apache.http.impl.client.CloseableHttpClient;
- import org.apache.http.impl.client.HttpClients;
- import org.apache.http.util.EntityUtils;
- import org.apache.http.util.TextUtils;
- import com.alibaba.fastjson.JSONArray;
- import com.alibaba.fastjson.JSONObject;
- import com.alibaba.fastjson2.JSON;
- import com.nianzai.base.mvc.Context;
- import com.nianzai.base.mvc.annotation.Controller;
- import com.nianzai.base.mvc.annotation.Path;
- import com.nianzai.base.mvc.view.SimpleJsonView;
- import com.nianzai.base.mvc.view.TextView;
- import com.nianzai.util.CodecUtil;
- import com.nianzai.util.Tools;
- import com.sharemao.web.wx.Constants;
- import com.sharemao.web.wx.JsApiReqData;
- import com.sharemao.web.wx.JsApiToJsData;
- import com.sharemao.web.wx.util.GzhUtil;
- import com.sharemao.web.wx.util.JsApiReqUtils;
- import com.sharemao.web.wx.util.Message2XmlUtil;
- import com.sharemao.web.wx.util.PaySign;
- import com.sharemao.web.wx.util.SignUtils;
- import com.sharemao.web.wx.util.XmlUtils;
- import com.sharemao.web.wx.util.YL;
- @Controller("/mifi")
- public class PayCtrl
- {
- private static final Log log = LogFactory.getLog(PayCtrl.class);
-
- /**
- * 跳转至商品下单界面
- * @param context
- * @return
- */
- @Path(value="/pdtOrder.do")
- public TextView pdtOrder(Context context)
- {
- HttpSession session = context.getRequest().getSession();
- Map<String, String> para = context.getParas();
- String appuid = String.valueOf(session.getAttribute("appuid"));
- if(GzhUtil.isEmpty(appuid))
- return new TextView(Constants.loginUrl);
-
- para.put("appuid", appuid);
- String addressId = para.get("addressId");
- GzhUtil.toM3Sign(para);
- // 获取默认收货地址
- String result = GzhUtil.sendPost(Constants.m3IntAddr + "/user/getAddr.do", para);
- JSONObject resJson = JSONObject.parseObject(result);
- JSONObject dataJson = resJson.getJSONObject("data");
- JSONArray addrJson = dataJson.getJSONArray("addr");
- JSONObject address = new JSONObject();
-
- if(addrJson.size() > 0)
- {
- if(!GzhUtil.isEmpty(addressId))
- {
- for(int i=0; i<addrJson.size(); i++)
- {
- JSONObject addr = addrJson.getJSONObject(i);
- if(addressId.equals(addr.getString("addressId")))
- {
- address = addr;
- break;
- }
- }
- }
- else
- {
- for(int i=0; i<addrJson.size(); i++)
- {
- JSONObject addr = addrJson.getJSONObject(i);
- if(addr.getIntValue("isdefault") == 0)
- {
- address = addr;
- break;
- }
- }
- }
-
- String detail = address.getString("detailAddr");
- if(detail.length() > 25)
- {
- detail = detail.substring(0, 25)+"...";
- address.put("address", detail);
- }
- else
- address.put("address", detail);
- context.getRequest().setAttribute("addr", address);
- }
-
- @SuppressWarnings("unchecked")
- Map<String, Object> pdtInfo = (Map<String, Object>) session.getAttribute("pdtInfo");
-
- context.getRequest().setAttribute("pdtInfo", pdtInfo);
- return new TextView("/order/pdtorder.jsp");
- }
-
- /**
- * 跳转至套餐购买下单界面
- * @param context
- * @return
- */
- @Path(value="/settlement.do")
- public TextView settlement(Context context)
- {
- HttpSession session = context.getRequest().getSession();
- Map<String, String> para = context.getParas();
- log.info("para==>"+para);
- String devid = para.get("devid");
- String pkgid = para.get("pkgid");
- String price0 = para.get("price");
- String sign = para.get("sign");
- String appuid = String.valueOf(session.getAttribute("appuid"));
- String openid = (String) session.getAttribute("openid");
- String wxCode = para.get("code");
- String opt = para.get("opt");
- if(GzhUtil.isEmpty(devid))
- {
- return new TextView("/user/index.do");
- }
- if(GzhUtil.isEmpty(appuid) || GzhUtil.isEmpty(openid))
- {
- if(!GzhUtil.isEmpty(wxCode))
- {
- Map<String,String> m=GzhUtil.getOpenId(wxCode,Constants.appId,Constants.appSecret);
- openid=m.get("openId");
- String accessToken=m.get("accessToken");
- session.setAttribute("openid", openid);
- session.setAttribute("accessToken", accessToken);
- log.info("wxCode="+wxCode+",openid="+openid);
- para.put("openid", openid);
- GzhUtil.toM3Sign(para);
- String u=Constants.m3IntAddr + "/user/wxIndex.do";
- String result = GzhUtil.sendPost(u, para);
- log.info("url="+u+",result="+result);
- JSONObject resJson = JSONObject.parseObject(result);
- int resCode = resJson.getIntValue("code");
- if(resCode == 0)
- {
- JSONObject dataJson = resJson.getJSONObject("data");
- if(dataJson!=null) {
- appuid=dataJson.getString("appuid");
- }
- session.setAttribute("appuid", appuid);
- session.setAttribute("openid", openid);
- }
- }
-
- if(GzhUtil.isEmpty(appuid) || GzhUtil.isEmpty(openid))
- {
- para.put("devid", devid);
- GzhUtil.toM3Sign(para);
- String result = GzhUtil.sendPost(Constants.m3IntAddr + "/user/getInfoByDevid.do", para);
- JSONObject resJson = JSONObject.parseObject(result);
- int resCode = resJson.getIntValue("code");
- if(resCode == 0)
- {
- JSONObject dataJson = resJson.getJSONObject("data");
- appuid=dataJson.getString("id");
- openid=dataJson.getString("openid");
- if(GzhUtil.isEmpty(appuid) || GzhUtil.isEmpty(openid))
- {
- return new TextView("/user/index.do");
- }
- session.setAttribute("appuid", appuid);
- session.setAttribute("openid", openid);
- } else {
- return new TextView("/user/index.do");
- }
- }
- }
- context.getRequest().setAttribute("devid", devid);
- context.getRequest().setAttribute("opt", opt);
- String signstr = pkgid+'#'+devid+'*'+price0;
- String signc = CodecUtil.str2md5(signstr);
- if(!signc.equals(sign)) {
- return new TextView("/user/index.do");
- }
- if(!GzhUtil.isEmpty(pkgid))
- {
- para.put("pkid", pkgid);
- GzhUtil.toM3Sign(para);
- String result = GzhUtil.sendPost(Constants.m3IntAddr + "/package/getPkgByPkid.do", para);
- JSONObject resJson = JSONObject.parseObject(result);
- log.info(resJson);
- int resCode = resJson.getIntValue("code");
- if(resCode == 0)
- {
- JSONObject dataJson = resJson.getJSONObject("data");
- dataJson = JSONObject.parseObject(dataJson.getString("pkg"));
- String pkgName = dataJson.getString("pkgName");
- String pkgDesc = dataJson.getString("pkgDesc");
- double price = dataJson.getDoubleValue("price");
- String ts = dataJson.getString("ts");
- String expiryDay = dataJson.getString("expiryDay");
- String paytype = dataJson.getString("paytype");
- Map<String, Object> pkgInfo = new HashMap<String, Object>();
- pkgInfo.put("pkgName", pkgName);
- pkgInfo.put("pkgDesc", pkgDesc);
- if(!GzhUtil.isEmpty(price0)) {
- price = Double.parseDouble(price0);
- }
- pkgInfo.put("price", price);
- pkgInfo.put("pkgid", pkgid);
- pkgInfo.put("ts", ts);
- pkgInfo.put("expiryDay", expiryDay);
- pkgInfo.put("paytype", paytype);
- session.setAttribute("pkgInfo", pkgInfo);
- context.getRequest().setAttribute("pkgInfo", pkgInfo);
- }
- }
-
- para.put("openid", openid);
- GzhUtil.toM3Sign(para);
- String result = GzhUtil.sendPost(Constants.m3IntAddr + "/user/getBalance.do", para);
- JSONObject resJson = JSONObject.parseObject(result);
- int resCode = resJson.getIntValue("code");
- if(resCode == 0)
- {
- JSONObject dataJson = resJson.getJSONObject("data");
- String balance=dataJson.getString("balance");
- context.getRequest().setAttribute("balance", balance);
- } else
- {
- context.getRequest().setAttribute("balance", "0.00");
- }
- result = GzhUtil.sendPost(Constants.m3IntAddr + "/package/getSPkgs.do", para);
- if(!Tools.isEmpty(result))
- {
- resJson = JSONObject.parseObject(result);
- JSONArray dataJson = resJson.getJSONArray("data");
- log.info(dataJson);
- context.getRequest().setAttribute("spkgs", dataJson);
- }
- result = GzhUtil.sendPost(Constants.m3IntAddr + "/packkey/getMember.do", para);
- if(!Tools.isEmpty(result))
- {
- resJson = JSONObject.parseObject(result);
- JSONArray dataJson = resJson.getJSONArray("data");
- context.getRequest().setAttribute("cons", dataJson);
- }
- return new TextView("/pkgordersyb.jsp");
- // return new TextView("/pkgorder.jsp");
- }
- /**
- * 跳转至加速包购买下单界面
- * @param context
- * @return
- */
- @Path(value="/settlementSpkgs.do")
- public TextView settlementSpkgs(Context context)
- {
- HttpSession session = context.getRequest().getSession();
- Map<String, String> para = context.getParas();
- log.info("spkgs para==>"+para);
- String devid = para.get("devid");
- String spkgid = para.get("spkgid");
- String price0 = para.get("price");
- String sign = para.get("sign");
- String appuid = String.valueOf(session.getAttribute("appuid"));
- String openid = (String) session.getAttribute("openid");
- String wxCode = para.get("code");
- if(GzhUtil.isEmpty(devid))
- {
- return new TextView("/user/index.do");
- }
- if(GzhUtil.isEmpty(appuid) || GzhUtil.isEmpty(openid))
- {
- if(!GzhUtil.isEmpty(wxCode))
- {
- Map<String,String> m=GzhUtil.getOpenId(wxCode,Constants.appId,Constants.appSecret);
- openid=m.get("openId");
- String accessToken=m.get("accessToken");
- session.setAttribute("openid", openid);
- session.setAttribute("accessToken", accessToken);
- log.info("wxCode="+wxCode+",openid="+openid);
- para.put("openid", openid);
- GzhUtil.toM3Sign(para);
- String u=Constants.m3IntAddr + "/user/wxIndex.do";
- String result = GzhUtil.sendPost(u, para);
- log.info("url="+u+",result="+result);
- JSONObject resJson = JSONObject.parseObject(result);
- int resCode = resJson.getIntValue("code");
- if(resCode == 0)
- {
- JSONObject dataJson = resJson.getJSONObject("data");
- if(dataJson!=null) {
- appuid=dataJson.getString("appuid");
- }
- session.setAttribute("appuid", appuid);
- session.setAttribute("openid", openid);
- }
- }
- if(GzhUtil.isEmpty(appuid) || GzhUtil.isEmpty(openid))
- {
- para.put("devid", devid);
- GzhUtil.toM3Sign(para);
- String result = GzhUtil.sendPost(Constants.m3IntAddr + "/user/getInfoByDevid.do", para);
- JSONObject resJson = JSONObject.parseObject(result);
- int resCode = resJson.getIntValue("code");
- if(resCode == 0)
- {
- JSONObject dataJson = resJson.getJSONObject("data");
- appuid=dataJson.getString("id");
- openid=dataJson.getString("openid");
- if(GzhUtil.isEmpty(appuid) || GzhUtil.isEmpty(openid))
- {
- return new TextView("/user/index.do");
- }
- session.setAttribute("appuid", appuid);
- session.setAttribute("openid", openid);
- } else {
- return new TextView("/user/index.do");
- }
- }
- }
- context.getRequest().setAttribute("devid", devid);
- context.getRequest().setAttribute("amount", price0);
- context.getRequest().setAttribute("speedpackid", spkgid);
- String signstr = spkgid+'#'+devid+'*'+price0;
- String signc = CodecUtil.str2md5(signstr);
- if(!signc.equals(sign)) {
- return new TextView("/mifi/benefit.do");
- }
- para.put("openid", openid);
- GzhUtil.toM3Sign(para);
- String result = GzhUtil.sendPost(Constants.m3IntAddr + "/user/getBalance.do", para);
- JSONObject resJson = JSONObject.parseObject(result);
- int resCode = resJson.getIntValue("code");
- if(resCode == 0)
- {
- JSONObject dataJson = resJson.getJSONObject("data");
- String balance=dataJson.getString("balance");
- context.getRequest().setAttribute("balance", balance);
- } else
- {
- context.getRequest().setAttribute("balance", "0.00");
- }
- return new TextView("/mifi/benefitSubmit.do");
- }
-
- /**
- * 跳转至套餐购买下单界面
- * @param context
- * @return
- */
- @Path(value="/pkgOrder.do")
- public TextView pkgOrder(Context context)
- {
- HttpSession session = context.getRequest().getSession();
- Map<String, String> para = context.getParas();
- String appuid = String.valueOf(session.getAttribute("appuid"));
-
- String cursn=(String)session.getAttribute("cursn");
- int devtype=GzhUtil.getDeviceType(cursn);
- if(devtype==0)
- {
- if(GzhUtil.isEmpty(appuid))
- return new TextView(Constants.loginUrl);
- }
-
- String devid = cursn;
- if (GzhUtil.isEmpty(devid)) {
- devid = GzhUtil.getDevID(session, para);
- }
-
- @SuppressWarnings("unchecked")
- Map<String, Object> pkgInfo = (Map<String, Object>) session.getAttribute("pkgInfo");
-
- String openid = (String) session.getAttribute("openid");
- para.put("openid", openid);
- GzhUtil.toM3Sign(para);
- String result = GzhUtil.sendPost(Constants.m3IntAddr + "/user/getBalance.do", para);
- JSONObject resJson = JSONObject.parseObject(result);
- int resCode = resJson.getIntValue("code");
- if(resCode == 0)
- {
- JSONObject dataJson = resJson.getJSONObject("data");
- String balance=dataJson.getString("balance");
- context.getRequest().setAttribute("balance", balance);
- } else
- {
- context.getRequest().setAttribute("balance", "0.00");
- }
- result = GzhUtil.sendPost(Constants.m3IntAddr + "/package/getSPkgs.do", para);
- if(!Tools.isEmpty(result))
- {
- resJson = JSONObject.parseObject(result);
- JSONArray dataJson = resJson.getJSONArray("data");
- log.info(dataJson);
- context.getRequest().setAttribute("spkgs", dataJson);
- }
- result = GzhUtil.sendPost(Constants.m3IntAddr + "/packkey/getMember.do", para);
- if(!Tools.isEmpty(result))
- {
- resJson = JSONObject.parseObject(result);
- JSONArray dataJson = resJson.getJSONArray("data");
- context.getRequest().setAttribute("cons", dataJson);
- }
- context.getRequest().setAttribute("pkgInfo", pkgInfo);
- context.getRequest().setAttribute("devid", devid);
- if("151992".equals(appuid)) {
- return new TextView("/pkgordersyb.jsp");
- }
- return new TextView("/pkgordersyb.jsp");
- // return new TextView("/pkgorder.jsp");
- }
-
- /**
- * 购买产品/套餐下单-支付
- * @param context
- * @return
- */
- @Path(value="/buyPdts.do")
- @SuppressWarnings("unchecked")
- public SimpleJsonView buyPdts(Context context)
- {
- HttpSession session = context.getRequest().getSession();
- Map<String,String> para = context.getParas();
- String appuid = String.valueOf(session.getAttribute("appuid"));
- // if(GzhUtil.isEmpty(appuid))
- // return new SimpleJsonView(Constants.noLoginMsg);
-
- String openid = (String) session.getAttribute("openid");
-
- if(Tools.isEmpty(Constants.appId) || Tools.isEmpty(Constants.apikey) || Tools.isEmpty(Constants.appSecret) || Tools.isEmpty(Constants.mch_id))
- {
- log.info("充值失败,支付信息为空>>>代理ID:"+Constants.orgid);
- return new SimpleJsonView("支付信息错误,请联系客服");
- }
-
- String amount = ""; //订单价格
- String outTradeNo = ""; //订单ID
- String body = "";
-
- int type = Integer.parseInt(para.get("type"));
- log.info("type="+type);
- if(type == 0)
- {
- body = "商品购买";
- Map<String, Object> pdtInfo = (Map<String, Object>) session.getAttribute("pdtInfo");
- amount = String.valueOf(pdtInfo.get("total"));
- para.put("pdtid", String.valueOf(pdtInfo.get("pdtid")));
- para.put("appuid", appuid);
- para.put("num", String.valueOf(pdtInfo.get("num")));
- para.put("price", amount);
-
- /***********************下单,获取订单编号-BEGIN***********************/
- log.info("设备购买,下单>>>"+para);
-
- GzhUtil.toM3PaySign(para);
- String result = GzhUtil.sendPost(Constants.m3IntAddr+"/device/buyPdts.do", para);
- JSONObject resJson = JSONObject.parseObject(result);
- log.info("购买设备获取订单编号返回:"+result);
- if(resJson.getIntValue("code") != 0){
- return new SimpleJsonView(resJson.getString("msg"));
- }
- JSONObject dataJson = resJson.getJSONObject("data");
- outTradeNo = dataJson.getString("orderid");
- }
- else if(type == 1)
- {
- body = "套餐购买";
- Map<String, Object> pkgInfo = (Map<String, Object>) session.getAttribute("pkgInfo");
- //amount = String.valueOf(pkgInfo.get("price"));
- amount = String.valueOf(para.get("amount"));
-
- para.put("pkid", String.valueOf(pkgInfo.get("pkgid")));
- para.put("appuid", appuid);
- para.put("price", amount);
- para.put("ts", String.valueOf(pkgInfo.get("ts")));
-
- /***********************下单,获取订单编号-BEGIN***********************/
- log.info("套餐购买,下单>>>"+para);
-
- GzhUtil.toM3PaySign(para);
- String result = GzhUtil.sendPost(Constants.m3IntAddr+"/package/buyPkg.do", para);
- JSONObject resJson = JSONObject.parseObject(result);
- log.info("购买套餐获取订单编号返回:"+result);
- if(resJson.getIntValue("code") != 0){
- return new SimpleJsonView(resJson);
- }
- JSONObject dataJson = resJson.getJSONObject("data");
- outTradeNo = dataJson.getString("orderid");
- }
-
- /***********************下单,获取订单编号-END***********************/
- //执行统一下单接口,初始化各参数
-
- String nonceStr = PaySign.getNonceStr();
- String spBillCreateIP = JsApiReqUtils.getRealIp(context.getRequest());
-
- //初始化传入参数
- BigDecimal dised = new BigDecimal(amount);
- // BigDecimal dised = new BigDecimal(0.01); //测试价格0.01,待修改为totalAmount zby
- BigDecimal diz = new BigDecimal(100);
-
- JsApiReqData jsApiReqData = new JsApiReqData(body,nonceStr,outTradeNo,dised.multiply(diz).intValue(),spBillCreateIP, openid,Constants.appId,Constants.mch_id,Constants.apikey);
- String info = Message2XmlUtil.JsApiReqData2xml(jsApiReqData).replaceAll("mch__id", "mch_id").replaceAll("nonce__str", "nonce_str").replaceAll("notify__url", "notify_url").replaceAll("out__trade__no", "out_trade_no").replaceAll("spbill__create__ip", "spbill_create_ip").replaceAll("total__fee>", "total_fee>").replaceAll("trade__type", "trade_type");
- log.info("info========="+info);
- String prepay_id="err";
- StringBuffer sb = JsApiReqUtils.httpsRequest(Constants.unifiedorderurl, "POST", info);
- log.info("sb=="+sb.toString());
- Map<String,Object> payInfo = new HashMap<String, Object>();
- if (!"".equals(sb.toString()))
- {
- try
- {
- //得到预支付ID,即prepay_id
- Map<String, String> getMap = Message2XmlUtil.parseXml(new String(sb.toString().getBytes(), "utf-8"));
- if(getMap.get("prepay_id")!=null)
- {
- //在return_code 和result_code都为SUCCESS的时候有返回
- prepay_id = getMap.get("prepay_id");
- log.info("订单:"+outTradeNo+",请求微信支付!");
- }
- else
- {
- log.info("获取预支付ID失败,返回参数为>>>>>>"+getMap);
- }
- }
- catch (UnsupportedEncodingException e)
- {
- log.info(Tools.getExceptionMessage(e));
- }
- Integer timeStramp = (int)(System.currentTimeMillis()/1000);
- JsApiToJsData jsApiToJsData = new JsApiToJsData(timeStramp,nonceStr,prepay_id,Constants.appId,Constants.apikey);
-
- payInfo.put("appId", jsApiToJsData.getAppid());
- payInfo.put("timeStamp", String.valueOf(jsApiToJsData.getTimeStamp()));
- payInfo.put("nonceStr", jsApiToJsData.getNonce_str());
- payInfo.put("package", "prepay_id="+jsApiToJsData.getPrepay_id());
- payInfo.put("signType", "MD5");
- payInfo.put("paySign", jsApiToJsData.getSign());
-
- log.info("支付信息:"+payInfo);
- }
- else
- {
- log.info("支付失败,支付参数初始化失败>>>{"+sb+"}");
- }
- return new SimpleJsonView(payInfo);
- }
-
- //银联支付
- @Path(value="/buyYLPdts.do")
- public SimpleJsonView buyYLPdts(Context context)
- {
- Map<String,String> para = context.getParas();
-
- HttpSession session = context.getRequest().getSession();
- String appuid = String.valueOf(session.getAttribute("appuid"));
- String openid = (String) session.getAttribute("openid");
- if(GzhUtil.isEmpty(appuid))
- {
- Map<String,String> result = new HashMap<String,String>();
- result.put("status", "403");
- result.put("msg", "请登录");
- return new SimpleJsonView(result);
- }
-
- String amount=para.get("amount"); //订单价格
- double af=Double.parseDouble(amount);
- //低于1元不能充值
- if(af<1)
- {
- Map<String,String> result = new HashMap<String,String>();
- result.put("status", "500");
- result.put("msg", "出错了");
- return new SimpleJsonView(result);
- }
- String outTradeNo = ""; //订单ID
- String notify=YL.notify;
-
- int type = Integer.parseInt(para.get("type"));
- log.info("type="+type);
- if(type == 0)
- {
- Map<String, Object> pdtInfo = (Map<String, Object>) session.getAttribute("pdtInfo");
- //amount = String.valueOf(pdtInfo.get("total"));
- //amount=para.get("amount");
- para.put("pdtid", String.valueOf(pdtInfo.get("pdtid")));
- para.put("appuid", appuid);
- para.put("num", String.valueOf(pdtInfo.get("num")));
- para.put("price", amount);
-
- /***********************下单,获取订单编号-BEGIN***********************/
- log.info("设备购买,下单>>>"+para);
-
- GzhUtil.toM3PaySign(para);
- String result = GzhUtil.sendPost(Constants.m3IntAddr+"/device/buyPdts.do", para);
- JSONObject resJson = JSONObject.parseObject(result);
- log.info("购买设备获取订单编号返回:"+result);
- if(resJson.getIntValue("code") != 0){
- return new SimpleJsonView(resJson.getString("msg"));
- }
- JSONObject dataJson = resJson.getJSONObject("data");
- outTradeNo = dataJson.getString("orderid");
- }
- else if(type == 1)
- {
- Map<String, Object> pkgInfo = (Map<String, Object>) session.getAttribute("pkgInfo");
- //amount = String.valueOf(pkgInfo.get("price"));
- //amount=para.get("amount");
- para.put("pkid", String.valueOf(pkgInfo.get("pkgid")));
- para.put("appuid", appuid);
- para.put("price", amount);
- para.put("ts", String.valueOf(pkgInfo.get("ts")));
-
- /***********************下单,获取订单编号-BEGIN***********************/
- log.info("套餐购买,下单>>>"+para);
-
- GzhUtil.toM3PaySign(para);
- String result = GzhUtil.sendPost(Constants.m3IntAddr+"/package/buyPkg.do", para);
- JSONObject resJson = JSONObject.parseObject(result);
- log.info("购买套餐获取订单编号返回:"+result);
- if(resJson.getIntValue("code") != 0){
- return new SimpleJsonView(resJson);
- }
- JSONObject dataJson = resJson.getJSONObject("data");
- outTradeNo = dataJson.getString("orderid");
- }
- else if(type == 2)
- {
- amount=para.get("amount");
- para.put("appuid", appuid);
- para.put("price", amount);
-
- //TODO pkgid pkgprice
- para.put("openid", openid);
- String pkgprice=para.get("pkgprice");
- para.put("pkgprice", pkgprice);
-
- /***********************下单,获取订单编号-BEGIN***********************/
- log.info("钱包充值,下单>>>"+para);
-
- GzhUtil.toM3PaySign(para);
- String result = GzhUtil.sendPost(Constants.m3IntAddr+"/package/buyMember.do", para);
- log.info(result);
- JSONObject resJson = JSONObject.parseObject(result);
- log.info("钱包充值获取订单编号返回:"+result);
- if(resJson.getIntValue("code") != 0){
- return new SimpleJsonView(resJson);
- }
- JSONObject dataJson = resJson.getJSONObject("data");
- outTradeNo = dataJson.getString("orderid");
- notify = YL.membernotify;
- }
- else if(type == 3)
- {
- amount=para.get("amount");
- para.put("appuid", appuid);
- para.put("price", amount);
-
- /***********************下单,获取订单编号-BEGIN***********************/
- log.info("加速包购买,下单>>>"+para);
-
- GzhUtil.toM3PaySign(para);
- String result = GzhUtil.sendPost(Constants.m3IntAddr+"/package/buySpeedPack.do", para);
- log.info(result);
- JSONObject resJson = JSONObject.parseObject(result);
- log.info("购买加速包获取订单编号返回:"+result);
- if(resJson.getIntValue("code") != 0){
- return new SimpleJsonView(resJson);
- }
- JSONObject dataJson = resJson.getJSONObject("data");
- outTradeNo = dataJson.getString("orderid");
- notify = YL.ylmemberspeedpacknotify;
- }
-
- SortedMap<String, String> map = new TreeMap<String, String>();
-
- String spBillCreateIP = JsApiReqUtils.getRealIp(context.getRequest());
-
- //初始化传入参数
- BigDecimal dised = new BigDecimal(amount);
- // BigDecimal dised = new BigDecimal(0.01); //测试价格0.01,待修改为totalAmount zby
- BigDecimal diz = new BigDecimal(100);
- if("151992".equals(appuid) || "174056".equals(appuid)) {
- dised = new BigDecimal(0.01);
- }
- // String key = "432fc0caf293dde237e574fbf057f056";
- // String mch_id="QRA6072481C0003";
- // String notify="http://shuhai.sharemao.cn/mifi/ylnotify.do";
- /*String key = YL.key;
- String mch_id=YL.mch_id;
- // String notify=YL.notify;
- map.put("body", "收款码收款_商品");
- map.put("charset", "UTF-8");
- map.put("is_raw", "1");
- map.put("mch_create_ip", spBillCreateIP);
- map.put("mch_id", mch_id);
- map.put("nonce_str", "str"+System.currentTimeMillis());
- map.put("notify_url", notify);
- map.put("out_trade_no", outTradeNo);
- map.put("service", "pay.weixin.jspay");
- map.put("sign_type", "MD5");
- map.put("sub_openid", openid);
- map.put("total_fee", String.valueOf(dised.multiply(diz).intValue()));
- map.put("version", "2.0");
- map.put("sign", sign(map,key));
- String reqUrl = "https://qra.95516.com/pay/gateway";
- log.info("reqUrl:" + reqUrl);
- log.info("reqParams:" + XmlUtils.parseXML(map));
- CloseableHttpResponse response = null;
- CloseableHttpClient client = null;
- String res = null;
- Map<String, String> resultMap = null;
- Map<String,String> payInfo = new HashMap<String,String>();
- try {
- HttpPost httpPost = new HttpPost(reqUrl);
- StringEntity entityParams = new StringEntity(XmlUtils.parseXML(map), "utf-8");
- httpPost.setEntity(entityParams);
- httpPost.setHeader("Content-Type", "text/xml;utf-8");
- client = HttpClients.createDefault();
- response = client.execute(httpPost);
- if (response != null && response.getEntity() != null) {
- resultMap = XmlUtils.toMap(EntityUtils.toByteArray(response.getEntity()), "utf-8");
- res = XmlUtils.toXml(resultMap);
- log.info("请求结果:" + res);
- if (!SignUtils.checkParam(resultMap, key)) {
- res = "验证签名不通过";
- } else {
- if ("0".equals(resultMap.get("status")) && "0".equals(resultMap.get("result_code"))) {
- String pay_info = resultMap.get("pay_info");
- log.info("pay_info : " + pay_info);
- res = "ok";
-
- JSONObject resJson = JSONObject.parseObject(pay_info);
-
- payInfo.put("appId", resJson.getString("appId"));
- payInfo.put("timeStamp", resJson.getString("timeStamp"));
- payInfo.put("nonceStr", resJson.getString("nonceStr"));
- payInfo.put("package", resJson.getString("package"));
- payInfo.put("signType", "MD5");
- payInfo.put("paySign", resJson.getString("paySign"));
- }
- }
- } else {
- res = "操作失败";
- }
- } catch (Exception e) {
- log.error("操作失败,原因:",e);
- res = "系统异常";
- } finally {
- if (response != null) {
- try {
- response.close();
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- if (client != null) {
- try {
- client.close();
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- }
- Map<String,String> result = new HashMap<String,String>();
- if("ok".equals(res)){
- // result = payInfo;
- // return new SimpleJsonView(resultMap);
- result.put("status", "200");
- result.put("msg", res);
- result.put("pay_info", resultMap.get("pay_info"));
- }else{
- result.put("status", "500");
- result.put("msg", res);
- }*/
- Map<String,String> result = new HashMap<String,String>();
- String nonceStr = PaySign.getNonceStr();
- JsApiReqData jsApiReqData = new JsApiReqData(notify,"收款码收款_商品",nonceStr,outTradeNo,dised.multiply(diz).intValue(),spBillCreateIP, openid,Constants.appId,Constants.mch_id,Constants.apikey);
- String info = Message2XmlUtil.JsApiReqData2xml(jsApiReqData).replaceAll("mch__id", "mch_id").replaceAll("nonce__str", "nonce_str").replaceAll("notify__url", "notify_url").replaceAll("out__trade__no", "out_trade_no").replaceAll("spbill__create__ip", "spbill_create_ip").replaceAll("total__fee>", "total_fee>").replaceAll("trade__type", "trade_type");
- log.info("info========="+info);
- String prepay_id="err";
- StringBuffer sb = JsApiReqUtils.httpsRequest(Constants.unifiedorderurl, "POST", info);
- Map<String,Object> payInfo = new HashMap<String, Object>();
- if (!"".equals(sb.toString()))
- {
- try
- {
- //得到预支付ID,即prepay_id
- Map<String, String> getMap = Message2XmlUtil.parseXml(new String(sb.toString().getBytes(), "utf-8"));
- if(getMap.get("prepay_id")!=null)
- {
- //在return_code 和result_code都为SUCCESS的时候有返回
- prepay_id = getMap.get("prepay_id");
- log.info("订单:"+outTradeNo+",请求微信支付!");
- }
- else
- {
- log.info("获取预支付ID失败,返回参数为>>>>>>"+getMap);
- }
- }
- catch (UnsupportedEncodingException e)
- {
- log.info(Tools.getExceptionMessage(e));
- }
- Integer timeStramp = (int)(System.currentTimeMillis()/1000);
- JsApiToJsData jsApiToJsData = new JsApiToJsData(timeStramp,nonceStr,prepay_id,Constants.appId,Constants.apikey);
- payInfo.put("appId", jsApiToJsData.getAppid());
- payInfo.put("timeStamp", String.valueOf(jsApiToJsData.getTimeStamp()));
- payInfo.put("nonceStr", jsApiToJsData.getNonce_str());
- payInfo.put("package", "prepay_id="+jsApiToJsData.getPrepay_id());
- payInfo.put("signType", "MD5");
- payInfo.put("paySign", jsApiToJsData.getSign());
- log.info("支付信息:"+payInfo);
- result.put("status", "200");
- result.put("msg", "ok");
- result.put("pay_info", JSON.toJSONString(payInfo));
- }
- else
- {
- log.info("支付失败,支付参数初始化失败>>>{"+sb+"}");
- result.put("status", "500");
- result.put("msg", "支付失败,支付参数初始化失败>>>{"+sb+"}");
- }
-
-
-
- return new SimpleJsonView(result);
- }
-
- // @Path(value="/buyYiZFPdts.do")
- // public SimpleJsonView buyYiZFPdts(Context context)
- // {
- // Map<String,String> para = context.getParas();
- //
- // HttpSession session = context.getRequest().getSession();
- // String appuid = String.valueOf(session.getAttribute("appuid"));
- // String openid = (String) session.getAttribute("openid");
- //
- // String amount=para.get("amount"); //订单价格
- //
- // String outTradeNo = ""; //订单ID
- //
- //
- // Map<String, Object> pkgInfo = (Map<String, Object>) session.getAttribute("pkgInfo");
- // //amount = String.valueOf(pkgInfo.get("price"));
- // //amount=para.get("amount");
- // para.put("pkid", String.valueOf(pkgInfo.get("pkgid")));
- // para.put("appuid", appuid);
- // para.put("price", amount);
- // para.put("ts", String.valueOf(pkgInfo.get("ts")));
- //
- // /***********************下单,获取订单编号-BEGIN***********************/
- // log.info("套餐购买,下单>>>"+para);
- //
- // GzhUtil.toM3PaySign(para);
- // String resulta = GzhUtil.sendPost(Constants.m3IntAddr+"/package/buyPkg.do", para);
- // JSONObject resJsona = JSONObject.parseObject(resulta);
- // log.info("购买套餐获取订单编号返回:"+resulta);
- // if(resJsona.getIntValue("code") != 0){
- // return new SimpleJsonView(resJsona);
- // }
- // JSONObject dataJson = resJsona.getJSONObject("data");
- // outTradeNo = dataJson.getString("orderid");
- //
- //
- // String spBillCreateIP = JsApiReqUtils.getRealIp(context.getRequest());
- // Map<String,String> payInfo = new HashMap<String,String>();
- // String res = null;
- // try
- // {
- // //接口地址
- // String api = "/yeepay/pre_pay";
- // //具体接口的业务参数
- // Map<String, Object> businessData = new HashMap<String, Object>();
- // businessData.put("appId", Constants.appId);
- // businessData.put("scene", "ONLINE");
- // businessData.put("payWay", "WECHAT_OFFIACCOUNT");
- // businessData.put("orderAmount", amount);
- // businessData.put("channel", "WECHAT");
- // businessData.put("userIp", spBillCreateIP);
- // businessData.put("userId", openid);
- // businessData.put("goodsName", "1"+outTradeNo);
- //
- // String jsonData = JSON.toJSONString(businessData);
- // log.info(jsonData);
- // PrivateKey merchantPrivateKey = YiZF.getPrivateKey(YiZF.MERCHANT_PRIVATE_KEY);
- // PublicKey publicKey = YiZF.getPublicKey(YiZF.PUBLIC_KEY);
- // OpenParam requestParam = YiZF.buildOpenParam(jsonData, YiZF.BUSINESS_SUBJECT_ID, merchantPrivateKey, publicKey);
- //
- // //接口返回基本结构:code、message、data(OpenParam)
- // String responseJson = YiZF.doPost4String(YiZF.URL_HOST + api, JSON.toJSONString(requestParam),"Bearer "+YiZF.getToken5());
- // log.info("url="+YiZF.URL_HOST + api+",Authorization="+"Bearer"+YiZF.getToken5()+",json="+JSON.toJSONString(requestParam));
- // log.info("responseJson="+responseJson);
- // com.alibaba.fastjson2.JSONObject result = JSON.parseObject(responseJson);
- // OpenParam responseParam = JSON.parseObject(result.getString("data"), OpenParam.class);
- // String responseBusinessData = YiZF.verifyAndDecrypt(responseParam, YiZF.BUSINESS_SUBJECT_ID, merchantPrivateKey, publicKey);
- // log.info("responseBusinessData="+responseBusinessData);
- //
- //
- // JSONObject resJson = JSONObject.parseObject(responseBusinessData);
- // if(resJson.getString("code").equals("0000"))
- // {
- // res = "ok";
- // resJson = JSONObject.parseObject(resJson.getString("data"));
- // resJson = JSONObject.parseObject(resJson.getString("prePayTn"));
- // payInfo.put("appId", resJson.getString("appId"));
- // payInfo.put("timeStamp", resJson.getString("timeStamp"));
- // payInfo.put("nonceStr", resJson.getString("nonceStr"));
- // payInfo.put("package", resJson.getString("package"));
- // payInfo.put("signType", resJson.getString("signType"));
- // payInfo.put("paySign", resJson.getString("paySign"));
- // }
- // }
- // catch(Exception e)
- // {
- // Tools.getExceptionMessage(e);
- // }
- //
- // Map<String,String> result = new HashMap<String,String>();
- // if("ok".equals(res)){
- // result = payInfo;
- // }else{
- // result.put("status", "500");
- // result.put("msg", res);
- // }
- // return new SimpleJsonView(result);
- // }
-
- @Path(value="/buyMember.do")
- public SimpleJsonView buyMember(Context context)
- {
- Map<String,String> para = context.getParas();
-
- HttpSession session = context.getRequest().getSession();
- String appuid = String.valueOf(session.getAttribute("appuid"));
- String openid = (String) session.getAttribute("openid");
-
- String amount = ""; //订单价格
- String outTradeNo = ""; //订单ID
- String memid="";
-
- {
- amount=para.get("amount");
- memid=para.get("memid");
- para.put("appuid", appuid);
- para.put("price", amount);
- para.put("memid", memid);
-
- /***********************下单,获取订单编号-BEGIN***********************/
- log.info("套餐购买,下单>>>"+para);
-
- GzhUtil.toM3PaySign(para);
- String result = GzhUtil.sendPost(Constants.m3IntAddr+"/package/buyMember.do", para);
- log.info(result);
- JSONObject resJson = JSONObject.parseObject(result);
- log.info("购买套餐获取订单编号返回:"+result);
- if(resJson.getIntValue("code") != 0){
- return new SimpleJsonView(resJson);
- }
- JSONObject dataJson = resJson.getJSONObject("data");
- outTradeNo = dataJson.getString("orderid");
- }
-
- /***********************下单,获取订单编号-END***********************/
- //执行统一下单接口,初始化各参数
-
- String nonceStr = PaySign.getNonceStr();
- String spBillCreateIP = JsApiReqUtils.getRealIp(context.getRequest());
-
- //初始化传入参数
- BigDecimal dised = new BigDecimal(amount);
- // BigDecimal dised = new BigDecimal(0.01); //测试价格0.01,待修改为totalAmount zby
- BigDecimal diz = new BigDecimal(100);
-
- String body = "会员充值";
- String notify="/mifi/ylmembernotify.do";
- JsApiReqData jsApiReqData = new JsApiReqData(notify,body,nonceStr,outTradeNo,dised.multiply(diz).intValue(),spBillCreateIP, openid,Constants.appId,Constants.mch_id,Constants.apikey);
- String info = Message2XmlUtil.JsApiReqData2xml(jsApiReqData).replaceAll("mch__id", "mch_id").replaceAll("nonce__str", "nonce_str").replaceAll("notify__url", "notify_url").replaceAll("out__trade__no", "out_trade_no").replaceAll("spbill__create__ip", "spbill_create_ip").replaceAll("total__fee>", "total_fee>").replaceAll("trade__type", "trade_type");
- log.info("info========="+info);
- String prepay_id="err";
- StringBuffer sb = JsApiReqUtils.httpsRequest(Constants.unifiedorderurl, "POST", info);
- Map<String,Object> payInfo = new HashMap<String, Object>();
- if (!"".equals(sb.toString()))
- {
- try
- {
- //得到预支付ID,即prepay_id
- Map<String, String> getMap = Message2XmlUtil.parseXml(new String(sb.toString().getBytes(), "utf-8"));
- if(getMap.get("prepay_id")!=null)
- {
- //在return_code 和result_code都为SUCCESS的时候有返回
- prepay_id = getMap.get("prepay_id");
- log.info("订单:"+outTradeNo+",请求微信支付!");
- }
- else
- {
- log.info("获取预支付ID失败,返回参数为>>>>>>"+getMap);
- }
- }
- catch (UnsupportedEncodingException e)
- {
- log.info(Tools.getExceptionMessage(e));
- }
- Integer timeStramp = (int)(System.currentTimeMillis()/1000);
- JsApiToJsData jsApiToJsData = new JsApiToJsData(timeStramp,nonceStr,prepay_id,Constants.appId,Constants.apikey);
-
- payInfo.put("appId", jsApiToJsData.getAppid());
- payInfo.put("timeStamp", String.valueOf(jsApiToJsData.getTimeStamp()));
- payInfo.put("nonceStr", jsApiToJsData.getNonce_str());
- payInfo.put("package", "prepay_id="+jsApiToJsData.getPrepay_id());
- payInfo.put("signType", "MD5");
- payInfo.put("paySign", jsApiToJsData.getSign());
-
- log.info("支付信息:"+payInfo);
- }
- else
- {
- log.info("支付失败,支付参数初始化失败>>>{"+sb+"}");
- }
- return new SimpleJsonView(payInfo);
- }
-
- @Path(value="/buyYLMember.do")
- public SimpleJsonView buyYLMember(Context context)
- {
- Map<String,String> para = context.getParas();
-
- HttpSession session = context.getRequest().getSession();
- String appuid = String.valueOf(session.getAttribute("appuid"));
- String openid = (String) session.getAttribute("openid");
-
- String amount = ""; //订单价格
- String outTradeNo = ""; //订单ID
- String memid="";
-
- {
- amount=para.get("amount");
- memid=para.get("memid");
- para.put("appuid", appuid);
- para.put("price", amount);
- para.put("memid", memid);
-
- /***********************下单,获取订单编号-BEGIN***********************/
- log.info("套餐购买,下单>>>"+para);
-
- GzhUtil.toM3PaySign(para);
- String result = GzhUtil.sendPost(Constants.m3IntAddr+"/package/buyMember.do", para);
- log.info(result);
- JSONObject resJson = JSONObject.parseObject(result);
- log.info("购买套餐获取订单编号返回:"+result);
- if(resJson.getIntValue("code") != 0){
- return new SimpleJsonView(resJson);
- }
- JSONObject dataJson = resJson.getJSONObject("data");
- outTradeNo = dataJson.getString("orderid");
- }
-
-
- SortedMap<String, String> map = new TreeMap<String, String>();
-
- String spBillCreateIP = JsApiReqUtils.getRealIp(context.getRequest());
-
- //初始化传入参数
- BigDecimal dised = new BigDecimal(amount);
- // BigDecimal dised = new BigDecimal(0.01); //测试价格0.01,待修改为totalAmount zby
- BigDecimal diz = new BigDecimal(100);
-
-
- // String key = "432fc0caf293dde237e574fbf057f056";
- // String mch_id="QRA6072481C0003";
- // String notify="http://xcwx.sharemao.cn/mifi/ylmembernotify.do";
- String key = YL.key;
- String mch_id=YL.mch_id;
- String notify=YL.membernotify;
- map.put("body", "收款码收款_商品");
- map.put("charset", "UTF-8");
- map.put("is_raw", "1");
- map.put("mch_create_ip", spBillCreateIP);
- map.put("mch_id", mch_id);
- map.put("nonce_str", "str"+System.currentTimeMillis());
- map.put("notify_url", notify);
- map.put("out_trade_no", outTradeNo);
- map.put("service", "pay.weixin.jspay");
- map.put("sign_type", "MD5");
- map.put("sub_openid", openid);
- map.put("total_fee", String.valueOf(dised.multiply(diz).intValue()));
- map.put("version", "2.0");
- map.put("sign", sign(map,key));
- String reqUrl = "https://qra.95516.com/pay/gateway";
- log.info("reqUrl:" + reqUrl);
- log.info("reqParams:" + XmlUtils.parseXML(map));
- CloseableHttpResponse response = null;
- CloseableHttpClient client = null;
- String res = null;
- Map<String, String> resultMap = null;
- Map<String,String> payInfo = new HashMap<String,String>();
- try {
- HttpPost httpPost = new HttpPost(reqUrl);
- StringEntity entityParams = new StringEntity(XmlUtils.parseXML(map), "utf-8");
- httpPost.setEntity(entityParams);
- httpPost.setHeader("Content-Type", "text/xml;utf-8");
- client = HttpClients.createDefault();
- response = client.execute(httpPost);
- if (response != null && response.getEntity() != null) {
- resultMap = XmlUtils.toMap(EntityUtils.toByteArray(response.getEntity()), "utf-8");
- res = XmlUtils.toXml(resultMap);
- log.info("请求结果:" + res);
- if (!SignUtils.checkParam(resultMap, key)) {
- res = "验证签名不通过";
- } else {
- if ("0".equals(resultMap.get("status")) && "0".equals(resultMap.get("result_code"))) {
- String pay_info = resultMap.get("pay_info");
- log.info("pay_info : " + pay_info);
- res = "ok";
-
- JSONObject resJson = JSONObject.parseObject(pay_info);
-
- payInfo.put("appId", resJson.getString("appId"));
- payInfo.put("timeStamp", resJson.getString("timeStamp"));
- payInfo.put("nonceStr", resJson.getString("nonceStr"));
- payInfo.put("package", resJson.getString("package"));
- payInfo.put("signType", "MD5");
- payInfo.put("paySign", resJson.getString("paySign"));
- }
- }
- } else {
- res = "操作失败";
- }
- } catch (Exception e) {
- log.error("操作失败,原因:",e);
- res = "系统异常";
- } finally {
- if (response != null) {
- try {
- response.close();
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- if (client != null) {
- try {
- client.close();
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- }
- Map<String,String> result = new HashMap<String,String>();
- if("ok".equals(res)){
- result = payInfo;
- }else{
- result.put("status", "500");
- result.put("msg", res);
- }
- return new SimpleJsonView(result);
- }
-
- // @Path(value="/buyYiZFMember.do")
- // public SimpleJsonView buyYiZFMember(Context context)
- // {
- // Map<String,String> para = context.getParas();
- //
- // HttpSession session = context.getRequest().getSession();
- // String appuid = String.valueOf(session.getAttribute("appuid"));
- // String openid = (String) session.getAttribute("openid");
- //
- // String amount = ""; //订单价格
- // String outTradeNo = ""; //订单ID
- // String memid="";
- //
- // amount=para.get("amount");
- // memid=para.get("memid");
- // para.put("appuid", appuid);
- // para.put("price", amount);
- // para.put("memid", memid);
- //
- // /***********************下单,获取订单编号-BEGIN***********************/
- // log.info("套餐购买,下单>>>"+para);
- //
- // GzhUtil.toM3PaySign(para);
- // String resulta = GzhUtil.sendPost(Constants.m3IntAddr+"/package/buyMember.do", para);
- // log.info(resulta);
- // JSONObject resJsona = JSONObject.parseObject(resulta);
- // log.info("购买套餐获取订单编号返回:"+resulta);
- // if(resJsona.getIntValue("code") != 0){
- // return new SimpleJsonView(resJsona);
- // }
- // JSONObject dataJson = resJsona.getJSONObject("data");
- // outTradeNo = dataJson.getString("orderid");
- //
- // String spBillCreateIP = JsApiReqUtils.getRealIp(context.getRequest());
- // Map<String,String> payInfo = new HashMap<String,String>();
- // String res = null;
- // try
- // {
- // //接口地址
- // String api = "/yeepay/pre_pay";
- // //具体接口的业务参数
- // Map<String, Object> businessData = new HashMap<String, Object>();
- // businessData.put("appId", Constants.appId);
- // businessData.put("scene", "ONLINE");
- // businessData.put("payWay", "WECHAT_OFFIACCOUNT");
- // businessData.put("orderAmount", amount);
- // businessData.put("channel", "WECHAT");
- // businessData.put("userIp", spBillCreateIP);
- // businessData.put("userId", openid);
- // businessData.put("goodsName", "9"+outTradeNo);
- //
- // String jsonData = JSON.toJSONString(businessData);
- // log.info(jsonData);
- // PrivateKey merchantPrivateKey = YiZF.getPrivateKey(YiZF.MERCHANT_PRIVATE_KEY);
- // PublicKey publicKey = YiZF.getPublicKey(YiZF.PUBLIC_KEY);
- // OpenParam requestParam = YiZF.buildOpenParam(jsonData, YiZF.BUSINESS_SUBJECT_ID, merchantPrivateKey, publicKey);
- //
- // //接口返回基本结构:code、message、data(OpenParam)
- // String responseJson = YiZF.doPost4String(YiZF.URL_HOST + api, JSON.toJSONString(requestParam),"Bearer "+YiZF.getToken5());
- // log.info("url="+YiZF.URL_HOST + api+",Authorization="+"Bearer"+YiZF.getToken5()+",json="+JSON.toJSONString(requestParam));
- // log.info("responseJson="+responseJson);
- // com.alibaba.fastjson2.JSONObject result = JSON.parseObject(responseJson);
- // OpenParam responseParam = JSON.parseObject(result.getString("data"), OpenParam.class);
- // String responseBusinessData = YiZF.verifyAndDecrypt(responseParam, YiZF.BUSINESS_SUBJECT_ID, merchantPrivateKey, publicKey);
- // log.info("responseBusinessData="+responseBusinessData);
- //
- //
- // JSONObject resJson = JSONObject.parseObject(responseBusinessData);
- // if(resJson.getString("code").equals("0000"))
- // {
- // res = "ok";
- // resJson = JSONObject.parseObject(resJson.getString("data"));
- // resJson = JSONObject.parseObject(resJson.getString("prePayTn"));
- // payInfo.put("appId", resJson.getString("appId"));
- // payInfo.put("timeStamp", resJson.getString("timeStamp"));
- // payInfo.put("nonceStr", resJson.getString("nonceStr"));
- // payInfo.put("package", resJson.getString("package"));
- // payInfo.put("signType", resJson.getString("signType"));
- // payInfo.put("paySign", resJson.getString("paySign"));
- // }
- // }
- // catch(Exception e)
- // {
- // Tools.getExceptionMessage(e);
- // }
- //
- // Map<String,String> result = new HashMap<String,String>();
- // if("ok".equals(res)){
- // result = payInfo;
- // }else{
- // result.put("status", "500");
- // result.put("msg", res);
- // }
- // return new SimpleJsonView(result);
- // }
-
- @Path(value="/buyBalance.do")
- public SimpleJsonView buyBalance(Context context)
- {
- Map<String,String> para = context.getParas();
-
- HttpSession session = context.getRequest().getSession();
- String openid = (String) session.getAttribute("openid");
- para.put("openid", openid);
- Map<String, Object> pkgInfo = (Map<String, Object>) session.getAttribute("pkgInfo");
- para.put("packid", String.valueOf(pkgInfo.get("pkgid")));
-
- GzhUtil.toM3Sign(para);
- String result = GzhUtil.sendPost(Constants.m3IntAddr + "/payment/memPackRecharge.do", para);
- log.info(result);
- JSONObject resJson = JSONObject.parseObject(result);
- int resCode = resJson.getIntValue("code");
- if(resCode == 0)
- {
- return new SimpleJsonView("OK");
- }
- return new SimpleJsonView(resJson.getString("msg"));
- }
-
- @Path(value="/memPackRechargeToSpeedPack.do")
- public SimpleJsonView memPackRechargeToSpeedPack(Context context)
- {
- Map<String,String> para = context.getParas();
-
- HttpSession session = context.getRequest().getSession();
- String openid = (String) session.getAttribute("openid");
- para.put("openid", openid);
-
- GzhUtil.toM3Sign(para);
- String result = GzhUtil.sendPost(Constants.m3IntAddr + "/payment/memPackRechargeToSpeedPack.do", para);
- log.info(result);
- JSONObject resJson = JSONObject.parseObject(result);
- int resCode = resJson.getIntValue("code");
- if(resCode == 0)
- {
- return new SimpleJsonView("OK");
- }
- return new SimpleJsonView(resJson.getString("msg"));
- }
-
- public static String sign(SortedMap<String, String> parameters,String key){
- StringBuffer sb = new StringBuffer();
- Set es = parameters.entrySet();
- Iterator it = es.iterator();
- while (it.hasNext()) {
- Map.Entry entry = (Map.Entry)it.next();
- String k = (String)entry.getKey();
- String v = (String)entry.getValue();
- if (null != v && !"".equals(v)) {
- sb.append(k + "=" + parameters.get(k) + "&");
- }
- }
- sb.append("key="+key);
- System.out.println(sb.toString());
- try {
- byte[] bytes = sb.toString().getBytes("utf-8");
- return DigestUtils.md5Hex(bytes).toUpperCase();
- } catch (UnsupportedEncodingException e) {
- return "";
- }
- }
-
- @Path(value="/notify.do")
- public void notify(Context context)
- {
- Map<String,String> paramMap = Message2XmlUtil.xml2map(context.getRequest());
- log.info("微信公众号回调:{"+paramMap+"}");
- String result_code = paramMap.get("result_code").toString();
- // 进行业务处理
- if("SUCCESS".equals(result_code.toUpperCase()))
- {
- Map<String,String> para = new HashMap<String, String>();
- String orderid = paramMap.get("out_trade_no").toString();
- log.info("处理订单:orderno:"+orderid);
- para.put("orderid", orderid);
- GzhUtil.toM3Sign(para);
- String result = GzhUtil.sendPost(Constants.m3IntAddr+"/payment/gzhRecharge.do", para);
- log.info("下单购买后回调结果:"+result);
- }
- else
- {
- log.info("订单支付通知:签名错误");
- return;
- }
- }
-
- @Path(value="/ylnotify.do")
- public void ylnotify(Context context)
- {
- Map<String,String> paramMap = Message2XmlUtil.xml2map(context.getRequest());
- log.info("微信公众号回调:{"+paramMap+"}");
- String result_code = paramMap.get("result_code").toString();
- // 进行业务处理
- if("0".equals(result_code) || "SUCCESS".equalsIgnoreCase(result_code))
- {
- Map<String,String> para = new HashMap<String, String>();
- String orderid = paramMap.get("out_trade_no").toString();
- String transactionId = paramMap.get("transaction_id").toString();
- log.info("处理订单:orderno:"+orderid);
- para.put("orderid", orderid);
- para.put("transaction_id", transactionId);
- GzhUtil.toM3Sign(para);
- String result = GzhUtil.sendPost(Constants.m3IntAddr+"/payment/gzhRecharge.do", para);
- log.info("下单购买后回调结果:"+result);
- try {
- context.getResponse().getWriter().write("success");
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- else
- {
- log.info("订单支付通知:签名错误");
- return;
- }
- }
-
- @Path(value="/ylmembernotify.do")
- public void ylmembernotify(Context context)
- {
- Map<String,String> paramMap = Message2XmlUtil.xml2map(context.getRequest());
- log.info("微信公众号回调:{"+paramMap+"}");
- String result_code = paramMap.get("result_code").toString();
- // 进行业务处理
- if("0".equals(result_code) || "SUCCESS".equals(result_code.toUpperCase()))
- {
- Map<String,String> para = new HashMap<String, String>();
- String orderid = paramMap.get("out_trade_no").toString();
- String transactionId = paramMap.get("transaction_id").toString();
- log.info("处理订单:orderno:"+orderid);
- para.put("orderid", orderid);
- para.put("transaction_id", transactionId);
- GzhUtil.toM3Sign(para);
- String result = GzhUtil.sendPost(Constants.m3IntAddr+"/payment/memRecharge.do", para);
- log.info("下单购买后回调结果:"+result);
- try {
- context.getResponse().getWriter().write("success");
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- else
- {
- log.info("订单支付通知:签名错误");
- return;
- }
- }
-
- @Path(value="/ylmemberspeedpacknotify.do")
- public void ylmemberspeedpacknotify(Context context)
- {
- Map<String,String> paramMap = Message2XmlUtil.xml2map(context.getRequest());
- log.info("微信公众号回调:{"+paramMap+"}");
- String result_code = paramMap.get("result_code").toString();
- // 进行业务处理
- if("0".equals(result_code) || "SUCCESS".equals(result_code.toUpperCase()))
- {
- Map<String,String> para = new HashMap<String, String>();
- String orderid = paramMap.get("out_trade_no").toString();
- String transactionId = paramMap.get("transaction_id").toString();
- log.info("处理加速包购买订单:orderno:"+orderid);
- para.put("orderid", orderid);
- para.put("transaction_id", transactionId);
- GzhUtil.toM3Sign(para);
- String result = GzhUtil.sendPost(Constants.m3IntAddr+"/payment/speedPackRecharge.do", para);
- log.info("加速包购买后回调结果:"+result);
- try {
- context.getResponse().getWriter().write("success");
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- else
- {
- log.info("订单支付通知:签名错误");
- return;
- }
- }
-
- @Path("/getMember2.do")
- public TextView getMember(Context context)
- {
- Map<String, String> para = context.getParas();
- GzhUtil.toM3Sign(para);
- String result = GzhUtil.sendPost(Constants.m3IntAddr + "/packkey/getMember.do", para);
- if(!Tools.isEmpty(result))
- {
- JSONObject resJson = JSONObject.parseObject(result);
- JSONArray dataJson = resJson.getJSONArray("data");
- context.getRequest().setAttribute("cons", dataJson);
- }
- String devid =GzhUtil.getDevID(context.getRequest().getSession(), para);
- context.getRequest().setAttribute("devid", devid);
- HttpSession session = context.getRequest().getSession();
- String phonenum = (String) session.getAttribute("phonenum");
- context.getRequest().setAttribute("phonenum", phonenum);
- String openid = (String) session.getAttribute("openid");
- para.put("openid", openid);
- GzhUtil.toM3Sign(para);
- result = GzhUtil.sendPost(Constants.m3IntAddr + "/user/getBalance.do", para);
- JSONObject resJson = JSONObject.parseObject(result);
- int resCode = resJson.getIntValue("code");
- if(resCode == 0)
- {
- JSONObject dataJson = resJson.getJSONObject("data");
- String balance=dataJson.getString("balance");
- String jine=dataJson.getString("jine");
- String zsong=dataJson.getString("zsong");
- context.getRequest().setAttribute("balance", balance);
- context.getRequest().setAttribute("jine", jine);
- context.getRequest().setAttribute("zsong", zsong);
- } else
- {
- context.getRequest().setAttribute("balance", "0.00");
- context.getRequest().setAttribute("jine", "0.00");
- context.getRequest().setAttribute("zsong", "0.00");
- }
- result = GzhUtil.sendPost(Constants.m3IntAddr + "/package/getSPkgs.do", para);
- if(!Tools.isEmpty(result))
- {
- resJson = JSONObject.parseObject(result);
- JSONArray dataJson = resJson.getJSONArray("data");
- log.info(dataJson);
- context.getRequest().setAttribute("spkgs", dataJson);
- }
- return new TextView("/membersyb.jsp");
- // return new TextView("/member.jsp");
- }
-
- @Path("/benefit.do")
- public TextView benefit(Context context)
- {
- Map<String, String> para = context.getParas();
- GzhUtil.toM3Sign(para);
- String result = GzhUtil.sendPost(Constants.m3IntAddr + "/packkey/getMember.do", para);
- if(!Tools.isEmpty(result))
- {
- JSONObject resJson = JSONObject.parseObject(result);
- JSONArray dataJson = resJson.getJSONArray("data");
- context.getRequest().setAttribute("cons", dataJson);
- }
- String devid =GzhUtil.getDevID(context.getRequest().getSession(), para);
- context.getRequest().setAttribute("devid", devid);
- HttpSession session = context.getRequest().getSession();
- String phonenum = (String) session.getAttribute("phonenum");
- context.getRequest().setAttribute("phonenum", phonenum);
- String openid = (String) session.getAttribute("openid");
- para.put("openid", openid);
- GzhUtil.toM3Sign(para);
- result = GzhUtil.sendPost(Constants.m3IntAddr + "/user/getBalance.do", para);
- JSONObject resJson = JSONObject.parseObject(result);
- int resCode = resJson.getIntValue("code");
- if(resCode == 0)
- {
- JSONObject dataJson = resJson.getJSONObject("data");
- context.getRequest().setAttribute("balance", dataJson.getString("balance"));
- context.getRequest().setAttribute("jine", dataJson.getString("jine"));
- context.getRequest().setAttribute("zsong", dataJson.getString("zsong"));
- } else
- {
- context.getRequest().setAttribute("balance", "0.00");
- context.getRequest().setAttribute("jine", "0.00");
- context.getRequest().setAttribute("zsong", "0.00");
- }
- result = GzhUtil.sendPost(Constants.m3IntAddr + "/package/getSPkgs.do", para);
- if(!Tools.isEmpty(result))
- {
- resJson = JSONObject.parseObject(result);
- JSONArray dataJson = resJson.getJSONArray("data");
- log.info(dataJson);
- context.getRequest().setAttribute("spkgs", dataJson);
- }
- return new TextView("/benefit.jsp");
- }
-
- @Path("/benefitSubmit.do")
- public TextView benefitSubmit(Context context)
- {
- Map<String, String> para = context.getParas();
- HttpSession session = context.getRequest().getSession();
- String openid = (String) session.getAttribute("openid");
- para.put("openid", openid);
- GzhUtil.toM3Sign(para);
- String result = GzhUtil.sendPost(Constants.m3IntAddr + "/user/getBalance.do", para);
- JSONObject resJson = JSONObject.parseObject(result);
- int resCode = resJson.getIntValue("code");
- if(resCode == 0)
- {
- JSONObject dataJson = resJson.getJSONObject("data");
- context.getRequest().setAttribute("balance", dataJson.getString("balance"));
- } else
- {
- context.getRequest().setAttribute("balance", "0.00");
- }
- para.forEach((k,v)->context.getRequest().setAttribute(k, v));
- return new TextView("/benefitSubmitSyb.jsp");
- // return new TextView("/benefitSubmit.jsp");
- }
- @Path(value="/submitorder.do")
- public SimpleJsonView submitorder(Context context) throws Exception {
- Map<String,String> para = context.getParas();
- HttpSession session = context.getRequest().getSession();
- String appuid = String.valueOf(session.getAttribute("appuid"));
- String openid = (String) session.getAttribute("openid");
- if(GzhUtil.isEmpty(appuid))
- {
- Map<String,String> result = new HashMap<String,String>();
- result.put("status", "403");
- result.put("msg", "请登录");
- return new SimpleJsonView(result);
- }
- String amount=para.get("amount"); //订单价格
- double af=Double.parseDouble(amount);
- //低于1元不能充值
- if(af<1)
- {
- Map<String,String> result = new HashMap<String,String>();
- result.put("status", "500");
- result.put("msg", "出错了");
- return new SimpleJsonView(result);
- }
- String outTradeNo = ""; //订单ID
- String notify=SybConstants.NOTFIY_PKG_URL;
- int type = Integer.parseInt(para.get("type"));
- log.info("type="+type);
- if(type == 0)
- {
- Map<String, Object> pdtInfo = (Map<String, Object>) session.getAttribute("pdtInfo");
- //amount = String.valueOf(pdtInfo.get("total"));
- //amount=para.get("amount");
- para.put("pdtid", String.valueOf(pdtInfo.get("pdtid")));
- para.put("appuid", appuid);
- para.put("num", String.valueOf(pdtInfo.get("num")));
- para.put("price", amount);
- /***********************下单,获取订单编号-BEGIN***********************/
- log.info("设备购买,下单>>>"+para);
- GzhUtil.toM3PaySign(para);
- String result = GzhUtil.sendPost(Constants.m3IntAddr+"/device/buyPdts.do", para);
- JSONObject resJson = JSONObject.parseObject(result);
- log.info("购买设备获取订单编号返回:"+result);
- if(resJson.getIntValue("code") != 0){
- return new SimpleJsonView(resJson.getString("msg"));
- }
- JSONObject dataJson = resJson.getJSONObject("data");
- outTradeNo = dataJson.getString("orderid");
- }
- else if(type == 1)
- {
- Map<String, Object> pkgInfo = (Map<String, Object>) session.getAttribute("pkgInfo");
- //amount = String.valueOf(pkgInfo.get("price"));
- //amount=para.get("amount");
- para.put("pkid", String.valueOf(pkgInfo.get("pkgid")));
- para.put("appuid", appuid);
- para.put("price", amount);
- para.put("ts", String.valueOf(pkgInfo.get("ts")));
- /***********************下单,获取订单编号-BEGIN***********************/
- log.info("套餐购买,下单>>>"+para);
- GzhUtil.toM3PaySign(para);
- String result = GzhUtil.sendPost(Constants.m3IntAddr+"/package/buyPkg.do", para);
- JSONObject resJson = JSONObject.parseObject(result);
- log.info("购买套餐获取订单编号返回:"+result);
- if(resJson.getIntValue("code") != 0){
- return new SimpleJsonView(resJson);
- }
- JSONObject dataJson = resJson.getJSONObject("data");
- outTradeNo = dataJson.getString("orderid");
- }
- else if(type == 2)
- {
- amount=para.get("amount");
- para.put("appuid", appuid);
- para.put("price", amount);
- //TODO pkgid pkgprice
- para.put("openid", openid);
- String pkgprice=para.get("pkgprice");
- para.put("pkgprice", pkgprice);
- /***********************下单,获取订单编号-BEGIN***********************/
- log.info("钱包充值,下单>>>"+para);
- GzhUtil.toM3PaySign(para);
- String result = GzhUtil.sendPost(Constants.m3IntAddr+"/package/buyMember.do", para);
- log.info(result);
- JSONObject resJson = JSONObject.parseObject(result);
- log.info("钱包充值获取订单编号返回:"+result);
- if(resJson.getIntValue("code") != 0){
- return new SimpleJsonView(resJson);
- }
- JSONObject dataJson = resJson.getJSONObject("data");
- outTradeNo = dataJson.getString("orderid");
- notify = SybConstants.NOTFIY_MEMBER_URL;
- }
- else if(type == 3)
- {
- amount=para.get("amount");
- para.put("appuid", appuid);
- para.put("price", amount);
- /***********************下单,获取订单编号-BEGIN***********************/
- log.info("加速包购买,下单>>>"+para);
- GzhUtil.toM3PaySign(para);
- String result = GzhUtil.sendPost(Constants.m3IntAddr+"/package/buySpeedPack.do", para);
- log.info(result);
- JSONObject resJson = JSONObject.parseObject(result);
- log.info("购买加速包获取订单编号返回:"+result);
- if(resJson.getIntValue("code") != 0){
- return new SimpleJsonView(resJson);
- }
- JSONObject dataJson = resJson.getJSONObject("data");
- outTradeNo = dataJson.getString("orderid");
- notify = SybConstants.NOTFIY_SPEEDPACK_URL;
- }
- Map<String, String> result = new HashMap<String, String>();
- result.put("status", "200");
- result.put("amount", "amount");
- result.put("notify", notify);
- result.put("outTradeNo", outTradeNo);
- return new SimpleJsonView(result);
- }
- /**
- * test 用于养号,方便充值
- */
- @Path(value="/testsyb.do")
- public TextView testsyb(Context context) throws Exception {
- Map<String,String> para = context.getParas();
- String appid = SybConstants.SYB_APPID;
- String cusid = SybConstants.SYB_CUSID;
- String version = SybConstants.VERSION;
- String charset = "utf-8";
- BigDecimal dised = new BigDecimal(String.valueOf(para.get("amt")));
- BigDecimal diz = new BigDecimal(100);
- String trxamt=dised.multiply( diz).toString();
- String reqsn = System.currentTimeMillis()+"";
- String returl = SybConstants.RET_URL;
- String notify_url = SybConstants.NOTFIY_URL;
- String body ="收款码收款_商品";
- String remark ="收款码收款_商品";
- String randomstr = String.valueOf(System.currentTimeMillis()) ;
- String validtime = String.valueOf( SybConstants.VALID_TIME);
- String signtype = SybConstants.SIGN_TYPE;
- String appkey = SybConstants.SYB_RSACUSPRIKEY;
- TreeMap<String,String> params = new TreeMap<String,String>();
- params.put("appid", appid);
- params.put("cusid", cusid);
- params.put("version", version);
- params.put("charset", charset);
- params.put("trxamt", trxamt);
- params.put("reqsn", reqsn);
- params.put("randomstr", randomstr);
- params.put("body", body);
- params.put("validtime", validtime);
- params.put("remark", remark);
- params.put("returl", returl);
- params.put("notify_url", notify_url);
- params.put("signtype",signtype);
- log.info("=================通联充值:"+params);
- String sign = SybUtil.unionSign(params,appkey,SybConstants.SIGN_TYPE);
- context.getRequest().setAttribute("appid", appid);
- context.getRequest().setAttribute("cusid", cusid);
- context.getRequest().setAttribute("version", version);
- context.getRequest().setAttribute("charset", charset);
- context.getRequest().setAttribute("trxamt", trxamt);
- context.getRequest().setAttribute("reqsn", reqsn);
- context.getRequest().setAttribute("randomstr", randomstr);
- context.getRequest().setAttribute("body", body);
- context.getRequest().setAttribute("validtime", validtime);
- context.getRequest().setAttribute("remark", remark);
- context.getRequest().setAttribute("returl", returl);
- context.getRequest().setAttribute("notify_url", notify_url);
- context.getRequest().setAttribute("signtype", signtype);
- context.getRequest().setAttribute("sign", sign);
- return new TextView("/sybpay.jsp");
- }
- @Path(value="/testwx.do")
- public TextView testwx(Context context) throws Exception {
- String wxCode = context.getParas().get("code");
- Map<String, String> m = GzhUtil.getOpenId(wxCode, Constants.appId, Constants.appSecret);
- String openid = m.get("openId");
- context.getRequest().getSession().setAttribute("openid", openid);
- context.getRequest().setAttribute("u", "/mifi/testwxpay.do");
- return new TextView("/testwx.jsp");
- }
- @Path(value = "/testwxpay.do")
- public SimpleJsonView testwxpay(Context context) throws Exception {
- Map<String, String> result = new HashMap<String, String>();
- String nonceStr = PaySign.getNonceStr();
- String trxamt = String.valueOf(context.getParas().get("amt"));
- BigDecimal dised = new BigDecimal(trxamt);
- BigDecimal diz = new BigDecimal(100);
- String outTradeNo = System.currentTimeMillis() + "";
- String spBillCreateIP = JsApiReqUtils.getRealIp(context.getRequest());
- String openid = context.getRequest().getSession().getAttribute("openid").toString();
- JsApiReqData jsApiReqData = new JsApiReqData("收款码收款_商品", nonceStr, outTradeNo, dised.multiply( diz).intValue(), spBillCreateIP, openid, Constants.appId, Constants.mch_id, Constants.apikey);
- String info = Message2XmlUtil.JsApiReqData2xml(jsApiReqData).replaceAll("mch__id", "mch_id").replaceAll("nonce__str", "nonce_str").replaceAll("notify__url", "notify_url").replaceAll("out__trade__no", "out_trade_no").replaceAll("spbill__create__ip", "spbill_create_ip").replaceAll("total__fee>", "total_fee>").replaceAll("trade__type", "trade_type");
- log.info("微信支付充值=========" + info);
- String prepay_id = "err";
- StringBuffer sb = JsApiReqUtils.httpsRequest(Constants.unifiedorderurl, "POST", info);
- Map<String, Object> payInfo = new HashMap<String, Object>();
- if (!"".equals(sb.toString())) {
- try {
- //得到预支付ID,即prepay_id
- Map<String, String> getMap = Message2XmlUtil.parseXml(new String(sb.toString().getBytes(), "utf-8"));
- if (getMap.get("prepay_id") != null) {
- //在return_code 和result_code都为SUCCESS的时候有返回
- prepay_id = getMap.get("prepay_id");
- log.info("订单:" + outTradeNo + ",请求微信支付!");
- } else {
- log.info("获取预支付ID失败,返回参数为>>>>>>" + getMap);
- }
- } catch (UnsupportedEncodingException e) {
- log.info(Tools.getExceptionMessage(e));
- }
- Integer timeStramp = (int) (System.currentTimeMillis() / 1000);
- JsApiToJsData jsApiToJsData = new JsApiToJsData(timeStramp, nonceStr, prepay_id, Constants.appId, Constants.apikey);
- payInfo.put("appId", jsApiToJsData.getAppid());
- payInfo.put("timeStamp", String.valueOf(jsApiToJsData.getTimeStamp()));
- payInfo.put("nonceStr", jsApiToJsData.getNonce_str());
- payInfo.put("package", "prepay_id=" + jsApiToJsData.getPrepay_id());
- payInfo.put("signType", "MD5");
- payInfo.put("paySign", jsApiToJsData.getSign());
- log.info("支付信息:" + payInfo);
- result.put("status", "200");
- result.put("msg", "ok");
- result.put("pay_info", JSON.toJSONString(payInfo));
- } else {
- log.info("支付失败,支付参数初始化失败>>>{" + sb + "}");
- result.put("status", "500");
- result.put("msg", "支付失败,支付参数初始化失败>>>{" + sb + "}");
- }
- return new SimpleJsonView(result);
- }
- /**
- * 通联收款
- */
- @Path(value="/tosybpay.do")
- public TextView tosybpay(Context context) throws Exception {
- Map<String,String> para = context.getParas();
- HttpSession session = context.getRequest().getSession();
- String appuid = String.valueOf(session.getAttribute("appuid"));
- String amount=para.get("amount"); //订单价格
- String outTradeNo=para.get("outTradeNo"); //订单价格
- String notify=para.get("notify"); //订单价格
- //初始化传入参数
- BigDecimal dised = new BigDecimal(amount);
- // BigDecimal dised = new BigDecimal(0.01); //测试价格0.01,待修改为totalAmount zby
- BigDecimal diz = new BigDecimal(100);
- if("151992".equals(appuid)) {
- dised = new BigDecimal(0.01);
- }
- // String result = GzhUtil.sendPost(Constants.m3IntAddr+"/payment/getPayType.do", para);
- // log.info(result);
- // JSONObject resJson = JSONObject.parseObject(result);
- // log.info("钱包充值获取订单编号返回:"+result);
- String appid = SybConstants.SYB_APPID;
- String cusid = SybConstants.SYB_CUSID;
- String version = SybConstants.VERSION;
- String charset = "utf-8";
- String trxamt=String.valueOf(dised.multiply(diz).intValue());
- String reqsn = outTradeNo;
- String returl = SybConstants.RET_URL;
- String notify_url = notify;
- String body ="收款码收款_商品";
- String remark ="收款码收款_商品";
- String randomstr = String.valueOf(System.currentTimeMillis()) ;
- String validtime = String.valueOf( SybConstants.VALID_TIME);
- String signtype = SybConstants.SIGN_TYPE;
- String appkey = SybConstants.SYB_RSACUSPRIKEY;
- // if(resJson.getIntValue("code") == 0){
- // JSONObject dataJson = resJson.getJSONObject("data");
- // appid = dataJson.getString("appid");
- // cusid = dataJson.getString("mchid");
- // appkey = dataJson.getString("prikey");
- // }
- TreeMap<String,String> params = new TreeMap<String,String>();
- params.put("appid", appid);
- params.put("cusid", cusid);
- params.put("version", version);
- params.put("charset", charset);
- params.put("trxamt", trxamt);
- params.put("reqsn", reqsn);
- params.put("randomstr", randomstr);
- params.put("body", body);
- params.put("validtime", validtime);
- params.put("remark", remark);
- params.put("returl", returl);
- params.put("notify_url", notify_url);
- params.put("signtype",signtype);
- log.info("=================签名参数:"+params);
- String sign = SybUtil.unionSign(params,appkey,SybConstants.SIGN_TYPE);
- context.getRequest().setAttribute("appid", appid);
- context.getRequest().setAttribute("cusid", cusid);
- context.getRequest().setAttribute("version", version);
- context.getRequest().setAttribute("charset", charset);
- context.getRequest().setAttribute("trxamt", trxamt);
- context.getRequest().setAttribute("reqsn", reqsn);
- context.getRequest().setAttribute("randomstr", randomstr);
- context.getRequest().setAttribute("body", body);
- context.getRequest().setAttribute("validtime", validtime);
- context.getRequest().setAttribute("remark", remark);
- context.getRequest().setAttribute("returl", returl);
- context.getRequest().setAttribute("notify_url", notify_url);
- context.getRequest().setAttribute("signtype", signtype);
- context.getRequest().setAttribute("sign", sign);
- return new TextView("/sybpay.jsp");
- }
- @Path(value="/sybpkgnotify.do")
- public void sybpkgnotify(Context context) throws Exception {
- log.info("充值套餐支付接收到通知");
- Map<String, String[]> paramMap = context.getRequest().getParameterMap();
- paramMap.forEach((key, value) -> log.info(key + ":" + value[0]));
- // 进行业务处理
- if(paramMap.get("outtrxid").length>0)
- {
- Map<String,String> para = new HashMap<String, String>();
- String orderid = paramMap.get("outtrxid")[0];
- // String transactionId = paramMap.get("transaction_id").toString();
- log.info("处理订单:orderno:"+orderid);
- para.put("orderid", orderid);
- para.put("transaction_id", "");
- // para.put("transaction_id", transactionId);
- GzhUtil.toM3Sign(para);
- String result = GzhUtil.sendPost(Constants.m3IntAddr+"/payment/gzhRecharge.do", para);
- log.info("下单购买后回调结果:"+result);
- try {
- context.getResponse().getWriter().write("success");
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- else
- {
- log.info("订单支付通知:签名错误");
- return;
- }
- }
- @Path(value="/sybmembernotify.do")
- public void sybmembernotify(Context context)
- {
- log.info("充值钱包支付接收到通知");
- Map<String, String[]> paramMap = context.getRequest().getParameterMap();
- paramMap.forEach((key, value) -> log.info(key + ":" + value[0]));
- // 进行业务处理
- if(paramMap.get("outtrxid").length>0)
- {
- Map<String,String> para = new HashMap<String, String>();
- String orderid = paramMap.get("outtrxid")[0];
- log.info("处理订单:orderno:"+orderid);
- para.put("orderid", orderid);
- para.put("transaction_id", "");
- GzhUtil.toM3Sign(para);
- String result = GzhUtil.sendPost(Constants.m3IntAddr+"/payment/memRecharge.do", para);
- log.info("下单购买后回调结果:"+result);
- try {
- context.getResponse().getWriter().write("success");
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- else
- {
- log.info("订单支付通知:签名错误");
- return;
- }
- }
- @Path(value="/sybspeedpacknotify.do")
- public void sybspeedpacknotify(Context context)
- {
- log.info("充值钱包支付接收到通知");
- Map<String, String[]> paramMap = context.getRequest().getParameterMap();
- paramMap.forEach((key, value) -> log.info(key + ":" + value[0]));
- // 进行业务处理
- if(paramMap.get("outtrxid").length>0)
- {
- Map<String,String> para = new HashMap<String, String>();
- String orderid = paramMap.get("outtrxid")[0];
- log.info("处理加速包购买订单:orderno:"+orderid);
- para.put("orderid", orderid);
- para.put("transaction_id", "");
- GzhUtil.toM3Sign(para);
- String result = GzhUtil.sendPost(Constants.m3IntAddr+"/payment/speedPackRecharge.do", para);
- log.info("加速包购买后回调结果:"+result);
- try {
- context.getResponse().getWriter().write("success");
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- else
- {
- log.info("订单支付通知:签名错误");
- return;
- }
- }
- }
|