No Description

PayCtrl.java 78KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039
  1. package com.sharemao.web.wx.ctrl;
  2. import java.io.IOException;
  3. import java.io.UnsupportedEncodingException;
  4. import java.math.BigDecimal;
  5. import java.math.RoundingMode;
  6. import java.security.PrivateKey;
  7. import java.security.PublicKey;
  8. import java.util.HashMap;
  9. import java.util.Iterator;
  10. import java.util.Map;
  11. import java.util.Set;
  12. import java.util.SortedMap;
  13. import java.util.TreeMap;
  14. import javax.servlet.http.HttpSession;
  15. import com.sharemao.web.wx.syb.SybConstants;
  16. import com.sharemao.web.wx.syb.SybUtil;
  17. import org.apache.commons.codec.digest.DigestUtils;
  18. import org.apache.commons.logging.Log;
  19. import org.apache.commons.logging.LogFactory;
  20. import org.apache.http.client.methods.CloseableHttpResponse;
  21. import org.apache.http.client.methods.HttpPost;
  22. import org.apache.http.entity.StringEntity;
  23. import org.apache.http.impl.client.CloseableHttpClient;
  24. import org.apache.http.impl.client.HttpClients;
  25. import org.apache.http.util.EntityUtils;
  26. import org.apache.http.util.TextUtils;
  27. import com.alibaba.fastjson.JSONArray;
  28. import com.alibaba.fastjson.JSONObject;
  29. import com.alibaba.fastjson2.JSON;
  30. import com.nianzai.base.mvc.Context;
  31. import com.nianzai.base.mvc.annotation.Controller;
  32. import com.nianzai.base.mvc.annotation.Path;
  33. import com.nianzai.base.mvc.view.SimpleJsonView;
  34. import com.nianzai.base.mvc.view.TextView;
  35. import com.nianzai.util.CodecUtil;
  36. import com.nianzai.util.Tools;
  37. import com.sharemao.web.wx.Constants;
  38. import com.sharemao.web.wx.JsApiReqData;
  39. import com.sharemao.web.wx.JsApiToJsData;
  40. import com.sharemao.web.wx.util.GzhUtil;
  41. import com.sharemao.web.wx.util.JsApiReqUtils;
  42. import com.sharemao.web.wx.util.Message2XmlUtil;
  43. import com.sharemao.web.wx.util.PaySign;
  44. import com.sharemao.web.wx.util.SignUtils;
  45. import com.sharemao.web.wx.util.XmlUtils;
  46. import com.sharemao.web.wx.util.YL;
  47. @Controller("/mifi")
  48. public class PayCtrl
  49. {
  50. private static final Log log = LogFactory.getLog(PayCtrl.class);
  51. /**
  52. * 跳转至商品下单界面
  53. * @param context
  54. * @return
  55. */
  56. @Path(value="/pdtOrder.do")
  57. public TextView pdtOrder(Context context)
  58. {
  59. HttpSession session = context.getRequest().getSession();
  60. Map<String, String> para = context.getParas();
  61. String appuid = String.valueOf(session.getAttribute("appuid"));
  62. if(GzhUtil.isEmpty(appuid))
  63. return new TextView(Constants.loginUrl);
  64. para.put("appuid", appuid);
  65. String addressId = para.get("addressId");
  66. GzhUtil.toM3Sign(para);
  67. // 获取默认收货地址
  68. String result = GzhUtil.sendPost(Constants.m3IntAddr + "/user/getAddr.do", para);
  69. JSONObject resJson = JSONObject.parseObject(result);
  70. JSONObject dataJson = resJson.getJSONObject("data");
  71. JSONArray addrJson = dataJson.getJSONArray("addr");
  72. JSONObject address = new JSONObject();
  73. if(addrJson.size() > 0)
  74. {
  75. if(!GzhUtil.isEmpty(addressId))
  76. {
  77. for(int i=0; i<addrJson.size(); i++)
  78. {
  79. JSONObject addr = addrJson.getJSONObject(i);
  80. if(addressId.equals(addr.getString("addressId")))
  81. {
  82. address = addr;
  83. break;
  84. }
  85. }
  86. }
  87. else
  88. {
  89. for(int i=0; i<addrJson.size(); i++)
  90. {
  91. JSONObject addr = addrJson.getJSONObject(i);
  92. if(addr.getIntValue("isdefault") == 0)
  93. {
  94. address = addr;
  95. break;
  96. }
  97. }
  98. }
  99. String detail = address.getString("detailAddr");
  100. if(detail.length() > 25)
  101. {
  102. detail = detail.substring(0, 25)+"...";
  103. address.put("address", detail);
  104. }
  105. else
  106. address.put("address", detail);
  107. context.getRequest().setAttribute("addr", address);
  108. }
  109. @SuppressWarnings("unchecked")
  110. Map<String, Object> pdtInfo = (Map<String, Object>) session.getAttribute("pdtInfo");
  111. context.getRequest().setAttribute("pdtInfo", pdtInfo);
  112. return new TextView("/order/pdtorder.jsp");
  113. }
  114. /**
  115. * 跳转至套餐购买下单界面
  116. * @param context
  117. * @return
  118. */
  119. @Path(value="/settlement.do")
  120. public TextView settlement(Context context)
  121. {
  122. HttpSession session = context.getRequest().getSession();
  123. Map<String, String> para = context.getParas();
  124. log.info("para==>"+para);
  125. String devid = para.get("devid");
  126. String pkgid = para.get("pkgid");
  127. String price0 = para.get("price");
  128. String sign = para.get("sign");
  129. String appuid = String.valueOf(session.getAttribute("appuid"));
  130. String openid = (String) session.getAttribute("openid");
  131. String wxCode = para.get("code");
  132. String opt = para.get("opt");
  133. if(GzhUtil.isEmpty(devid))
  134. {
  135. return new TextView("/user/index.do");
  136. }
  137. if(GzhUtil.isEmpty(appuid) || GzhUtil.isEmpty(openid))
  138. {
  139. if(!GzhUtil.isEmpty(wxCode))
  140. {
  141. Map<String,String> m=GzhUtil.getOpenId(wxCode,Constants.appId,Constants.appSecret);
  142. openid=m.get("openId");
  143. String accessToken=m.get("accessToken");
  144. session.setAttribute("openid", openid);
  145. session.setAttribute("accessToken", accessToken);
  146. log.info("wxCode="+wxCode+",openid="+openid);
  147. para.put("openid", openid);
  148. GzhUtil.toM3Sign(para);
  149. String u=Constants.m3IntAddr + "/user/wxIndex.do";
  150. String result = GzhUtil.sendPost(u, para);
  151. log.info("url="+u+",result="+result);
  152. JSONObject resJson = JSONObject.parseObject(result);
  153. int resCode = resJson.getIntValue("code");
  154. if(resCode == 0)
  155. {
  156. JSONObject dataJson = resJson.getJSONObject("data");
  157. if(dataJson!=null) {
  158. appuid=dataJson.getString("appuid");
  159. }
  160. session.setAttribute("appuid", appuid);
  161. session.setAttribute("openid", openid);
  162. }
  163. }
  164. if(GzhUtil.isEmpty(appuid) || GzhUtil.isEmpty(openid))
  165. {
  166. para.put("devid", devid);
  167. GzhUtil.toM3Sign(para);
  168. String result = GzhUtil.sendPost(Constants.m3IntAddr + "/user/getInfoByDevid.do", para);
  169. JSONObject resJson = JSONObject.parseObject(result);
  170. int resCode = resJson.getIntValue("code");
  171. if(resCode == 0)
  172. {
  173. JSONObject dataJson = resJson.getJSONObject("data");
  174. appuid=dataJson.getString("id");
  175. openid=dataJson.getString("openid");
  176. if(GzhUtil.isEmpty(appuid) || GzhUtil.isEmpty(openid))
  177. {
  178. return new TextView("/user/index.do");
  179. }
  180. session.setAttribute("appuid", appuid);
  181. session.setAttribute("openid", openid);
  182. } else {
  183. return new TextView("/user/index.do");
  184. }
  185. }
  186. }
  187. context.getRequest().setAttribute("devid", devid);
  188. context.getRequest().setAttribute("opt", opt);
  189. String signstr = pkgid+'#'+devid+'*'+price0;
  190. String signc = CodecUtil.str2md5(signstr);
  191. if(!signc.equals(sign)) {
  192. return new TextView("/user/index.do");
  193. }
  194. if(!GzhUtil.isEmpty(pkgid))
  195. {
  196. para.put("pkid", pkgid);
  197. GzhUtil.toM3Sign(para);
  198. String result = GzhUtil.sendPost(Constants.m3IntAddr + "/package/getPkgByPkid.do", para);
  199. JSONObject resJson = JSONObject.parseObject(result);
  200. log.info(resJson);
  201. int resCode = resJson.getIntValue("code");
  202. if(resCode == 0)
  203. {
  204. JSONObject dataJson = resJson.getJSONObject("data");
  205. dataJson = JSONObject.parseObject(dataJson.getString("pkg"));
  206. String pkgName = dataJson.getString("pkgName");
  207. String pkgDesc = dataJson.getString("pkgDesc");
  208. double price = dataJson.getDoubleValue("price");
  209. String ts = dataJson.getString("ts");
  210. String expiryDay = dataJson.getString("expiryDay");
  211. String paytype = dataJson.getString("paytype");
  212. Map<String, Object> pkgInfo = new HashMap<String, Object>();
  213. pkgInfo.put("pkgName", pkgName);
  214. pkgInfo.put("pkgDesc", pkgDesc);
  215. if(!GzhUtil.isEmpty(price0)) {
  216. price = Double.parseDouble(price0);
  217. }
  218. pkgInfo.put("price", price);
  219. pkgInfo.put("pkgid", pkgid);
  220. pkgInfo.put("ts", ts);
  221. pkgInfo.put("expiryDay", expiryDay);
  222. pkgInfo.put("paytype", paytype);
  223. session.setAttribute("pkgInfo", pkgInfo);
  224. context.getRequest().setAttribute("pkgInfo", pkgInfo);
  225. }
  226. }
  227. para.put("openid", openid);
  228. GzhUtil.toM3Sign(para);
  229. String result = GzhUtil.sendPost(Constants.m3IntAddr + "/user/getBalance.do", para);
  230. JSONObject resJson = JSONObject.parseObject(result);
  231. int resCode = resJson.getIntValue("code");
  232. if(resCode == 0)
  233. {
  234. JSONObject dataJson = resJson.getJSONObject("data");
  235. String balance=dataJson.getString("balance");
  236. context.getRequest().setAttribute("balance", balance);
  237. } else
  238. {
  239. context.getRequest().setAttribute("balance", "0.00");
  240. }
  241. result = GzhUtil.sendPost(Constants.m3IntAddr + "/package/getSPkgs.do", para);
  242. if(!Tools.isEmpty(result))
  243. {
  244. resJson = JSONObject.parseObject(result);
  245. JSONArray dataJson = resJson.getJSONArray("data");
  246. log.info(dataJson);
  247. context.getRequest().setAttribute("spkgs", dataJson);
  248. }
  249. result = GzhUtil.sendPost(Constants.m3IntAddr + "/packkey/getMember.do", para);
  250. if(!Tools.isEmpty(result))
  251. {
  252. resJson = JSONObject.parseObject(result);
  253. JSONArray dataJson = resJson.getJSONArray("data");
  254. context.getRequest().setAttribute("cons", dataJson);
  255. }
  256. return new TextView("/pkgordersyb.jsp");
  257. // return new TextView("/pkgorder.jsp");
  258. }
  259. /**
  260. * 跳转至加速包购买下单界面
  261. * @param context
  262. * @return
  263. */
  264. @Path(value="/settlementSpkgs.do")
  265. public TextView settlementSpkgs(Context context)
  266. {
  267. HttpSession session = context.getRequest().getSession();
  268. Map<String, String> para = context.getParas();
  269. log.info("spkgs para==>"+para);
  270. String devid = para.get("devid");
  271. String spkgid = para.get("spkgid");
  272. String price0 = para.get("price");
  273. String sign = para.get("sign");
  274. String appuid = String.valueOf(session.getAttribute("appuid"));
  275. String openid = (String) session.getAttribute("openid");
  276. String wxCode = para.get("code");
  277. if(GzhUtil.isEmpty(devid))
  278. {
  279. return new TextView("/user/index.do");
  280. }
  281. if(GzhUtil.isEmpty(appuid) || GzhUtil.isEmpty(openid))
  282. {
  283. if(!GzhUtil.isEmpty(wxCode))
  284. {
  285. Map<String,String> m=GzhUtil.getOpenId(wxCode,Constants.appId,Constants.appSecret);
  286. openid=m.get("openId");
  287. String accessToken=m.get("accessToken");
  288. session.setAttribute("openid", openid);
  289. session.setAttribute("accessToken", accessToken);
  290. log.info("wxCode="+wxCode+",openid="+openid);
  291. para.put("openid", openid);
  292. GzhUtil.toM3Sign(para);
  293. String u=Constants.m3IntAddr + "/user/wxIndex.do";
  294. String result = GzhUtil.sendPost(u, para);
  295. log.info("url="+u+",result="+result);
  296. JSONObject resJson = JSONObject.parseObject(result);
  297. int resCode = resJson.getIntValue("code");
  298. if(resCode == 0)
  299. {
  300. JSONObject dataJson = resJson.getJSONObject("data");
  301. if(dataJson!=null) {
  302. appuid=dataJson.getString("appuid");
  303. }
  304. session.setAttribute("appuid", appuid);
  305. session.setAttribute("openid", openid);
  306. }
  307. }
  308. if(GzhUtil.isEmpty(appuid) || GzhUtil.isEmpty(openid))
  309. {
  310. para.put("devid", devid);
  311. GzhUtil.toM3Sign(para);
  312. String result = GzhUtil.sendPost(Constants.m3IntAddr + "/user/getInfoByDevid.do", para);
  313. JSONObject resJson = JSONObject.parseObject(result);
  314. int resCode = resJson.getIntValue("code");
  315. if(resCode == 0)
  316. {
  317. JSONObject dataJson = resJson.getJSONObject("data");
  318. appuid=dataJson.getString("id");
  319. openid=dataJson.getString("openid");
  320. if(GzhUtil.isEmpty(appuid) || GzhUtil.isEmpty(openid))
  321. {
  322. return new TextView("/user/index.do");
  323. }
  324. session.setAttribute("appuid", appuid);
  325. session.setAttribute("openid", openid);
  326. } else {
  327. return new TextView("/user/index.do");
  328. }
  329. }
  330. }
  331. context.getRequest().setAttribute("devid", devid);
  332. context.getRequest().setAttribute("amount", price0);
  333. context.getRequest().setAttribute("speedpackid", spkgid);
  334. String signstr = spkgid+'#'+devid+'*'+price0;
  335. String signc = CodecUtil.str2md5(signstr);
  336. if(!signc.equals(sign)) {
  337. return new TextView("/mifi/benefit.do");
  338. }
  339. para.put("openid", openid);
  340. GzhUtil.toM3Sign(para);
  341. String result = GzhUtil.sendPost(Constants.m3IntAddr + "/user/getBalance.do", para);
  342. JSONObject resJson = JSONObject.parseObject(result);
  343. int resCode = resJson.getIntValue("code");
  344. if(resCode == 0)
  345. {
  346. JSONObject dataJson = resJson.getJSONObject("data");
  347. String balance=dataJson.getString("balance");
  348. context.getRequest().setAttribute("balance", balance);
  349. } else
  350. {
  351. context.getRequest().setAttribute("balance", "0.00");
  352. }
  353. return new TextView("/mifi/benefitSubmit.do");
  354. }
  355. /**
  356. * 跳转至套餐购买下单界面
  357. * @param context
  358. * @return
  359. */
  360. @Path(value="/pkgOrder.do")
  361. public TextView pkgOrder(Context context)
  362. {
  363. HttpSession session = context.getRequest().getSession();
  364. Map<String, String> para = context.getParas();
  365. String appuid = String.valueOf(session.getAttribute("appuid"));
  366. String cursn=(String)session.getAttribute("cursn");
  367. int devtype=GzhUtil.getDeviceType(cursn);
  368. if(devtype==0)
  369. {
  370. if(GzhUtil.isEmpty(appuid))
  371. return new TextView(Constants.loginUrl);
  372. }
  373. String devid = cursn;
  374. if (GzhUtil.isEmpty(devid)) {
  375. devid = GzhUtil.getDevID(session, para);
  376. }
  377. @SuppressWarnings("unchecked")
  378. Map<String, Object> pkgInfo = (Map<String, Object>) session.getAttribute("pkgInfo");
  379. String openid = (String) session.getAttribute("openid");
  380. para.put("openid", openid);
  381. GzhUtil.toM3Sign(para);
  382. String result = GzhUtil.sendPost(Constants.m3IntAddr + "/user/getBalance.do", para);
  383. JSONObject resJson = JSONObject.parseObject(result);
  384. int resCode = resJson.getIntValue("code");
  385. if(resCode == 0)
  386. {
  387. JSONObject dataJson = resJson.getJSONObject("data");
  388. String balance=dataJson.getString("balance");
  389. context.getRequest().setAttribute("balance", balance);
  390. } else
  391. {
  392. context.getRequest().setAttribute("balance", "0.00");
  393. }
  394. result = GzhUtil.sendPost(Constants.m3IntAddr + "/package/getSPkgs.do", para);
  395. if(!Tools.isEmpty(result))
  396. {
  397. resJson = JSONObject.parseObject(result);
  398. JSONArray dataJson = resJson.getJSONArray("data");
  399. log.info(dataJson);
  400. context.getRequest().setAttribute("spkgs", dataJson);
  401. }
  402. result = GzhUtil.sendPost(Constants.m3IntAddr + "/packkey/getMember.do", para);
  403. if(!Tools.isEmpty(result))
  404. {
  405. resJson = JSONObject.parseObject(result);
  406. JSONArray dataJson = resJson.getJSONArray("data");
  407. context.getRequest().setAttribute("cons", dataJson);
  408. }
  409. context.getRequest().setAttribute("pkgInfo", pkgInfo);
  410. context.getRequest().setAttribute("devid", devid);
  411. if("151992".equals(appuid)) {
  412. return new TextView("/pkgordersyb.jsp");
  413. }
  414. return new TextView("/pkgordersyb.jsp");
  415. // return new TextView("/pkgorder.jsp");
  416. }
  417. /**
  418. * 购买产品/套餐下单-支付
  419. * @param context
  420. * @return
  421. */
  422. @Path(value="/buyPdts.do")
  423. @SuppressWarnings("unchecked")
  424. public SimpleJsonView buyPdts(Context context)
  425. {
  426. HttpSession session = context.getRequest().getSession();
  427. Map<String,String> para = context.getParas();
  428. String appuid = String.valueOf(session.getAttribute("appuid"));
  429. // if(GzhUtil.isEmpty(appuid))
  430. // return new SimpleJsonView(Constants.noLoginMsg);
  431. String openid = (String) session.getAttribute("openid");
  432. if(Tools.isEmpty(Constants.appId) || Tools.isEmpty(Constants.apikey) || Tools.isEmpty(Constants.appSecret) || Tools.isEmpty(Constants.mch_id))
  433. {
  434. log.info("充值失败,支付信息为空>>>代理ID:"+Constants.orgid);
  435. return new SimpleJsonView("支付信息错误,请联系客服");
  436. }
  437. String amount = ""; //订单价格
  438. String outTradeNo = ""; //订单ID
  439. String body = "";
  440. int type = Integer.parseInt(para.get("type"));
  441. log.info("type="+type);
  442. if(type == 0)
  443. {
  444. body = "商品购买";
  445. Map<String, Object> pdtInfo = (Map<String, Object>) session.getAttribute("pdtInfo");
  446. amount = String.valueOf(pdtInfo.get("total"));
  447. para.put("pdtid", String.valueOf(pdtInfo.get("pdtid")));
  448. para.put("appuid", appuid);
  449. para.put("num", String.valueOf(pdtInfo.get("num")));
  450. para.put("price", amount);
  451. /***********************下单,获取订单编号-BEGIN***********************/
  452. log.info("设备购买,下单>>>"+para);
  453. GzhUtil.toM3PaySign(para);
  454. String result = GzhUtil.sendPost(Constants.m3IntAddr+"/device/buyPdts.do", para);
  455. JSONObject resJson = JSONObject.parseObject(result);
  456. log.info("购买设备获取订单编号返回:"+result);
  457. if(resJson.getIntValue("code") != 0){
  458. return new SimpleJsonView(resJson.getString("msg"));
  459. }
  460. JSONObject dataJson = resJson.getJSONObject("data");
  461. outTradeNo = dataJson.getString("orderid");
  462. }
  463. else if(type == 1)
  464. {
  465. body = "套餐购买";
  466. Map<String, Object> pkgInfo = (Map<String, Object>) session.getAttribute("pkgInfo");
  467. //amount = String.valueOf(pkgInfo.get("price"));
  468. amount = String.valueOf(para.get("amount"));
  469. para.put("pkid", String.valueOf(pkgInfo.get("pkgid")));
  470. para.put("appuid", appuid);
  471. para.put("price", amount);
  472. para.put("ts", String.valueOf(pkgInfo.get("ts")));
  473. /***********************下单,获取订单编号-BEGIN***********************/
  474. log.info("套餐购买,下单>>>"+para);
  475. GzhUtil.toM3PaySign(para);
  476. String result = GzhUtil.sendPost(Constants.m3IntAddr+"/package/buyPkg.do", para);
  477. JSONObject resJson = JSONObject.parseObject(result);
  478. log.info("购买套餐获取订单编号返回:"+result);
  479. if(resJson.getIntValue("code") != 0){
  480. return new SimpleJsonView(resJson);
  481. }
  482. JSONObject dataJson = resJson.getJSONObject("data");
  483. outTradeNo = dataJson.getString("orderid");
  484. }
  485. /***********************下单,获取订单编号-END***********************/
  486. //执行统一下单接口,初始化各参数
  487. String nonceStr = PaySign.getNonceStr();
  488. String spBillCreateIP = JsApiReqUtils.getRealIp(context.getRequest());
  489. //初始化传入参数
  490. BigDecimal dised = new BigDecimal(amount);
  491. // BigDecimal dised = new BigDecimal(0.01); //测试价格0.01,待修改为totalAmount zby
  492. BigDecimal diz = new BigDecimal(100);
  493. JsApiReqData jsApiReqData = new JsApiReqData(body,nonceStr,outTradeNo,dised.multiply(diz).intValue(),spBillCreateIP, openid,Constants.appId,Constants.mch_id,Constants.apikey);
  494. 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");
  495. log.info("info========="+info);
  496. String prepay_id="err";
  497. StringBuffer sb = JsApiReqUtils.httpsRequest(Constants.unifiedorderurl, "POST", info);
  498. log.info("sb=="+sb.toString());
  499. Map<String,Object> payInfo = new HashMap<String, Object>();
  500. if (!"".equals(sb.toString()))
  501. {
  502. try
  503. {
  504. //得到预支付ID,即prepay_id
  505. Map<String, String> getMap = Message2XmlUtil.parseXml(new String(sb.toString().getBytes(), "utf-8"));
  506. if(getMap.get("prepay_id")!=null)
  507. {
  508. //在return_code 和result_code都为SUCCESS的时候有返回
  509. prepay_id = getMap.get("prepay_id");
  510. log.info("订单:"+outTradeNo+",请求微信支付!");
  511. }
  512. else
  513. {
  514. log.info("获取预支付ID失败,返回参数为>>>>>>"+getMap);
  515. }
  516. }
  517. catch (UnsupportedEncodingException e)
  518. {
  519. log.info(Tools.getExceptionMessage(e));
  520. }
  521. Integer timeStramp = (int)(System.currentTimeMillis()/1000);
  522. JsApiToJsData jsApiToJsData = new JsApiToJsData(timeStramp,nonceStr,prepay_id,Constants.appId,Constants.apikey);
  523. payInfo.put("appId", jsApiToJsData.getAppid());
  524. payInfo.put("timeStamp", String.valueOf(jsApiToJsData.getTimeStamp()));
  525. payInfo.put("nonceStr", jsApiToJsData.getNonce_str());
  526. payInfo.put("package", "prepay_id="+jsApiToJsData.getPrepay_id());
  527. payInfo.put("signType", "MD5");
  528. payInfo.put("paySign", jsApiToJsData.getSign());
  529. log.info("支付信息:"+payInfo);
  530. }
  531. else
  532. {
  533. log.info("支付失败,支付参数初始化失败>>>{"+sb+"}");
  534. }
  535. return new SimpleJsonView(payInfo);
  536. }
  537. //银联支付
  538. @Path(value="/buyYLPdts.do")
  539. public SimpleJsonView buyYLPdts(Context context)
  540. {
  541. Map<String,String> para = context.getParas();
  542. HttpSession session = context.getRequest().getSession();
  543. String appuid = String.valueOf(session.getAttribute("appuid"));
  544. String openid = (String) session.getAttribute("openid");
  545. if(GzhUtil.isEmpty(appuid))
  546. {
  547. Map<String,String> result = new HashMap<String,String>();
  548. result.put("status", "403");
  549. result.put("msg", "请登录");
  550. return new SimpleJsonView(result);
  551. }
  552. String amount=para.get("amount"); //订单价格
  553. double af=Double.parseDouble(amount);
  554. //低于1元不能充值
  555. if(af<1)
  556. {
  557. Map<String,String> result = new HashMap<String,String>();
  558. result.put("status", "500");
  559. result.put("msg", "出错了");
  560. return new SimpleJsonView(result);
  561. }
  562. String outTradeNo = ""; //订单ID
  563. String notify=YL.notify;
  564. int type = Integer.parseInt(para.get("type"));
  565. log.info("type="+type);
  566. if(type == 0)
  567. {
  568. Map<String, Object> pdtInfo = (Map<String, Object>) session.getAttribute("pdtInfo");
  569. //amount = String.valueOf(pdtInfo.get("total"));
  570. //amount=para.get("amount");
  571. para.put("pdtid", String.valueOf(pdtInfo.get("pdtid")));
  572. para.put("appuid", appuid);
  573. para.put("num", String.valueOf(pdtInfo.get("num")));
  574. para.put("price", amount);
  575. /***********************下单,获取订单编号-BEGIN***********************/
  576. log.info("设备购买,下单>>>"+para);
  577. GzhUtil.toM3PaySign(para);
  578. String result = GzhUtil.sendPost(Constants.m3IntAddr+"/device/buyPdts.do", para);
  579. JSONObject resJson = JSONObject.parseObject(result);
  580. log.info("购买设备获取订单编号返回:"+result);
  581. if(resJson.getIntValue("code") != 0){
  582. return new SimpleJsonView(resJson.getString("msg"));
  583. }
  584. JSONObject dataJson = resJson.getJSONObject("data");
  585. outTradeNo = dataJson.getString("orderid");
  586. }
  587. else if(type == 1)
  588. {
  589. Map<String, Object> pkgInfo = (Map<String, Object>) session.getAttribute("pkgInfo");
  590. //amount = String.valueOf(pkgInfo.get("price"));
  591. //amount=para.get("amount");
  592. para.put("pkid", String.valueOf(pkgInfo.get("pkgid")));
  593. para.put("appuid", appuid);
  594. para.put("price", amount);
  595. para.put("ts", String.valueOf(pkgInfo.get("ts")));
  596. /***********************下单,获取订单编号-BEGIN***********************/
  597. log.info("套餐购买,下单>>>"+para);
  598. GzhUtil.toM3PaySign(para);
  599. String result = GzhUtil.sendPost(Constants.m3IntAddr+"/package/buyPkg.do", para);
  600. JSONObject resJson = JSONObject.parseObject(result);
  601. log.info("购买套餐获取订单编号返回:"+result);
  602. if(resJson.getIntValue("code") != 0){
  603. return new SimpleJsonView(resJson);
  604. }
  605. JSONObject dataJson = resJson.getJSONObject("data");
  606. outTradeNo = dataJson.getString("orderid");
  607. }
  608. else if(type == 2)
  609. {
  610. amount=para.get("amount");
  611. para.put("appuid", appuid);
  612. para.put("price", amount);
  613. //TODO pkgid pkgprice
  614. para.put("openid", openid);
  615. String pkgprice=para.get("pkgprice");
  616. para.put("pkgprice", pkgprice);
  617. /***********************下单,获取订单编号-BEGIN***********************/
  618. log.info("钱包充值,下单>>>"+para);
  619. GzhUtil.toM3PaySign(para);
  620. String result = GzhUtil.sendPost(Constants.m3IntAddr+"/package/buyMember.do", para);
  621. log.info(result);
  622. JSONObject resJson = JSONObject.parseObject(result);
  623. log.info("钱包充值获取订单编号返回:"+result);
  624. if(resJson.getIntValue("code") != 0){
  625. return new SimpleJsonView(resJson);
  626. }
  627. JSONObject dataJson = resJson.getJSONObject("data");
  628. outTradeNo = dataJson.getString("orderid");
  629. notify = YL.membernotify;
  630. }
  631. else if(type == 3)
  632. {
  633. amount=para.get("amount");
  634. para.put("appuid", appuid);
  635. para.put("price", amount);
  636. /***********************下单,获取订单编号-BEGIN***********************/
  637. log.info("加速包购买,下单>>>"+para);
  638. GzhUtil.toM3PaySign(para);
  639. String result = GzhUtil.sendPost(Constants.m3IntAddr+"/package/buySpeedPack.do", para);
  640. log.info(result);
  641. JSONObject resJson = JSONObject.parseObject(result);
  642. log.info("购买加速包获取订单编号返回:"+result);
  643. if(resJson.getIntValue("code") != 0){
  644. return new SimpleJsonView(resJson);
  645. }
  646. JSONObject dataJson = resJson.getJSONObject("data");
  647. outTradeNo = dataJson.getString("orderid");
  648. notify = YL.ylmemberspeedpacknotify;
  649. }
  650. SortedMap<String, String> map = new TreeMap<String, String>();
  651. String spBillCreateIP = JsApiReqUtils.getRealIp(context.getRequest());
  652. //初始化传入参数
  653. BigDecimal dised = new BigDecimal(amount);
  654. // BigDecimal dised = new BigDecimal(0.01); //测试价格0.01,待修改为totalAmount zby
  655. BigDecimal diz = new BigDecimal(100);
  656. if("151992".equals(appuid) || "174056".equals(appuid)) {
  657. dised = new BigDecimal(0.01);
  658. }
  659. // String key = "432fc0caf293dde237e574fbf057f056";
  660. // String mch_id="QRA6072481C0003";
  661. // String notify="http://shuhai.sharemao.cn/mifi/ylnotify.do";
  662. /*String key = YL.key;
  663. String mch_id=YL.mch_id;
  664. // String notify=YL.notify;
  665. map.put("body", "收款码收款_商品");
  666. map.put("charset", "UTF-8");
  667. map.put("is_raw", "1");
  668. map.put("mch_create_ip", spBillCreateIP);
  669. map.put("mch_id", mch_id);
  670. map.put("nonce_str", "str"+System.currentTimeMillis());
  671. map.put("notify_url", notify);
  672. map.put("out_trade_no", outTradeNo);
  673. map.put("service", "pay.weixin.jspay");
  674. map.put("sign_type", "MD5");
  675. map.put("sub_openid", openid);
  676. map.put("total_fee", String.valueOf(dised.multiply(diz).intValue()));
  677. map.put("version", "2.0");
  678. map.put("sign", sign(map,key));
  679. String reqUrl = "https://qra.95516.com/pay/gateway";
  680. log.info("reqUrl:" + reqUrl);
  681. log.info("reqParams:" + XmlUtils.parseXML(map));
  682. CloseableHttpResponse response = null;
  683. CloseableHttpClient client = null;
  684. String res = null;
  685. Map<String, String> resultMap = null;
  686. Map<String,String> payInfo = new HashMap<String,String>();
  687. try {
  688. HttpPost httpPost = new HttpPost(reqUrl);
  689. StringEntity entityParams = new StringEntity(XmlUtils.parseXML(map), "utf-8");
  690. httpPost.setEntity(entityParams);
  691. httpPost.setHeader("Content-Type", "text/xml;utf-8");
  692. client = HttpClients.createDefault();
  693. response = client.execute(httpPost);
  694. if (response != null && response.getEntity() != null) {
  695. resultMap = XmlUtils.toMap(EntityUtils.toByteArray(response.getEntity()), "utf-8");
  696. res = XmlUtils.toXml(resultMap);
  697. log.info("请求结果:" + res);
  698. if (!SignUtils.checkParam(resultMap, key)) {
  699. res = "验证签名不通过";
  700. } else {
  701. if ("0".equals(resultMap.get("status")) && "0".equals(resultMap.get("result_code"))) {
  702. String pay_info = resultMap.get("pay_info");
  703. log.info("pay_info : " + pay_info);
  704. res = "ok";
  705. JSONObject resJson = JSONObject.parseObject(pay_info);
  706. payInfo.put("appId", resJson.getString("appId"));
  707. payInfo.put("timeStamp", resJson.getString("timeStamp"));
  708. payInfo.put("nonceStr", resJson.getString("nonceStr"));
  709. payInfo.put("package", resJson.getString("package"));
  710. payInfo.put("signType", "MD5");
  711. payInfo.put("paySign", resJson.getString("paySign"));
  712. }
  713. }
  714. } else {
  715. res = "操作失败";
  716. }
  717. } catch (Exception e) {
  718. log.error("操作失败,原因:",e);
  719. res = "系统异常";
  720. } finally {
  721. if (response != null) {
  722. try {
  723. response.close();
  724. } catch (IOException e) {
  725. // TODO Auto-generated catch block
  726. e.printStackTrace();
  727. }
  728. }
  729. if (client != null) {
  730. try {
  731. client.close();
  732. } catch (IOException e) {
  733. // TODO Auto-generated catch block
  734. e.printStackTrace();
  735. }
  736. }
  737. }
  738. Map<String,String> result = new HashMap<String,String>();
  739. if("ok".equals(res)){
  740. // result = payInfo;
  741. // return new SimpleJsonView(resultMap);
  742. result.put("status", "200");
  743. result.put("msg", res);
  744. result.put("pay_info", resultMap.get("pay_info"));
  745. }else{
  746. result.put("status", "500");
  747. result.put("msg", res);
  748. }*/
  749. Map<String,String> result = new HashMap<String,String>();
  750. String nonceStr = PaySign.getNonceStr();
  751. JsApiReqData jsApiReqData = new JsApiReqData(notify,"收款码收款_商品",nonceStr,outTradeNo,dised.multiply(diz).intValue(),spBillCreateIP, openid,Constants.appId,Constants.mch_id,Constants.apikey);
  752. 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");
  753. log.info("info========="+info);
  754. String prepay_id="err";
  755. StringBuffer sb = JsApiReqUtils.httpsRequest(Constants.unifiedorderurl, "POST", info);
  756. Map<String,Object> payInfo = new HashMap<String, Object>();
  757. if (!"".equals(sb.toString()))
  758. {
  759. try
  760. {
  761. //得到预支付ID,即prepay_id
  762. Map<String, String> getMap = Message2XmlUtil.parseXml(new String(sb.toString().getBytes(), "utf-8"));
  763. if(getMap.get("prepay_id")!=null)
  764. {
  765. //在return_code 和result_code都为SUCCESS的时候有返回
  766. prepay_id = getMap.get("prepay_id");
  767. log.info("订单:"+outTradeNo+",请求微信支付!");
  768. }
  769. else
  770. {
  771. log.info("获取预支付ID失败,返回参数为>>>>>>"+getMap);
  772. }
  773. }
  774. catch (UnsupportedEncodingException e)
  775. {
  776. log.info(Tools.getExceptionMessage(e));
  777. }
  778. Integer timeStramp = (int)(System.currentTimeMillis()/1000);
  779. JsApiToJsData jsApiToJsData = new JsApiToJsData(timeStramp,nonceStr,prepay_id,Constants.appId,Constants.apikey);
  780. payInfo.put("appId", jsApiToJsData.getAppid());
  781. payInfo.put("timeStamp", String.valueOf(jsApiToJsData.getTimeStamp()));
  782. payInfo.put("nonceStr", jsApiToJsData.getNonce_str());
  783. payInfo.put("package", "prepay_id="+jsApiToJsData.getPrepay_id());
  784. payInfo.put("signType", "MD5");
  785. payInfo.put("paySign", jsApiToJsData.getSign());
  786. log.info("支付信息:"+payInfo);
  787. result.put("status", "200");
  788. result.put("msg", "ok");
  789. result.put("pay_info", JSON.toJSONString(payInfo));
  790. }
  791. else
  792. {
  793. log.info("支付失败,支付参数初始化失败>>>{"+sb+"}");
  794. result.put("status", "500");
  795. result.put("msg", "支付失败,支付参数初始化失败>>>{"+sb+"}");
  796. }
  797. return new SimpleJsonView(result);
  798. }
  799. // @Path(value="/buyYiZFPdts.do")
  800. // public SimpleJsonView buyYiZFPdts(Context context)
  801. // {
  802. // Map<String,String> para = context.getParas();
  803. //
  804. // HttpSession session = context.getRequest().getSession();
  805. // String appuid = String.valueOf(session.getAttribute("appuid"));
  806. // String openid = (String) session.getAttribute("openid");
  807. //
  808. // String amount=para.get("amount"); //订单价格
  809. //
  810. // String outTradeNo = ""; //订单ID
  811. //
  812. //
  813. // Map<String, Object> pkgInfo = (Map<String, Object>) session.getAttribute("pkgInfo");
  814. // //amount = String.valueOf(pkgInfo.get("price"));
  815. // //amount=para.get("amount");
  816. // para.put("pkid", String.valueOf(pkgInfo.get("pkgid")));
  817. // para.put("appuid", appuid);
  818. // para.put("price", amount);
  819. // para.put("ts", String.valueOf(pkgInfo.get("ts")));
  820. //
  821. // /***********************下单,获取订单编号-BEGIN***********************/
  822. // log.info("套餐购买,下单>>>"+para);
  823. //
  824. // GzhUtil.toM3PaySign(para);
  825. // String resulta = GzhUtil.sendPost(Constants.m3IntAddr+"/package/buyPkg.do", para);
  826. // JSONObject resJsona = JSONObject.parseObject(resulta);
  827. // log.info("购买套餐获取订单编号返回:"+resulta);
  828. // if(resJsona.getIntValue("code") != 0){
  829. // return new SimpleJsonView(resJsona);
  830. // }
  831. // JSONObject dataJson = resJsona.getJSONObject("data");
  832. // outTradeNo = dataJson.getString("orderid");
  833. //
  834. //
  835. // String spBillCreateIP = JsApiReqUtils.getRealIp(context.getRequest());
  836. // Map<String,String> payInfo = new HashMap<String,String>();
  837. // String res = null;
  838. // try
  839. // {
  840. // //接口地址
  841. // String api = "/yeepay/pre_pay";
  842. // //具体接口的业务参数
  843. // Map<String, Object> businessData = new HashMap<String, Object>();
  844. // businessData.put("appId", Constants.appId);
  845. // businessData.put("scene", "ONLINE");
  846. // businessData.put("payWay", "WECHAT_OFFIACCOUNT");
  847. // businessData.put("orderAmount", amount);
  848. // businessData.put("channel", "WECHAT");
  849. // businessData.put("userIp", spBillCreateIP);
  850. // businessData.put("userId", openid);
  851. // businessData.put("goodsName", "1"+outTradeNo);
  852. //
  853. // String jsonData = JSON.toJSONString(businessData);
  854. // log.info(jsonData);
  855. // PrivateKey merchantPrivateKey = YiZF.getPrivateKey(YiZF.MERCHANT_PRIVATE_KEY);
  856. // PublicKey publicKey = YiZF.getPublicKey(YiZF.PUBLIC_KEY);
  857. // OpenParam requestParam = YiZF.buildOpenParam(jsonData, YiZF.BUSINESS_SUBJECT_ID, merchantPrivateKey, publicKey);
  858. //
  859. // //接口返回基本结构:code、message、data(OpenParam)
  860. // String responseJson = YiZF.doPost4String(YiZF.URL_HOST + api, JSON.toJSONString(requestParam),"Bearer "+YiZF.getToken5());
  861. // log.info("url="+YiZF.URL_HOST + api+",Authorization="+"Bearer"+YiZF.getToken5()+",json="+JSON.toJSONString(requestParam));
  862. // log.info("responseJson="+responseJson);
  863. // com.alibaba.fastjson2.JSONObject result = JSON.parseObject(responseJson);
  864. // OpenParam responseParam = JSON.parseObject(result.getString("data"), OpenParam.class);
  865. // String responseBusinessData = YiZF.verifyAndDecrypt(responseParam, YiZF.BUSINESS_SUBJECT_ID, merchantPrivateKey, publicKey);
  866. // log.info("responseBusinessData="+responseBusinessData);
  867. //
  868. //
  869. // JSONObject resJson = JSONObject.parseObject(responseBusinessData);
  870. // if(resJson.getString("code").equals("0000"))
  871. // {
  872. // res = "ok";
  873. // resJson = JSONObject.parseObject(resJson.getString("data"));
  874. // resJson = JSONObject.parseObject(resJson.getString("prePayTn"));
  875. // payInfo.put("appId", resJson.getString("appId"));
  876. // payInfo.put("timeStamp", resJson.getString("timeStamp"));
  877. // payInfo.put("nonceStr", resJson.getString("nonceStr"));
  878. // payInfo.put("package", resJson.getString("package"));
  879. // payInfo.put("signType", resJson.getString("signType"));
  880. // payInfo.put("paySign", resJson.getString("paySign"));
  881. // }
  882. // }
  883. // catch(Exception e)
  884. // {
  885. // Tools.getExceptionMessage(e);
  886. // }
  887. //
  888. // Map<String,String> result = new HashMap<String,String>();
  889. // if("ok".equals(res)){
  890. // result = payInfo;
  891. // }else{
  892. // result.put("status", "500");
  893. // result.put("msg", res);
  894. // }
  895. // return new SimpleJsonView(result);
  896. // }
  897. @Path(value="/buyMember.do")
  898. public SimpleJsonView buyMember(Context context)
  899. {
  900. Map<String,String> para = context.getParas();
  901. HttpSession session = context.getRequest().getSession();
  902. String appuid = String.valueOf(session.getAttribute("appuid"));
  903. String openid = (String) session.getAttribute("openid");
  904. String amount = ""; //订单价格
  905. String outTradeNo = ""; //订单ID
  906. String memid="";
  907. {
  908. amount=para.get("amount");
  909. memid=para.get("memid");
  910. para.put("appuid", appuid);
  911. para.put("price", amount);
  912. para.put("memid", memid);
  913. /***********************下单,获取订单编号-BEGIN***********************/
  914. log.info("套餐购买,下单>>>"+para);
  915. GzhUtil.toM3PaySign(para);
  916. String result = GzhUtil.sendPost(Constants.m3IntAddr+"/package/buyMember.do", para);
  917. log.info(result);
  918. JSONObject resJson = JSONObject.parseObject(result);
  919. log.info("购买套餐获取订单编号返回:"+result);
  920. if(resJson.getIntValue("code") != 0){
  921. return new SimpleJsonView(resJson);
  922. }
  923. JSONObject dataJson = resJson.getJSONObject("data");
  924. outTradeNo = dataJson.getString("orderid");
  925. }
  926. /***********************下单,获取订单编号-END***********************/
  927. //执行统一下单接口,初始化各参数
  928. String nonceStr = PaySign.getNonceStr();
  929. String spBillCreateIP = JsApiReqUtils.getRealIp(context.getRequest());
  930. //初始化传入参数
  931. BigDecimal dised = new BigDecimal(amount);
  932. // BigDecimal dised = new BigDecimal(0.01); //测试价格0.01,待修改为totalAmount zby
  933. BigDecimal diz = new BigDecimal(100);
  934. String body = "会员充值";
  935. String notify="/mifi/ylmembernotify.do";
  936. JsApiReqData jsApiReqData = new JsApiReqData(notify,body,nonceStr,outTradeNo,dised.multiply(diz).intValue(),spBillCreateIP, openid,Constants.appId,Constants.mch_id,Constants.apikey);
  937. 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");
  938. log.info("info========="+info);
  939. String prepay_id="err";
  940. StringBuffer sb = JsApiReqUtils.httpsRequest(Constants.unifiedorderurl, "POST", info);
  941. Map<String,Object> payInfo = new HashMap<String, Object>();
  942. if (!"".equals(sb.toString()))
  943. {
  944. try
  945. {
  946. //得到预支付ID,即prepay_id
  947. Map<String, String> getMap = Message2XmlUtil.parseXml(new String(sb.toString().getBytes(), "utf-8"));
  948. if(getMap.get("prepay_id")!=null)
  949. {
  950. //在return_code 和result_code都为SUCCESS的时候有返回
  951. prepay_id = getMap.get("prepay_id");
  952. log.info("订单:"+outTradeNo+",请求微信支付!");
  953. }
  954. else
  955. {
  956. log.info("获取预支付ID失败,返回参数为>>>>>>"+getMap);
  957. }
  958. }
  959. catch (UnsupportedEncodingException e)
  960. {
  961. log.info(Tools.getExceptionMessage(e));
  962. }
  963. Integer timeStramp = (int)(System.currentTimeMillis()/1000);
  964. JsApiToJsData jsApiToJsData = new JsApiToJsData(timeStramp,nonceStr,prepay_id,Constants.appId,Constants.apikey);
  965. payInfo.put("appId", jsApiToJsData.getAppid());
  966. payInfo.put("timeStamp", String.valueOf(jsApiToJsData.getTimeStamp()));
  967. payInfo.put("nonceStr", jsApiToJsData.getNonce_str());
  968. payInfo.put("package", "prepay_id="+jsApiToJsData.getPrepay_id());
  969. payInfo.put("signType", "MD5");
  970. payInfo.put("paySign", jsApiToJsData.getSign());
  971. log.info("支付信息:"+payInfo);
  972. }
  973. else
  974. {
  975. log.info("支付失败,支付参数初始化失败>>>{"+sb+"}");
  976. }
  977. return new SimpleJsonView(payInfo);
  978. }
  979. @Path(value="/buyYLMember.do")
  980. public SimpleJsonView buyYLMember(Context context)
  981. {
  982. Map<String,String> para = context.getParas();
  983. HttpSession session = context.getRequest().getSession();
  984. String appuid = String.valueOf(session.getAttribute("appuid"));
  985. String openid = (String) session.getAttribute("openid");
  986. String amount = ""; //订单价格
  987. String outTradeNo = ""; //订单ID
  988. String memid="";
  989. {
  990. amount=para.get("amount");
  991. memid=para.get("memid");
  992. para.put("appuid", appuid);
  993. para.put("price", amount);
  994. para.put("memid", memid);
  995. /***********************下单,获取订单编号-BEGIN***********************/
  996. log.info("套餐购买,下单>>>"+para);
  997. GzhUtil.toM3PaySign(para);
  998. String result = GzhUtil.sendPost(Constants.m3IntAddr+"/package/buyMember.do", para);
  999. log.info(result);
  1000. JSONObject resJson = JSONObject.parseObject(result);
  1001. log.info("购买套餐获取订单编号返回:"+result);
  1002. if(resJson.getIntValue("code") != 0){
  1003. return new SimpleJsonView(resJson);
  1004. }
  1005. JSONObject dataJson = resJson.getJSONObject("data");
  1006. outTradeNo = dataJson.getString("orderid");
  1007. }
  1008. SortedMap<String, String> map = new TreeMap<String, String>();
  1009. String spBillCreateIP = JsApiReqUtils.getRealIp(context.getRequest());
  1010. //初始化传入参数
  1011. BigDecimal dised = new BigDecimal(amount);
  1012. // BigDecimal dised = new BigDecimal(0.01); //测试价格0.01,待修改为totalAmount zby
  1013. BigDecimal diz = new BigDecimal(100);
  1014. // String key = "432fc0caf293dde237e574fbf057f056";
  1015. // String mch_id="QRA6072481C0003";
  1016. // String notify="http://xcwx.sharemao.cn/mifi/ylmembernotify.do";
  1017. String key = YL.key;
  1018. String mch_id=YL.mch_id;
  1019. String notify=YL.membernotify;
  1020. map.put("body", "收款码收款_商品");
  1021. map.put("charset", "UTF-8");
  1022. map.put("is_raw", "1");
  1023. map.put("mch_create_ip", spBillCreateIP);
  1024. map.put("mch_id", mch_id);
  1025. map.put("nonce_str", "str"+System.currentTimeMillis());
  1026. map.put("notify_url", notify);
  1027. map.put("out_trade_no", outTradeNo);
  1028. map.put("service", "pay.weixin.jspay");
  1029. map.put("sign_type", "MD5");
  1030. map.put("sub_openid", openid);
  1031. map.put("total_fee", String.valueOf(dised.multiply(diz).intValue()));
  1032. map.put("version", "2.0");
  1033. map.put("sign", sign(map,key));
  1034. String reqUrl = "https://qra.95516.com/pay/gateway";
  1035. log.info("reqUrl:" + reqUrl);
  1036. log.info("reqParams:" + XmlUtils.parseXML(map));
  1037. CloseableHttpResponse response = null;
  1038. CloseableHttpClient client = null;
  1039. String res = null;
  1040. Map<String, String> resultMap = null;
  1041. Map<String,String> payInfo = new HashMap<String,String>();
  1042. try {
  1043. HttpPost httpPost = new HttpPost(reqUrl);
  1044. StringEntity entityParams = new StringEntity(XmlUtils.parseXML(map), "utf-8");
  1045. httpPost.setEntity(entityParams);
  1046. httpPost.setHeader("Content-Type", "text/xml;utf-8");
  1047. client = HttpClients.createDefault();
  1048. response = client.execute(httpPost);
  1049. if (response != null && response.getEntity() != null) {
  1050. resultMap = XmlUtils.toMap(EntityUtils.toByteArray(response.getEntity()), "utf-8");
  1051. res = XmlUtils.toXml(resultMap);
  1052. log.info("请求结果:" + res);
  1053. if (!SignUtils.checkParam(resultMap, key)) {
  1054. res = "验证签名不通过";
  1055. } else {
  1056. if ("0".equals(resultMap.get("status")) && "0".equals(resultMap.get("result_code"))) {
  1057. String pay_info = resultMap.get("pay_info");
  1058. log.info("pay_info : " + pay_info);
  1059. res = "ok";
  1060. JSONObject resJson = JSONObject.parseObject(pay_info);
  1061. payInfo.put("appId", resJson.getString("appId"));
  1062. payInfo.put("timeStamp", resJson.getString("timeStamp"));
  1063. payInfo.put("nonceStr", resJson.getString("nonceStr"));
  1064. payInfo.put("package", resJson.getString("package"));
  1065. payInfo.put("signType", "MD5");
  1066. payInfo.put("paySign", resJson.getString("paySign"));
  1067. }
  1068. }
  1069. } else {
  1070. res = "操作失败";
  1071. }
  1072. } catch (Exception e) {
  1073. log.error("操作失败,原因:",e);
  1074. res = "系统异常";
  1075. } finally {
  1076. if (response != null) {
  1077. try {
  1078. response.close();
  1079. } catch (IOException e) {
  1080. // TODO Auto-generated catch block
  1081. e.printStackTrace();
  1082. }
  1083. }
  1084. if (client != null) {
  1085. try {
  1086. client.close();
  1087. } catch (IOException e) {
  1088. // TODO Auto-generated catch block
  1089. e.printStackTrace();
  1090. }
  1091. }
  1092. }
  1093. Map<String,String> result = new HashMap<String,String>();
  1094. if("ok".equals(res)){
  1095. result = payInfo;
  1096. }else{
  1097. result.put("status", "500");
  1098. result.put("msg", res);
  1099. }
  1100. return new SimpleJsonView(result);
  1101. }
  1102. // @Path(value="/buyYiZFMember.do")
  1103. // public SimpleJsonView buyYiZFMember(Context context)
  1104. // {
  1105. // Map<String,String> para = context.getParas();
  1106. //
  1107. // HttpSession session = context.getRequest().getSession();
  1108. // String appuid = String.valueOf(session.getAttribute("appuid"));
  1109. // String openid = (String) session.getAttribute("openid");
  1110. //
  1111. // String amount = ""; //订单价格
  1112. // String outTradeNo = ""; //订单ID
  1113. // String memid="";
  1114. //
  1115. // amount=para.get("amount");
  1116. // memid=para.get("memid");
  1117. // para.put("appuid", appuid);
  1118. // para.put("price", amount);
  1119. // para.put("memid", memid);
  1120. //
  1121. // /***********************下单,获取订单编号-BEGIN***********************/
  1122. // log.info("套餐购买,下单>>>"+para);
  1123. //
  1124. // GzhUtil.toM3PaySign(para);
  1125. // String resulta = GzhUtil.sendPost(Constants.m3IntAddr+"/package/buyMember.do", para);
  1126. // log.info(resulta);
  1127. // JSONObject resJsona = JSONObject.parseObject(resulta);
  1128. // log.info("购买套餐获取订单编号返回:"+resulta);
  1129. // if(resJsona.getIntValue("code") != 0){
  1130. // return new SimpleJsonView(resJsona);
  1131. // }
  1132. // JSONObject dataJson = resJsona.getJSONObject("data");
  1133. // outTradeNo = dataJson.getString("orderid");
  1134. //
  1135. // String spBillCreateIP = JsApiReqUtils.getRealIp(context.getRequest());
  1136. // Map<String,String> payInfo = new HashMap<String,String>();
  1137. // String res = null;
  1138. // try
  1139. // {
  1140. // //接口地址
  1141. // String api = "/yeepay/pre_pay";
  1142. // //具体接口的业务参数
  1143. // Map<String, Object> businessData = new HashMap<String, Object>();
  1144. // businessData.put("appId", Constants.appId);
  1145. // businessData.put("scene", "ONLINE");
  1146. // businessData.put("payWay", "WECHAT_OFFIACCOUNT");
  1147. // businessData.put("orderAmount", amount);
  1148. // businessData.put("channel", "WECHAT");
  1149. // businessData.put("userIp", spBillCreateIP);
  1150. // businessData.put("userId", openid);
  1151. // businessData.put("goodsName", "9"+outTradeNo);
  1152. //
  1153. // String jsonData = JSON.toJSONString(businessData);
  1154. // log.info(jsonData);
  1155. // PrivateKey merchantPrivateKey = YiZF.getPrivateKey(YiZF.MERCHANT_PRIVATE_KEY);
  1156. // PublicKey publicKey = YiZF.getPublicKey(YiZF.PUBLIC_KEY);
  1157. // OpenParam requestParam = YiZF.buildOpenParam(jsonData, YiZF.BUSINESS_SUBJECT_ID, merchantPrivateKey, publicKey);
  1158. //
  1159. // //接口返回基本结构:code、message、data(OpenParam)
  1160. // String responseJson = YiZF.doPost4String(YiZF.URL_HOST + api, JSON.toJSONString(requestParam),"Bearer "+YiZF.getToken5());
  1161. // log.info("url="+YiZF.URL_HOST + api+",Authorization="+"Bearer"+YiZF.getToken5()+",json="+JSON.toJSONString(requestParam));
  1162. // log.info("responseJson="+responseJson);
  1163. // com.alibaba.fastjson2.JSONObject result = JSON.parseObject(responseJson);
  1164. // OpenParam responseParam = JSON.parseObject(result.getString("data"), OpenParam.class);
  1165. // String responseBusinessData = YiZF.verifyAndDecrypt(responseParam, YiZF.BUSINESS_SUBJECT_ID, merchantPrivateKey, publicKey);
  1166. // log.info("responseBusinessData="+responseBusinessData);
  1167. //
  1168. //
  1169. // JSONObject resJson = JSONObject.parseObject(responseBusinessData);
  1170. // if(resJson.getString("code").equals("0000"))
  1171. // {
  1172. // res = "ok";
  1173. // resJson = JSONObject.parseObject(resJson.getString("data"));
  1174. // resJson = JSONObject.parseObject(resJson.getString("prePayTn"));
  1175. // payInfo.put("appId", resJson.getString("appId"));
  1176. // payInfo.put("timeStamp", resJson.getString("timeStamp"));
  1177. // payInfo.put("nonceStr", resJson.getString("nonceStr"));
  1178. // payInfo.put("package", resJson.getString("package"));
  1179. // payInfo.put("signType", resJson.getString("signType"));
  1180. // payInfo.put("paySign", resJson.getString("paySign"));
  1181. // }
  1182. // }
  1183. // catch(Exception e)
  1184. // {
  1185. // Tools.getExceptionMessage(e);
  1186. // }
  1187. //
  1188. // Map<String,String> result = new HashMap<String,String>();
  1189. // if("ok".equals(res)){
  1190. // result = payInfo;
  1191. // }else{
  1192. // result.put("status", "500");
  1193. // result.put("msg", res);
  1194. // }
  1195. // return new SimpleJsonView(result);
  1196. // }
  1197. @Path(value="/buyBalance.do")
  1198. public SimpleJsonView buyBalance(Context context)
  1199. {
  1200. Map<String,String> para = context.getParas();
  1201. HttpSession session = context.getRequest().getSession();
  1202. String openid = (String) session.getAttribute("openid");
  1203. para.put("openid", openid);
  1204. Map<String, Object> pkgInfo = (Map<String, Object>) session.getAttribute("pkgInfo");
  1205. para.put("packid", String.valueOf(pkgInfo.get("pkgid")));
  1206. GzhUtil.toM3Sign(para);
  1207. String result = GzhUtil.sendPost(Constants.m3IntAddr + "/payment/memPackRecharge.do", para);
  1208. log.info(result);
  1209. JSONObject resJson = JSONObject.parseObject(result);
  1210. int resCode = resJson.getIntValue("code");
  1211. if(resCode == 0)
  1212. {
  1213. return new SimpleJsonView("OK");
  1214. }
  1215. return new SimpleJsonView(resJson.getString("msg"));
  1216. }
  1217. @Path(value="/memPackRechargeToSpeedPack.do")
  1218. public SimpleJsonView memPackRechargeToSpeedPack(Context context)
  1219. {
  1220. Map<String,String> para = context.getParas();
  1221. HttpSession session = context.getRequest().getSession();
  1222. String openid = (String) session.getAttribute("openid");
  1223. para.put("openid", openid);
  1224. GzhUtil.toM3Sign(para);
  1225. String result = GzhUtil.sendPost(Constants.m3IntAddr + "/payment/memPackRechargeToSpeedPack.do", para);
  1226. log.info(result);
  1227. JSONObject resJson = JSONObject.parseObject(result);
  1228. int resCode = resJson.getIntValue("code");
  1229. if(resCode == 0)
  1230. {
  1231. return new SimpleJsonView("OK");
  1232. }
  1233. return new SimpleJsonView(resJson.getString("msg"));
  1234. }
  1235. public static String sign(SortedMap<String, String> parameters,String key){
  1236. StringBuffer sb = new StringBuffer();
  1237. Set es = parameters.entrySet();
  1238. Iterator it = es.iterator();
  1239. while (it.hasNext()) {
  1240. Map.Entry entry = (Map.Entry)it.next();
  1241. String k = (String)entry.getKey();
  1242. String v = (String)entry.getValue();
  1243. if (null != v && !"".equals(v)) {
  1244. sb.append(k + "=" + parameters.get(k) + "&");
  1245. }
  1246. }
  1247. sb.append("key="+key);
  1248. System.out.println(sb.toString());
  1249. try {
  1250. byte[] bytes = sb.toString().getBytes("utf-8");
  1251. return DigestUtils.md5Hex(bytes).toUpperCase();
  1252. } catch (UnsupportedEncodingException e) {
  1253. return "";
  1254. }
  1255. }
  1256. @Path(value="/notify.do")
  1257. public void notify(Context context)
  1258. {
  1259. Map<String,String> paramMap = Message2XmlUtil.xml2map(context.getRequest());
  1260. log.info("微信公众号回调:{"+paramMap+"}");
  1261. String result_code = paramMap.get("result_code").toString();
  1262. // 进行业务处理
  1263. if("SUCCESS".equals(result_code.toUpperCase()))
  1264. {
  1265. Map<String,String> para = new HashMap<String, String>();
  1266. String orderid = paramMap.get("out_trade_no").toString();
  1267. log.info("处理订单:orderno:"+orderid);
  1268. para.put("orderid", orderid);
  1269. GzhUtil.toM3Sign(para);
  1270. String result = GzhUtil.sendPost(Constants.m3IntAddr+"/payment/gzhRecharge.do", para);
  1271. log.info("下单购买后回调结果:"+result);
  1272. }
  1273. else
  1274. {
  1275. log.info("订单支付通知:签名错误");
  1276. return;
  1277. }
  1278. }
  1279. @Path(value="/ylnotify.do")
  1280. public void ylnotify(Context context)
  1281. {
  1282. Map<String,String> paramMap = Message2XmlUtil.xml2map(context.getRequest());
  1283. log.info("微信公众号回调:{"+paramMap+"}");
  1284. String result_code = paramMap.get("result_code").toString();
  1285. // 进行业务处理
  1286. if("0".equals(result_code) || "SUCCESS".equalsIgnoreCase(result_code))
  1287. {
  1288. Map<String,String> para = new HashMap<String, String>();
  1289. String orderid = paramMap.get("out_trade_no").toString();
  1290. String transactionId = paramMap.get("transaction_id").toString();
  1291. log.info("处理订单:orderno:"+orderid);
  1292. para.put("orderid", orderid);
  1293. para.put("transaction_id", transactionId);
  1294. GzhUtil.toM3Sign(para);
  1295. String result = GzhUtil.sendPost(Constants.m3IntAddr+"/payment/gzhRecharge.do", para);
  1296. log.info("下单购买后回调结果:"+result);
  1297. try {
  1298. context.getResponse().getWriter().write("success");
  1299. } catch (IOException e) {
  1300. e.printStackTrace();
  1301. }
  1302. }
  1303. else
  1304. {
  1305. log.info("订单支付通知:签名错误");
  1306. return;
  1307. }
  1308. }
  1309. @Path(value="/ylmembernotify.do")
  1310. public void ylmembernotify(Context context)
  1311. {
  1312. Map<String,String> paramMap = Message2XmlUtil.xml2map(context.getRequest());
  1313. log.info("微信公众号回调:{"+paramMap+"}");
  1314. String result_code = paramMap.get("result_code").toString();
  1315. // 进行业务处理
  1316. if("0".equals(result_code) || "SUCCESS".equals(result_code.toUpperCase()))
  1317. {
  1318. Map<String,String> para = new HashMap<String, String>();
  1319. String orderid = paramMap.get("out_trade_no").toString();
  1320. String transactionId = paramMap.get("transaction_id").toString();
  1321. log.info("处理订单:orderno:"+orderid);
  1322. para.put("orderid", orderid);
  1323. para.put("transaction_id", transactionId);
  1324. GzhUtil.toM3Sign(para);
  1325. String result = GzhUtil.sendPost(Constants.m3IntAddr+"/payment/memRecharge.do", para);
  1326. log.info("下单购买后回调结果:"+result);
  1327. try {
  1328. context.getResponse().getWriter().write("success");
  1329. } catch (IOException e) {
  1330. e.printStackTrace();
  1331. }
  1332. }
  1333. else
  1334. {
  1335. log.info("订单支付通知:签名错误");
  1336. return;
  1337. }
  1338. }
  1339. @Path(value="/ylmemberspeedpacknotify.do")
  1340. public void ylmemberspeedpacknotify(Context context)
  1341. {
  1342. Map<String,String> paramMap = Message2XmlUtil.xml2map(context.getRequest());
  1343. log.info("微信公众号回调:{"+paramMap+"}");
  1344. String result_code = paramMap.get("result_code").toString();
  1345. // 进行业务处理
  1346. if("0".equals(result_code) || "SUCCESS".equals(result_code.toUpperCase()))
  1347. {
  1348. Map<String,String> para = new HashMap<String, String>();
  1349. String orderid = paramMap.get("out_trade_no").toString();
  1350. String transactionId = paramMap.get("transaction_id").toString();
  1351. log.info("处理加速包购买订单:orderno:"+orderid);
  1352. para.put("orderid", orderid);
  1353. para.put("transaction_id", transactionId);
  1354. GzhUtil.toM3Sign(para);
  1355. String result = GzhUtil.sendPost(Constants.m3IntAddr+"/payment/speedPackRecharge.do", para);
  1356. log.info("加速包购买后回调结果:"+result);
  1357. try {
  1358. context.getResponse().getWriter().write("success");
  1359. } catch (IOException e) {
  1360. e.printStackTrace();
  1361. }
  1362. }
  1363. else
  1364. {
  1365. log.info("订单支付通知:签名错误");
  1366. return;
  1367. }
  1368. }
  1369. @Path("/getMember2.do")
  1370. public TextView getMember(Context context)
  1371. {
  1372. Map<String, String> para = context.getParas();
  1373. GzhUtil.toM3Sign(para);
  1374. String result = GzhUtil.sendPost(Constants.m3IntAddr + "/packkey/getMember.do", para);
  1375. if(!Tools.isEmpty(result))
  1376. {
  1377. JSONObject resJson = JSONObject.parseObject(result);
  1378. JSONArray dataJson = resJson.getJSONArray("data");
  1379. context.getRequest().setAttribute("cons", dataJson);
  1380. }
  1381. String devid =GzhUtil.getDevID(context.getRequest().getSession(), para);
  1382. context.getRequest().setAttribute("devid", devid);
  1383. HttpSession session = context.getRequest().getSession();
  1384. String phonenum = (String) session.getAttribute("phonenum");
  1385. context.getRequest().setAttribute("phonenum", phonenum);
  1386. String openid = (String) session.getAttribute("openid");
  1387. para.put("openid", openid);
  1388. GzhUtil.toM3Sign(para);
  1389. result = GzhUtil.sendPost(Constants.m3IntAddr + "/user/getBalance.do", para);
  1390. JSONObject resJson = JSONObject.parseObject(result);
  1391. int resCode = resJson.getIntValue("code");
  1392. if(resCode == 0)
  1393. {
  1394. JSONObject dataJson = resJson.getJSONObject("data");
  1395. String balance=dataJson.getString("balance");
  1396. String jine=dataJson.getString("jine");
  1397. String zsong=dataJson.getString("zsong");
  1398. context.getRequest().setAttribute("balance", balance);
  1399. context.getRequest().setAttribute("jine", jine);
  1400. context.getRequest().setAttribute("zsong", zsong);
  1401. } else
  1402. {
  1403. context.getRequest().setAttribute("balance", "0.00");
  1404. context.getRequest().setAttribute("jine", "0.00");
  1405. context.getRequest().setAttribute("zsong", "0.00");
  1406. }
  1407. result = GzhUtil.sendPost(Constants.m3IntAddr + "/package/getSPkgs.do", para);
  1408. if(!Tools.isEmpty(result))
  1409. {
  1410. resJson = JSONObject.parseObject(result);
  1411. JSONArray dataJson = resJson.getJSONArray("data");
  1412. log.info(dataJson);
  1413. context.getRequest().setAttribute("spkgs", dataJson);
  1414. }
  1415. return new TextView("/membersyb.jsp");
  1416. // return new TextView("/member.jsp");
  1417. }
  1418. @Path("/benefit.do")
  1419. public TextView benefit(Context context)
  1420. {
  1421. Map<String, String> para = context.getParas();
  1422. GzhUtil.toM3Sign(para);
  1423. String result = GzhUtil.sendPost(Constants.m3IntAddr + "/packkey/getMember.do", para);
  1424. if(!Tools.isEmpty(result))
  1425. {
  1426. JSONObject resJson = JSONObject.parseObject(result);
  1427. JSONArray dataJson = resJson.getJSONArray("data");
  1428. context.getRequest().setAttribute("cons", dataJson);
  1429. }
  1430. String devid =GzhUtil.getDevID(context.getRequest().getSession(), para);
  1431. context.getRequest().setAttribute("devid", devid);
  1432. HttpSession session = context.getRequest().getSession();
  1433. String phonenum = (String) session.getAttribute("phonenum");
  1434. context.getRequest().setAttribute("phonenum", phonenum);
  1435. String openid = (String) session.getAttribute("openid");
  1436. para.put("openid", openid);
  1437. GzhUtil.toM3Sign(para);
  1438. result = GzhUtil.sendPost(Constants.m3IntAddr + "/user/getBalance.do", para);
  1439. JSONObject resJson = JSONObject.parseObject(result);
  1440. int resCode = resJson.getIntValue("code");
  1441. if(resCode == 0)
  1442. {
  1443. JSONObject dataJson = resJson.getJSONObject("data");
  1444. context.getRequest().setAttribute("balance", dataJson.getString("balance"));
  1445. context.getRequest().setAttribute("jine", dataJson.getString("jine"));
  1446. context.getRequest().setAttribute("zsong", dataJson.getString("zsong"));
  1447. } else
  1448. {
  1449. context.getRequest().setAttribute("balance", "0.00");
  1450. context.getRequest().setAttribute("jine", "0.00");
  1451. context.getRequest().setAttribute("zsong", "0.00");
  1452. }
  1453. result = GzhUtil.sendPost(Constants.m3IntAddr + "/package/getSPkgs.do", para);
  1454. if(!Tools.isEmpty(result))
  1455. {
  1456. resJson = JSONObject.parseObject(result);
  1457. JSONArray dataJson = resJson.getJSONArray("data");
  1458. log.info(dataJson);
  1459. context.getRequest().setAttribute("spkgs", dataJson);
  1460. }
  1461. return new TextView("/benefit.jsp");
  1462. }
  1463. @Path("/benefitSubmit.do")
  1464. public TextView benefitSubmit(Context context)
  1465. {
  1466. Map<String, String> para = context.getParas();
  1467. HttpSession session = context.getRequest().getSession();
  1468. String openid = (String) session.getAttribute("openid");
  1469. para.put("openid", openid);
  1470. GzhUtil.toM3Sign(para);
  1471. String result = GzhUtil.sendPost(Constants.m3IntAddr + "/user/getBalance.do", para);
  1472. JSONObject resJson = JSONObject.parseObject(result);
  1473. int resCode = resJson.getIntValue("code");
  1474. if(resCode == 0)
  1475. {
  1476. JSONObject dataJson = resJson.getJSONObject("data");
  1477. context.getRequest().setAttribute("balance", dataJson.getString("balance"));
  1478. } else
  1479. {
  1480. context.getRequest().setAttribute("balance", "0.00");
  1481. }
  1482. para.forEach((k,v)->context.getRequest().setAttribute(k, v));
  1483. return new TextView("/benefitSubmitSyb.jsp");
  1484. // return new TextView("/benefitSubmit.jsp");
  1485. }
  1486. @Path(value="/submitorder.do")
  1487. public SimpleJsonView submitorder(Context context) throws Exception {
  1488. Map<String,String> para = context.getParas();
  1489. HttpSession session = context.getRequest().getSession();
  1490. String appuid = String.valueOf(session.getAttribute("appuid"));
  1491. String openid = (String) session.getAttribute("openid");
  1492. if(GzhUtil.isEmpty(appuid))
  1493. {
  1494. Map<String,String> result = new HashMap<String,String>();
  1495. result.put("status", "403");
  1496. result.put("msg", "请登录");
  1497. return new SimpleJsonView(result);
  1498. }
  1499. String amount=para.get("amount"); //订单价格
  1500. double af=Double.parseDouble(amount);
  1501. //低于1元不能充值
  1502. if(af<1)
  1503. {
  1504. Map<String,String> result = new HashMap<String,String>();
  1505. result.put("status", "500");
  1506. result.put("msg", "出错了");
  1507. return new SimpleJsonView(result);
  1508. }
  1509. String outTradeNo = ""; //订单ID
  1510. String notify=SybConstants.NOTFIY_PKG_URL;
  1511. int type = Integer.parseInt(para.get("type"));
  1512. log.info("type="+type);
  1513. if(type == 0)
  1514. {
  1515. Map<String, Object> pdtInfo = (Map<String, Object>) session.getAttribute("pdtInfo");
  1516. //amount = String.valueOf(pdtInfo.get("total"));
  1517. //amount=para.get("amount");
  1518. para.put("pdtid", String.valueOf(pdtInfo.get("pdtid")));
  1519. para.put("appuid", appuid);
  1520. para.put("num", String.valueOf(pdtInfo.get("num")));
  1521. para.put("price", amount);
  1522. /***********************下单,获取订单编号-BEGIN***********************/
  1523. log.info("设备购买,下单>>>"+para);
  1524. GzhUtil.toM3PaySign(para);
  1525. String result = GzhUtil.sendPost(Constants.m3IntAddr+"/device/buyPdts.do", para);
  1526. JSONObject resJson = JSONObject.parseObject(result);
  1527. log.info("购买设备获取订单编号返回:"+result);
  1528. if(resJson.getIntValue("code") != 0){
  1529. return new SimpleJsonView(resJson.getString("msg"));
  1530. }
  1531. JSONObject dataJson = resJson.getJSONObject("data");
  1532. outTradeNo = dataJson.getString("orderid");
  1533. }
  1534. else if(type == 1)
  1535. {
  1536. Map<String, Object> pkgInfo = (Map<String, Object>) session.getAttribute("pkgInfo");
  1537. //amount = String.valueOf(pkgInfo.get("price"));
  1538. //amount=para.get("amount");
  1539. para.put("pkid", String.valueOf(pkgInfo.get("pkgid")));
  1540. para.put("appuid", appuid);
  1541. para.put("price", amount);
  1542. para.put("ts", String.valueOf(pkgInfo.get("ts")));
  1543. /***********************下单,获取订单编号-BEGIN***********************/
  1544. log.info("套餐购买,下单>>>"+para);
  1545. GzhUtil.toM3PaySign(para);
  1546. String result = GzhUtil.sendPost(Constants.m3IntAddr+"/package/buyPkg.do", para);
  1547. JSONObject resJson = JSONObject.parseObject(result);
  1548. log.info("购买套餐获取订单编号返回:"+result);
  1549. if(resJson.getIntValue("code") != 0){
  1550. return new SimpleJsonView(resJson);
  1551. }
  1552. JSONObject dataJson = resJson.getJSONObject("data");
  1553. outTradeNo = dataJson.getString("orderid");
  1554. }
  1555. else if(type == 2)
  1556. {
  1557. amount=para.get("amount");
  1558. para.put("appuid", appuid);
  1559. para.put("price", amount);
  1560. //TODO pkgid pkgprice
  1561. para.put("openid", openid);
  1562. String pkgprice=para.get("pkgprice");
  1563. para.put("pkgprice", pkgprice);
  1564. /***********************下单,获取订单编号-BEGIN***********************/
  1565. log.info("钱包充值,下单>>>"+para);
  1566. GzhUtil.toM3PaySign(para);
  1567. String result = GzhUtil.sendPost(Constants.m3IntAddr+"/package/buyMember.do", para);
  1568. log.info(result);
  1569. JSONObject resJson = JSONObject.parseObject(result);
  1570. log.info("钱包充值获取订单编号返回:"+result);
  1571. if(resJson.getIntValue("code") != 0){
  1572. return new SimpleJsonView(resJson);
  1573. }
  1574. JSONObject dataJson = resJson.getJSONObject("data");
  1575. outTradeNo = dataJson.getString("orderid");
  1576. notify = SybConstants.NOTFIY_MEMBER_URL;
  1577. }
  1578. else if(type == 3)
  1579. {
  1580. amount=para.get("amount");
  1581. para.put("appuid", appuid);
  1582. para.put("price", amount);
  1583. /***********************下单,获取订单编号-BEGIN***********************/
  1584. log.info("加速包购买,下单>>>"+para);
  1585. GzhUtil.toM3PaySign(para);
  1586. String result = GzhUtil.sendPost(Constants.m3IntAddr+"/package/buySpeedPack.do", para);
  1587. log.info(result);
  1588. JSONObject resJson = JSONObject.parseObject(result);
  1589. log.info("购买加速包获取订单编号返回:"+result);
  1590. if(resJson.getIntValue("code") != 0){
  1591. return new SimpleJsonView(resJson);
  1592. }
  1593. JSONObject dataJson = resJson.getJSONObject("data");
  1594. outTradeNo = dataJson.getString("orderid");
  1595. notify = SybConstants.NOTFIY_SPEEDPACK_URL;
  1596. }
  1597. Map<String, String> result = new HashMap<String, String>();
  1598. result.put("status", "200");
  1599. result.put("amount", "amount");
  1600. result.put("notify", notify);
  1601. result.put("outTradeNo", outTradeNo);
  1602. return new SimpleJsonView(result);
  1603. }
  1604. /**
  1605. * test 用于养号,方便充值
  1606. */
  1607. @Path(value="/testsyb.do")
  1608. public TextView testsyb(Context context) throws Exception {
  1609. Map<String,String> para = context.getParas();
  1610. String appid = SybConstants.SYB_APPID;
  1611. String cusid = SybConstants.SYB_CUSID;
  1612. String version = SybConstants.VERSION;
  1613. String charset = "utf-8";
  1614. BigDecimal dised = new BigDecimal(String.valueOf(para.get("amt")));
  1615. BigDecimal diz = new BigDecimal(100);
  1616. String trxamt=dised.multiply( diz).toString();
  1617. String reqsn = System.currentTimeMillis()+"";
  1618. String returl = SybConstants.RET_URL;
  1619. String notify_url = SybConstants.NOTFIY_URL;
  1620. String body ="收款码收款_商品";
  1621. String remark ="收款码收款_商品";
  1622. String randomstr = String.valueOf(System.currentTimeMillis()) ;
  1623. String validtime = String.valueOf( SybConstants.VALID_TIME);
  1624. String signtype = SybConstants.SIGN_TYPE;
  1625. String appkey = SybConstants.SYB_RSACUSPRIKEY;
  1626. TreeMap<String,String> params = new TreeMap<String,String>();
  1627. params.put("appid", appid);
  1628. params.put("cusid", cusid);
  1629. params.put("version", version);
  1630. params.put("charset", charset);
  1631. params.put("trxamt", trxamt);
  1632. params.put("reqsn", reqsn);
  1633. params.put("randomstr", randomstr);
  1634. params.put("body", body);
  1635. params.put("validtime", validtime);
  1636. params.put("remark", remark);
  1637. params.put("returl", returl);
  1638. params.put("notify_url", notify_url);
  1639. params.put("signtype",signtype);
  1640. log.info("=================通联充值:"+params);
  1641. String sign = SybUtil.unionSign(params,appkey,SybConstants.SIGN_TYPE);
  1642. context.getRequest().setAttribute("appid", appid);
  1643. context.getRequest().setAttribute("cusid", cusid);
  1644. context.getRequest().setAttribute("version", version);
  1645. context.getRequest().setAttribute("charset", charset);
  1646. context.getRequest().setAttribute("trxamt", trxamt);
  1647. context.getRequest().setAttribute("reqsn", reqsn);
  1648. context.getRequest().setAttribute("randomstr", randomstr);
  1649. context.getRequest().setAttribute("body", body);
  1650. context.getRequest().setAttribute("validtime", validtime);
  1651. context.getRequest().setAttribute("remark", remark);
  1652. context.getRequest().setAttribute("returl", returl);
  1653. context.getRequest().setAttribute("notify_url", notify_url);
  1654. context.getRequest().setAttribute("signtype", signtype);
  1655. context.getRequest().setAttribute("sign", sign);
  1656. return new TextView("/sybpay.jsp");
  1657. }
  1658. @Path(value="/testwx.do")
  1659. public TextView testwx(Context context) throws Exception {
  1660. String wxCode = context.getParas().get("code");
  1661. Map<String, String> m = GzhUtil.getOpenId(wxCode, Constants.appId, Constants.appSecret);
  1662. String openid = m.get("openId");
  1663. context.getRequest().getSession().setAttribute("openid", openid);
  1664. context.getRequest().setAttribute("u", "/mifi/testwxpay.do");
  1665. return new TextView("/testwx.jsp");
  1666. }
  1667. @Path(value = "/testwxpay.do")
  1668. public SimpleJsonView testwxpay(Context context) throws Exception {
  1669. Map<String, String> result = new HashMap<String, String>();
  1670. String nonceStr = PaySign.getNonceStr();
  1671. String trxamt = String.valueOf(context.getParas().get("amt"));
  1672. BigDecimal dised = new BigDecimal(trxamt);
  1673. BigDecimal diz = new BigDecimal(100);
  1674. String outTradeNo = System.currentTimeMillis() + "";
  1675. String spBillCreateIP = JsApiReqUtils.getRealIp(context.getRequest());
  1676. String openid = context.getRequest().getSession().getAttribute("openid").toString();
  1677. JsApiReqData jsApiReqData = new JsApiReqData("收款码收款_商品", nonceStr, outTradeNo, dised.multiply( diz).intValue(), spBillCreateIP, openid, Constants.appId, Constants.mch_id, Constants.apikey);
  1678. 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");
  1679. log.info("微信支付充值=========" + info);
  1680. String prepay_id = "err";
  1681. StringBuffer sb = JsApiReqUtils.httpsRequest(Constants.unifiedorderurl, "POST", info);
  1682. Map<String, Object> payInfo = new HashMap<String, Object>();
  1683. if (!"".equals(sb.toString())) {
  1684. try {
  1685. //得到预支付ID,即prepay_id
  1686. Map<String, String> getMap = Message2XmlUtil.parseXml(new String(sb.toString().getBytes(), "utf-8"));
  1687. if (getMap.get("prepay_id") != null) {
  1688. //在return_code 和result_code都为SUCCESS的时候有返回
  1689. prepay_id = getMap.get("prepay_id");
  1690. log.info("订单:" + outTradeNo + ",请求微信支付!");
  1691. } else {
  1692. log.info("获取预支付ID失败,返回参数为>>>>>>" + getMap);
  1693. }
  1694. } catch (UnsupportedEncodingException e) {
  1695. log.info(Tools.getExceptionMessage(e));
  1696. }
  1697. Integer timeStramp = (int) (System.currentTimeMillis() / 1000);
  1698. JsApiToJsData jsApiToJsData = new JsApiToJsData(timeStramp, nonceStr, prepay_id, Constants.appId, Constants.apikey);
  1699. payInfo.put("appId", jsApiToJsData.getAppid());
  1700. payInfo.put("timeStamp", String.valueOf(jsApiToJsData.getTimeStamp()));
  1701. payInfo.put("nonceStr", jsApiToJsData.getNonce_str());
  1702. payInfo.put("package", "prepay_id=" + jsApiToJsData.getPrepay_id());
  1703. payInfo.put("signType", "MD5");
  1704. payInfo.put("paySign", jsApiToJsData.getSign());
  1705. log.info("支付信息:" + payInfo);
  1706. result.put("status", "200");
  1707. result.put("msg", "ok");
  1708. result.put("pay_info", JSON.toJSONString(payInfo));
  1709. } else {
  1710. log.info("支付失败,支付参数初始化失败>>>{" + sb + "}");
  1711. result.put("status", "500");
  1712. result.put("msg", "支付失败,支付参数初始化失败>>>{" + sb + "}");
  1713. }
  1714. return new SimpleJsonView(result);
  1715. }
  1716. /**
  1717. * 通联收款
  1718. */
  1719. @Path(value="/tosybpay.do")
  1720. public TextView tosybpay(Context context) throws Exception {
  1721. Map<String,String> para = context.getParas();
  1722. HttpSession session = context.getRequest().getSession();
  1723. String appuid = String.valueOf(session.getAttribute("appuid"));
  1724. String amount=para.get("amount"); //订单价格
  1725. String outTradeNo=para.get("outTradeNo"); //订单价格
  1726. String notify=para.get("notify"); //订单价格
  1727. //初始化传入参数
  1728. BigDecimal dised = new BigDecimal(amount);
  1729. // BigDecimal dised = new BigDecimal(0.01); //测试价格0.01,待修改为totalAmount zby
  1730. BigDecimal diz = new BigDecimal(100);
  1731. if("151992".equals(appuid)) {
  1732. dised = new BigDecimal(0.01);
  1733. }
  1734. // String result = GzhUtil.sendPost(Constants.m3IntAddr+"/payment/getPayType.do", para);
  1735. // log.info(result);
  1736. // JSONObject resJson = JSONObject.parseObject(result);
  1737. // log.info("钱包充值获取订单编号返回:"+result);
  1738. String appid = SybConstants.SYB_APPID;
  1739. String cusid = SybConstants.SYB_CUSID;
  1740. String version = SybConstants.VERSION;
  1741. String charset = "utf-8";
  1742. String trxamt=String.valueOf(dised.multiply(diz).intValue());
  1743. String reqsn = outTradeNo;
  1744. String returl = SybConstants.RET_URL;
  1745. String notify_url = notify;
  1746. String body ="收款码收款_商品";
  1747. String remark ="收款码收款_商品";
  1748. String randomstr = String.valueOf(System.currentTimeMillis()) ;
  1749. String validtime = String.valueOf( SybConstants.VALID_TIME);
  1750. String signtype = SybConstants.SIGN_TYPE;
  1751. String appkey = SybConstants.SYB_RSACUSPRIKEY;
  1752. // if(resJson.getIntValue("code") == 0){
  1753. // JSONObject dataJson = resJson.getJSONObject("data");
  1754. // appid = dataJson.getString("appid");
  1755. // cusid = dataJson.getString("mchid");
  1756. // appkey = dataJson.getString("prikey");
  1757. // }
  1758. TreeMap<String,String> params = new TreeMap<String,String>();
  1759. params.put("appid", appid);
  1760. params.put("cusid", cusid);
  1761. params.put("version", version);
  1762. params.put("charset", charset);
  1763. params.put("trxamt", trxamt);
  1764. params.put("reqsn", reqsn);
  1765. params.put("randomstr", randomstr);
  1766. params.put("body", body);
  1767. params.put("validtime", validtime);
  1768. params.put("remark", remark);
  1769. params.put("returl", returl);
  1770. params.put("notify_url", notify_url);
  1771. params.put("signtype",signtype);
  1772. log.info("=================签名参数:"+params);
  1773. String sign = SybUtil.unionSign(params,appkey,SybConstants.SIGN_TYPE);
  1774. context.getRequest().setAttribute("appid", appid);
  1775. context.getRequest().setAttribute("cusid", cusid);
  1776. context.getRequest().setAttribute("version", version);
  1777. context.getRequest().setAttribute("charset", charset);
  1778. context.getRequest().setAttribute("trxamt", trxamt);
  1779. context.getRequest().setAttribute("reqsn", reqsn);
  1780. context.getRequest().setAttribute("randomstr", randomstr);
  1781. context.getRequest().setAttribute("body", body);
  1782. context.getRequest().setAttribute("validtime", validtime);
  1783. context.getRequest().setAttribute("remark", remark);
  1784. context.getRequest().setAttribute("returl", returl);
  1785. context.getRequest().setAttribute("notify_url", notify_url);
  1786. context.getRequest().setAttribute("signtype", signtype);
  1787. context.getRequest().setAttribute("sign", sign);
  1788. return new TextView("/sybpay.jsp");
  1789. }
  1790. @Path(value="/sybpkgnotify.do")
  1791. public void sybpkgnotify(Context context) throws Exception {
  1792. log.info("充值套餐支付接收到通知");
  1793. Map<String, String[]> paramMap = context.getRequest().getParameterMap();
  1794. paramMap.forEach((key, value) -> log.info(key + ":" + value[0]));
  1795. // 进行业务处理
  1796. if(paramMap.get("outtrxid").length>0)
  1797. {
  1798. Map<String,String> para = new HashMap<String, String>();
  1799. String orderid = paramMap.get("outtrxid")[0];
  1800. // String transactionId = paramMap.get("transaction_id").toString();
  1801. log.info("处理订单:orderno:"+orderid);
  1802. para.put("orderid", orderid);
  1803. para.put("transaction_id", "");
  1804. // para.put("transaction_id", transactionId);
  1805. GzhUtil.toM3Sign(para);
  1806. String result = GzhUtil.sendPost(Constants.m3IntAddr+"/payment/gzhRecharge.do", para);
  1807. log.info("下单购买后回调结果:"+result);
  1808. try {
  1809. context.getResponse().getWriter().write("success");
  1810. } catch (IOException e) {
  1811. e.printStackTrace();
  1812. }
  1813. }
  1814. else
  1815. {
  1816. log.info("订单支付通知:签名错误");
  1817. return;
  1818. }
  1819. }
  1820. @Path(value="/sybmembernotify.do")
  1821. public void sybmembernotify(Context context)
  1822. {
  1823. log.info("充值钱包支付接收到通知");
  1824. Map<String, String[]> paramMap = context.getRequest().getParameterMap();
  1825. paramMap.forEach((key, value) -> log.info(key + ":" + value[0]));
  1826. // 进行业务处理
  1827. if(paramMap.get("outtrxid").length>0)
  1828. {
  1829. Map<String,String> para = new HashMap<String, String>();
  1830. String orderid = paramMap.get("outtrxid")[0];
  1831. log.info("处理订单:orderno:"+orderid);
  1832. para.put("orderid", orderid);
  1833. para.put("transaction_id", "");
  1834. GzhUtil.toM3Sign(para);
  1835. String result = GzhUtil.sendPost(Constants.m3IntAddr+"/payment/memRecharge.do", para);
  1836. log.info("下单购买后回调结果:"+result);
  1837. try {
  1838. context.getResponse().getWriter().write("success");
  1839. } catch (IOException e) {
  1840. e.printStackTrace();
  1841. }
  1842. }
  1843. else
  1844. {
  1845. log.info("订单支付通知:签名错误");
  1846. return;
  1847. }
  1848. }
  1849. @Path(value="/sybspeedpacknotify.do")
  1850. public void sybspeedpacknotify(Context context)
  1851. {
  1852. log.info("充值钱包支付接收到通知");
  1853. Map<String, String[]> paramMap = context.getRequest().getParameterMap();
  1854. paramMap.forEach((key, value) -> log.info(key + ":" + value[0]));
  1855. // 进行业务处理
  1856. if(paramMap.get("outtrxid").length>0)
  1857. {
  1858. Map<String,String> para = new HashMap<String, String>();
  1859. String orderid = paramMap.get("outtrxid")[0];
  1860. log.info("处理加速包购买订单:orderno:"+orderid);
  1861. para.put("orderid", orderid);
  1862. para.put("transaction_id", "");
  1863. GzhUtil.toM3Sign(para);
  1864. String result = GzhUtil.sendPost(Constants.m3IntAddr+"/payment/speedPackRecharge.do", para);
  1865. log.info("加速包购买后回调结果:"+result);
  1866. try {
  1867. context.getResponse().getWriter().write("success");
  1868. } catch (IOException e) {
  1869. e.printStackTrace();
  1870. }
  1871. }
  1872. else
  1873. {
  1874. log.info("订单支付通知:签名错误");
  1875. return;
  1876. }
  1877. }
  1878. }