Added method 1 (Tread) for asynchronous message sending by the thread to send the message tread.

Source: Internet
Author: User
Tags openid

Added method 1 (Tread) for asynchronous message sending by the thread to send the message tread.

@ RequestMapping (value = "order/updateOrder. do ") public String updateOrder (HttpServletRequest request, HttpServletResponse response) {final String ordId = request. getParameter ("ordId"); String proDesc = request. getParameter ("proDesc"); final String logisticnum = request. getParameter ("logisticnum"); final String logisticcompany = request. getParameter ("logisticcompany"); String stats = request. getParameter ("st Ats "); final String tranNum = request. getParameter ("tranNum"); final String openId = request. getParameter ("openId"); System. out. println ("order status stats:" + stats); System. out. println ("tranNum:" + tranNum); System. out. println ("openId:" + openId); System. out. println ("logisticnum:" + logisticnum); System. out. println ("logisticcompany:" + logisticcompany); GoodsOrder order = new GoodsOrder (); order. setOrdId (o RdId); order. setProDesc (proDesc); order. setLogisticnum (logisticnum); order. setLogisticcompany (logisticcompany); order. setrStatus (stats); // get the current time: millisecond long a = System. currentTimeMillis (); System. out. println ("a:" + a); try {// change the order status shopService. updateOrder (order); // if the order status changes from payment successful to delivered, a message is sent to the user. If (Integer. parseInt (stats) = 3) {// asynchronously sends the message new Thread () {public void run () {message. sendWxMessage (openId, tranNum, logisticcompany, logisticnum );}}. start (); // synchronously send a message // message. sendWxMessage (openId, tranNum, logisticcompany, logisticnum) ;}} catch (Exception e) {e. printStackTrace ();} // calculate the execution time of the try statement long B = System. currentTimeMillis (); System. out. println ("B:" + B); System. out. println ("B -A: "+ (B-a); return" redirect:/order/orderlist. do? CurrPage = 1 ";}

  

 

Package com. starcloud. helpapp. wxMessage. service;/***** Project name: eduappweb * Class Name: * class description: * Creator: Administrator * Creation Time: 02:53:01 * @ version 1.0 */public interface Message {/***** [brief description]: PUSH Message * [Detailed description]: ** @ param openId * @ param proName * @ param payenders * @ param phoneNum * @ param flag 1: Message 2: endorsement return message */public void sendWxMessage (String openId, String tranNum, String logisticcompany, String logisticnum );}

  

Package com. starcloud. helpapp. wxMessage. service. impl; import org. springframework. stereotype. service; import net. sf. json. JSONObject; import com. starcloud. helpapp. common. loger; import com. starcloud. helpapp. common. utils. tools; import com. starcloud. helpapp. wxMessage. connectionUrlUtil; import com. starcloud. helpapp. wxMessage. beans. msgTemplateBean; import com. starcloud. helpapp. wxMessage. common. constant; import co M. starcloud. helpapp. wxMessage. service. message; @ Service ("Message") public class MessageImpl implements Message {/***** [brief description]: PUSH Message * [Detailed description]: 1: change the order status to delivered ** @ param parameter */public void sendWxMessage (String openId, String tranNum, String logisticcompany, String logisticnum) {JSONObject parameters = new JSONObject (); msgTemplateBean = MsgTemplateBean. getMsgTemplageBean (tranNum, logisticcompany, Logisticnum); bean. setTouser (openId); parameters = JSONObject. fromObject (bean); System. out. println ("parameters:" + parameters. toString (); // else // {// proName rebate order // MsgforDistributeBean = MsgforDistributeBean. getMsgTemplageBean (payinvoke, phoneNum, proName); // bean. setTouser (openId); // parameters = JSONObject. fromObject (bean); //} Loger. logtxt ("WxMessage", "Send message" + parameters); String access_tok En = getAccess_token (); if (null! = Access_token) {String returnstr = ConnectionUrlUtil. sendPost (Constant. SEND_MESSAGEURL + "? Access_token = "+ access_token, parameters. toString (); try {JSONObject returnJson = JSONObject. fromObject (returnstr); if (0 = returnJson. getInt ("errcode") {Loger. logtxt ("WxMessage", "message sent successfully" + parameters);} else {Loger. logtxt ("WxMessage", "failed to send message" + parameters) ;}} catch (Exception e) {e. printStackTrace () ;}} else {// failed to send, failed to get token Loger. logtxt ("WxMessage", "failed to send the message because an error occurred while obtaining the access_token ");}}/** ** [Brief description]: Get access_token * [Detailed description]: ** @ return */public String getAccess_token () {String access_token = ""; // company's access_token String access_token_json = ConnectionUrlUtil. sendPost (Constant. TOKEN_URL, "grant_type = client_credential & appid =" + Constant. APP_ID + "& secret =" + Constant. APP_SECRET); if (Tools. isNotEmty (access_token_json) {JSONObject tokenJson = JSONObject. fromObject (access_token_json); If (null! = TokenJson & null! = TokenJson. get ("access_token") {// ACCESS_TOKEN access_token = tokenJson. getString ("access_token") ;}} return access_token ;}}

  

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.