ϵÁÐÎÄÕÂĿ¼
ÄÚÈݼò½é
ÀûÓù«ÖÚºÅ×÷ΪÈë¿Ú£¬Î¢ÐÅÅäÍøÔÉúAirkiss½çÃæ¿Éͨ¹ýJS-SDKÓÉ¡°Î¢ÐÅÄÚÍøÒ³£¨¼´ÔÚÊÖ»ú΢ÐÅAPPÄÚ´ò¿ªµÄÍøÒ³£©¡±µ÷Æð¡£±¾ÆªÎÒÃÇÀ´Á˽âһϡ°Î¢ÐÅÄÚÍøÒ³¡±½Ó¿Ú¿ª·¢£¬ÓÃC#ºǫ́´úÂëʵÏÖ΢ÐÅJS-SDK×¢ÈëÅäÖã¬ÒÔ¼°ÓÃÇ°¶ËJSµ÷ÓÃÏà¹Ø½Ó¿Ú¡£
΢ÐŽӿڿª·¢
΢ÐÅ×÷Ϊһ¿î¼´Ê±Í¨Ñ¶Èí¼þ£¬È´ÓÖ²»Ö»ÊÇÒ»¿î¼´Ê±Í¨Ñ¶Èí¼þ¡£Ëæ×Åʱ´úµÄ·¢Õ¹£¬Î¢ÐÅÒѾ³ÉΪһ¸öƽ̨¡¢Ò»ÖÖÉú»î·½Ê½¡£ÎÞÂÛÊÇ΢ÐÅÁÄÌ졢΢ÐÅÖ§¸¶»¹ÊÇÅóÓÑȦ£¬¶¼ÒѾÉø͸µ½ÁËÎÒÃÇÉú»îµÄ·½·½ÃæÃæ¡£¶ø΢ÐŵÄÇ¿´ó£¬»¹ÔÚÓÚËü¸ø¿ª·¢ÕßÌṩÁË´óÁ¿µÄ½Ó¿Ú£¨°üÀ¨Òƶ¯Ó¦Óá¢ÍøÕ¾ºÍ¹«Öںſª·¢£©£¬´ó´óËõ¶ÌÁËÓ¦ÓõĿª·¢ÖÜÆÚ£¬½µµÍÁË¿ª·¢ÄѶȣ¬¸ø¿ª·¢ÕßÌṩÁ˸ü¶àµÄ¿ÉÄÜ¡£
ʲôÊǽӿڣ¨API£©£¿
API£¨Application Programming Interface,Ó¦ÓóÌÐò±à³Ì½Ó¿Ú£©ÊÇһЩԤÏȶ¨ÒåµÄº¯Êý£¬Ä¿µÄÊÇÌṩӦÓóÌÐòÓ뿪·¢ÈËÔ±»ùÓÚijÈí¼þ»òÓ²¼þµÃÒÔ·ÃÎÊÒ»×éÀý³ÌµÄÄÜÁ¦£¬¶øÓÖÎÞÐè·ÃÎÊÔ´Â룬»òÀí½âÄÚ²¿¹¤×÷»úÖƵÄϸ½Ú¡£
˵¼òµ¥µã£¬½Ó¿Ú¾ÍÊDZðÈË×öºÃµÄ¹¦ÄÜ£¬ÎÒÃÇÖ±½ÓÓþÍÐÐÁË£¬²¢»ùÓÚÕâЩ»ù´¡¹¦ÄÜÍùÉÏÖ𲽴ÆðÎÒÃÇ×Ô¼º·á¸»¶à²ÊµÄÓ¦Óá£
Smart Config½Ó¿Ú
»Øµ½Ö÷½ÇSmart ConfigÉÏ£¬Ç°Ãæ˵µ½Smart ConfigÊÇͨ¹ýWiFiÄ£¿é£¨ÎÞÏßÍø¿¨£©Í¨¹ý¹ã²¥ºÍ×¥°üµÄ·½Ê½ÊµÏֵģ¬Òª¶ÔÊý¾ÝÖ¡½øÐвÙ×÷¡£¶øÕâЩÈç´Ëµ×²ã¡¢ÓëÓ²¼þ´ò½»µÀµÄÊÂΰ´óµÄ³ÌÐòÔ³Ôç¾Í×öºÃÁË£¬ÎÒÃDz»ÐèÒª¹ØÐľßÌåʵÏÖϸ½Ú£¨³ý·ÇÄãÏëÒª³ÉΪÍøÂç´óÅ££¬¶ø²»ÊÇʵÏÖÒ»¼üÅäÍø£©£¬¿ÉÒÔÖ±½ÓÄÃÀ´Óá£
½Ó¿ÚµÄÌṩ·½Ê½
ÎÒËùÁ˽⵽µÄ½Ó¿ÚÓÐHTTPºÍSDKÁ½ÖÖ£¬HTTP½Ó¿Ú»ùÓÚPOSTºÍGETÇëÇ󣬳£ÓÃJson¸ñʽ×Ö·û´®½øÐн»»¥£¬Ê¹Óüòµ¥µ«¹¦ÄÜÓÐÏÞ¡£¶øͨ¹ýµ¼ÈëÍⲿSDKµÄ·½Ê½¿ÉÒÔ¸üÖ±½ÓʹÓøüÇ¿´óµÄ½Ó¿Ú¡£ÀýÈçÕâ´ÎÒªÓõÄAirkiss½Ó¿Ú¡ª¡ª°üÀ¨ÔËÐÐÔÚESP8266Ä£¿éµÄAirKiss2.0¿â£¬ÒÔ¼°ÔËÐÐÔÚÊÖ»ú΢ÐŵÄJS-SDK£¬Í¨¹ý΢ÐÅAPPÈ¥²Ù¿ØÊÖ»úÎÞÏßÍø¿¨£¨ÔÚ΢ÐÅÄÚÖÃä¯ÀÀÆ÷ÔËÐеÄJS´úÂë×ÔÈ»¾ÍÄÜÖ±½Óµ÷ÓÃ΢ÐÅAPPµÄ¹¦ÄÜ£©¡£
Õâ´ÎÒ»¼üÅäÍøʹÓõ½Î¢ÐÅÌṩµÄ½Ó¿ÚÖ÷ÒªÓÐ΢ÐŹ«ÖÚƽ̨½Ó¿Ú¡¢Î¢ÐÅJS-SDK¡¢JS-API¡£
΢ÐÅ¿ª·¢µÄÕýÈ·×ËÊÆ
ÕýËùν¡°¹¤ÓûÉÆÆäʱØÏÈÀûÆäÆ÷¡±£¬Ò»Ð©ºÃÓõŤ¾ß¿ÉÒÔÈÃÎÒÃǸüÓä¿ìµÄ´ò´úÂë¡¡
1¡¢Ê¹ÓÃngrokʵÏÖÓòÃûÄÚÍøÓ³Éä
ngrok ÊÇÒ»¿îÓÃgo ÓïÑÔ¿ª·¢µÄ¿ªÔ´Èí¼þ£¬ËüÊÇÒ»¸ö·´Ïò´úÀí£¬Í¨¹ýÔÚ¹«¹²µÄ¶ËµãºÍ
±¾µØÔËÐеÄWeb ·þÎñÆ÷Ö®¼ä½¨Á¢Ò»¸ö°²È«µÄͨµÀ¡£
ʹÓÃJS-SDKÐèÒªÔÚ΢ÐŹ«ÖںŰó¶¨JS½Ó¿Ú°²È«ÓòÃû£¬ÇÒ²»Ö§³ÖIPµØÖ·¼°¶Ë¿ÚºÅ£¬ËùÒÔÎÒÃÇÐèÒªÒ»¸öÓòÃûÀ´·ÃÎÊÒ³Ãæ¡£ÄѵÀÓÖÒª»¨ÖؽðÂò·þÎñÆ÷ºÍÓòÃû£¿²»²»²»£¬ÕâÑù¾ÍÌ«Âé·³ÁË¡£¶Ô£¬²»ÊÇÇ®µÄÎÊÌ⣬ÊÇÂé·³¡£ÄѵÀÄãÿ´Î¸ÄÍê´úÂ붼ҪÖØв¿ÊðÒ»±éÔÙÀ´¿´½á¹û£¿ÎÒÃÇÏÖÔÚ¿ÉÊÇÔÚ¿ª·¢µ÷ÊÔ°¡¡¡
Èç¹ûÄÜ°ÑÔÚ±¾µØÆô¶¯µ÷ÊÔµÄÍøÒ³Ó³Éäµ½ÍâÍøµÄÓòÃûÉϾͺÃÁË£¬ËùÒÔ¾ÍÓÐÁËngrokÕâ¸öÉñÆ÷£¬²»µ«ÄÜÔÚÍâÍø·ÃÎÊ£¬¶øÇÒ»¹ÓÐÓòÃû£¡ÔÚ¿ª·¢Ê±Å¼µÃQQä¯ÀÀÆ÷ÍŶӷþÎñÆ÷°æµÄngrok£¬³´¼¦ºÃÓã¬ÍƼö´ó¼ÒʹÓᣰ´Õս̳Ì[¹¤¾ß] ʹÓà Ngrok À´°ïÖúÄãʵÏÖ±¾»úÍâÍø·ÃÎÊÏÈ°ÑngrokÏÂÔØ¡¢ÅäÖúᣠÏÂÔØngrok.exeÎļþ£¬²¢ÔÚͬĿ¼Ï´´½¨ ngrok.conf ÅäÖÃÎļþ£¬²¢¸ù¾ÝÐèÒª¸ü¸ÄÅäÖÃÎļþ¡£
trust_host_root_certs: false
server_addr: proxy.qqbrowser.cc:4443
inspect_addr: 0.0.0.0:4040
tunnels:
wechat:
subdomain: shaoguoji
proto:
http: 127.0.0.1:44073
¸´ÖÆ´úÂë
ÎÒµÄ ngrok.conf ÎļþÖÐÅäÖÃÁËÒ»¸öÃûΪ¡°wechat¡±µÄÓ³É䣬ÓòÃûΪ¡°shaoguoji¡±£¬Ö¸Ïò±¾µØ£¨127.0.0.1Ϊ±¾»úµØÖ·£©µÄ44073¶Ë¿Ú¡£
±£´æÅäÖÃÎļþ£¬ÔÚcmdÃüÁîÐд°¿Ú½øÈëngrokËùÔÚĿ¼£¨ÎÒµÄÔÚC:\ngrok£©£¬ÇÃÈë ngrok start wechat ÃüÁîÔËÐÐngrok¿ªÊ¼ÓòÃûÓ³É䣬µÃµ½µÄÓòÃû shaoguoji.proxy.qqbrowser.cc ¾Í¿ÉÒÔÓÃÀ´¿ª·¢À²¡£
Õ⻹ûÍêÄØ£¬µÈÏ»¹ÒªÔÙÐÞ¸ÄÅäÖ㬽«ngrokÖ¸ÏòÍøÕ¾Æô¶¯µÄ¾ßÌå¶Ë¿Ú²ÅÄܽøÐÐÍâÍø·ÃÎÊ¡£
×¢£º²»ÖªµÀʲôÔÒò£¬Õâ¸ö°æ±¾µÄngrok³¤Ê±¼äÔËÐлá×Ô¶¯Í˳ö£¬Ã¿´Î¶¼ÒªÊÖ¶¯ÔÙÔËÐУ¬ÓôÃÆ¡¡
2¡¢Î¢ÐŽӿڲâÊÔºÅÉêÇë
¼ÈÈ»Êǹ«Öںſª·¢£¬ºÃÏñ¡¡ÏȵÃÓÐÒ»¸ö¹«Öںţ¿
3¡¢Ê¹ÓÃ΢ÐÅWeb¿ª·¢Õß¹¤¾ßµ÷ÊÔÍøÒ³
µ÷ÓÃJS-SDKµÄÒ³ÃæÒªÔÚ΢ÐÅÄÚ´ò¿ª²ÅÓÐЧ£¬ÓÉÓÚÿ´ÎÓÃÊÖ»úµ÷ÊԵĻ°ÂÔÏÔ·±ËöÓë²»±ã£¬µ÷ÊÔÐÅÏ¢Ò²²»È«Ãæ¡£ÓÚÊÇ΢ÐŹٷ½ÌṩÁË¡°Web¿ª·¢Õß¹¤¾ß¡±£¬Ï൱ÓÚPC¶ËµÄÒ»¸ö΢ÐÅ¿Í»§¶ËÄ£ÄâÆ÷ÁË£¨ä¯ÀÀÆ÷£©£¬Í¬ÑùÒ²¿ÉÒÔɨÂëµÇ¼¡£
4¡¢Ëæʱ²éÔÄ΢ÐŹٷ½¿ª·¢ÕßÎĵµ
ÎÒ¸öÈËÊǺܲ»ÉÆÓÚ¿´Îĵµ¿ª·¢µÄ£¬¶ÔÎĵµÒ²·Ç³£¿Ö¾å¡£µ«Ç벻ҪѧÎÒ£¡ºÜ¶àʱºòÔÚÍøÉÏÕÒÁËÒ»´ó¶ÑÎÄÕ»òÊÓƵ½Ì³ÌÀ´¿´£¬×îºó²Å·¢ÏÖÎĵµÐ´×ÅÇåÇå³þ³þÄØ¡¡ËùÒÔ£¬Óöµ½ÈκÎÎÊÌâÎñ±ØÏȲéÔÄÎĵµ¡£
΢ÐŹ«ÖÚƽ̨¿ª·¢¡ª¡ª×Ô¶¨Òå²Ëµ¥
Óеã±êÌâµ³ÁË£¬Æäʵ΢ÐŹ«ÖںŲ¢²»ÊÇÖ÷½Ç£¬Ö»ÊÇÔÚºǫ́ÑéÖ¤Ò»ÏÂJS°²È«ÓòÃû¡¢ÔÚ¹«ÖںŽçÃæÌṩһ¸ö²Ëµ¥×÷ΪÍøÒ³Èë¿Ú½ö´Ë¶øÒÑ£¨¡°Î¢ÐÅÄÚÍøÒ³¡±ÒªÇóÔËÐÐÔÚ΢ÐÅAPPÄÚÖÃä¯ÀÀÆ÷ÖУ©¡£Ö±½ÓÔÚ΢ÐÅÖеãurl´ò¿ªÒ³ÃæÒ²ÊÇ¿ÉÒԵģ¬Ö»²»¹ý¹«ÖÚºÅÌṩÁËÒ»¸ö¹Ì¶¨¿É·¢²¼µÄ¡¢¸üÒ×ÓõÄÈë¿Ú¡£ÎÒÃÇÖ»Óõ½Á˹«ÖںŵIJ˵¥¹¦ÄÜ£¬µ«²¢²»Òâζ×ÅÕâ¾ÍÊǹ«Öںſª·¢µÄÈ«²¿£¬»ùÓÚÏûÏ¢¡¢ËزĺÍÓû§¹ÜÀíµÄ½Ó¿Ú¿ª·¢²ÅÊǹ«Öںſª·¢µÄ¾«Ë裬±¾ÎÄÖصãÊÇ΢ÐÅÄÚÍøÒ³¿ª·¢ËùÉæ¼°µ½µÄJS-SDKºÍÓëÓ²¼þÏà¹ØµÄJSAPIµÄʹÓá£
ÀûÓá°½Ó¿ÚÔÚÏßµ÷ÊÔ¹¤¾ß¡±×Ô¶¨Òå²Ëµ¥
ÊÖ»úɨÂë¹Ø×¢¹Ø×¢¹«Öںźó·¢ÏÖ¿Õ¿ÕÈçÒ²£¬ÄÇÏȼӸö²Ëµ¥ÊÔһϰɣ¡ÒòΪ²Ëµ¥²»ÐèÒª¾³£¸ü¸Ä£¬¿ÉÒÔÓÃ΢ÐŹٷ½ÌṩµÄ¡°½Ó¿ÚÔÚÏßµ÷ÊÔ¹¤¾ß¡±µ÷ÓÃ×Ô¶¨Òå²Ëµ¥½Ó¿Ú£¬Îª¹«ÖÚºÅÌí¼Ó²Ëµ¥£¬ÃâÈ¥×Ô¼ºÐ´ºǫ́´úÂë¡£
×¢£º¶ÔÓÚ³£¹æ¹«ÖÚºÅÓû§£¬¿ÉÖ±½ÓÔÚºǫ́¹ÜÀíÒ³ÃæÔö¼Ó²Ëµ¥£¬¶ø²âÊÔºÅûÓд˹¦ÄÜ¡£
ͬÑùÔÚ΢ÐŹ«ÖÚƽ̨¿ª·¢ÕßÎĵµ×ó²àĿ¼¡°¿ªÊ¼¿ª·¢¡±ÏµĽӿÚÔÚÏßµ÷ÊÔÖдò¿ª½Ó¿Úµ÷ÊÔÒ³Ã棬ĬÈÏÊÇ»ñÈ¡tokenµÄ½Ó¿Ú£¬°Ñ¹«Öںźǫ́µÄ appID ºÍ appsecret ¸´ÖÆÌîµ½½Ó¿Ú²ÎÊýÁбíÊäÈë¿ò£¬µã»÷¡°¼ì²éÎÊÌ⡱°´Å¥»ñÈ¡token¡£ ÏÂÃæ·µ»ØµÄ¾ÍÊǵ÷Óýá¹ûÁË£¬°üº¬Ò»Ð©ÏàÓ¦ÐÅÏ¢£¬ÆäÖÐ access_token ºóµÄÒ»³¤´®¾ÍÊÇ»ñÈ¡µ½µÄtokenÁË£¬Ñ¡Öи´ÖÆÏÂÀ´¡£
tokenÊÇËùÓнӿڵ÷ÓõĻù´¡£¬ÓÐÁËtoken¾Í¿ÉÒÔµ÷ÓÃÆäËû½Ó¿ÚÁË¡£ÔÚ¡°½Ó¿ÚÀàÐÍ¡±ÏÂÀ¿òÖÐÑ¡Ôñ¡°×Ô¶¨Òå²Ëµ¥¡±£¬ÌîÈë¸Õ¸Õ»ñÈ¡µ½µÄtoken£¬²¢¸ù¾Ý×Ô¶¨Òå²Ëµ¥´´½¨½Ó¿ÚÎĵµÕÕºù«»Æ°ÌîÈëJson¸ñʽµÄ²ÎÊýÌ壬µã»÷¡°¼ì²éÎÊÌ⡱°´Å¥µ÷Óýӿڣ¬Èôµ÷Óóɹ¦»á·µ»Ø¡°Request successful¡±µÄÌáʾÐÅÏ¢¡£ { "button": [ { "type": "view", "name": "´ò¿ª°Ù¶È", "url": "https://www.baidu.com/" } ]}
ÊÖ»úɨÂë¹Ø×¢²âÊԺţ¬¿ÉÒÔ¿´µ½ÓÐÁËÒ»¸ö¡°´ò¿ª°Ù¶È¡±µÄ²Ëµ¥£¬µã½øÈ¥¾ÍÊÇÊìϤµÄ°Ù¶ÈÒ³Ã棬Ҳ¾ÍÊÇ˵ÎÒÃÇÖªµÀÈçºÎÔÚ¹«ÖںŲ˵¥´ò¿ªÍøÒ³ÁË£¡
΢ÐÅÍøÒ³¿ª·¢¡ª¡ªJS-SDK
΢ÐÅJS-SDKÊÇʹÓÃJSAPIµÄ»ù´¡£¬±ØÐëÁ˽âпò¼ÜµÄ»ù±¾Ó÷¨£¬Èçwx.configº¯ÊýºÍwx.readyº¯Êý£¬ÕâÊÇËùÓÐJSAPIʹÓõÄÇ°Ìá¡£
ÏëҪʹÓÃJSAPIʵÏÖһ΢ÐÅÅäÍø£¬ÏÈÒª¿ç¹ýJS-SDKÕâ×ùСɽÇð¡£À´¿´¿´JS-SDKµÄÎĵµËµÃ÷£º
΢ÐÅJS-SDKÊÇ΢ÐŹ«ÖÚƽ̨ÃæÏòÍøÒ³¿ª·¢ÕßÌṩµÄ»ùÓÚ΢ÐÅÄÚµÄÍøÒ³¿ª·¢¹¤¾ß°ü¡£
ͨ¹ýʹÓÃ΢ÐÅJS-SDK£¬ÍøÒ³¿ª·¢Õ߿ɽèÖú΢ПßЧµØʹÓÃÅÄÕÕ¡¢Ñ¡Í¼¡¢ÓïÒô¡¢Î»ÖõÈÊÖ»úϵͳµÄÄÜÁ¦£¬Í¬Ê±¿ÉÒÔÖ±½ÓʹÓÃ΢ÐÅ·ÖÏí¡¢É¨Ò»É¨¡¢¿¨È¯¡¢Ö§¸¶µÈ΢ÐÅÌØÓеÄÄÜÁ¦£¬ÎªÎ¢ÐÅÓû§Ìṩ¸üÓÅÖʵÄÍøÒ³ÌåÑé¡£
Ç°¶ËÓëºó¶ËµÄÅäºÏ
¼ÈÈ»JS-SDKÊÇ»ùÓÚJSµÄ½Ó¿Ú£¬ÄÇÀíÂÛÉÏÀ´ËµÊÇ´¿Ç°¶ËµÄ¶«Î÷£¬Óþ²Ì¬Ò³ÃæºÍJSÓ¦¸Ã¾ÍÄÜʤÈΡ£µ«Î¢ÐŶԽӿڰ²È«ÐÔÊÇÓÐÒªÇóµÄ£¬ÐèÒªtokenºÍticketÈÏÖ¤£¬¶øÕâЩ²Ù×÷Èç¹û¶¼·Åµ½Ç°¶ËJSÖÐÆñ²»Êǽ«×Ô¼ºµÄƾ֤¹«Ö®ÓÚÖÚÁË£¿ÄãÒ²²»Ïë±ðÈË°´¸öF12¾ÍÇáÇáËÉËÉαÔìÄãµÄÉí·Ý°É¡¡ËùÒÔµ½ÕâÀï˼·ºÜÇå³þÁË£º·Ö¹¤ºÏ×÷£¬Ç°¶Ë¸ºÔðJS-SDK½Ó¿Úµ÷Ó㬺ó¶ËÌṩ½Ó¿Úµ÷ÓÃËùÐèµÄƾ֤²ÎÊý¡£
¿Éµ±³õ¾ÍËãµÀÀí¶¼¶®£¬¶ÔÓÚ»¹ÔÚWeb¿ª·¢ÃÅÍâÅÇ»²µÄÎÒ£¬Ò²ÊÇÊÖ×ãÎÞ´ëµØÉÏÍøÕÒ±ðÈ˵Ädemo£¬µ«ÏÂÔØ·¢ÏÖ²»ÊDz»»áÓᢲ»ÊÊÓþÍÊÇÓò»ÁË¡£ÎÞÄÎÖ®ÏÂÖ»ºÃÏòʵÑéÊҵĴóÉñÇóÖú£¬Ëû¶þ»°²»ËµÈÓ¸øÁËÎÒÒ»¸ö½Ì³ÌÊÓƵ£¬¿´ÍêÖ®ºóÖØ£¨zhao£©»ñ£¨ban£©Ð£¨dai£©Éú£¨ma£©¡£Èç¹ûÄãÒ²´òËãÓÃC#ʵÏÖ£¬¿ÉÒÔ¿´¿´Õâ¸öÊÓƵ£ºÎ¢ÐÅÄÚÍøÒ³¿Î³Ì£¨ÌáÈ¡Â룺r5fb£© Visual Studioн¨ASP.Net¿ÕÍøÕ¾
ÔÚVS£¨ÎÒÓõÄÊÇVS2015£©ÖÐн¨Ò»¸öASP.Net¿ÕÍøÕ¾£¬ÕÒµ½½â¾ö·½°¸¹ÜÀíÆ÷ÏîÄ¿Ãû³Æ£¬ÓÒ¼üÌí¼ÓÒ»¸öWebFormÒ³Ã棬ÃüÃûΪ Index.aspx £¬ÍùÀïÃæд¸ö¡°Hello World¡±×ö²âÊÔÓá£
°´ÏÂCtrl+F5·Çµ÷ÊÔÔËÐÐÍøÒ³£¬¿ÉÒÔ¿´µ½ÎÒÃǵġ°Hello World¡±£¬×¢Òâµ½ä¯ÀÀÆ÷µØÖ·À¸µÄµØÖ·Ö÷»úΪ localhost £¬¶Ë¿ÚºÅΪ 44073 £¬Õâ¸ö¶Ë¿ÚºÅÊDz»ÊǺÜÊìϤ£¿Ã»´í£¬¾ÍÊÇÇ°ÃæÅäÖÃngrokʱÓòÃûÖ¸ÏòµÄ¶Ë¿ÚºÅ£¡ÎÒÊÇÔç¾ÍÖªµÀÁË£¬µ«ÏÖÔÚÄãÓ¦¸Ã¸ù¾ÝVSÆô¶¯µÄʵ¼Ê¶Ë¿ÚºÅ»ØÍ·ÐÞ¸ÄngrokÅäÖÃÎļþÁË¡£
×¢£ºVSÿ´ÎµÄÆô¶¯¶Ë¿ÚºÅ¿ÉÄÜ»¹»á±ä£¡²»Í¬°æ±¾µÄVSÉèÖ÷½·¨Ò²ÓÐÇø±ð¡£Ö»Òª¼ÇסÁ½µã£º1¡¢È·±£VSÿ´ÎÆô¶¯ÍøÕ¾µÄ¶Ë¿ÚºÅÊǹ̶¨µÄ¡£2¡¢ÅäÖÃngrokÖ¸ÏòÕâ¸ö¶Ë¿ÚºÅ¡£
ÖØÐÂÅäÖúÃngrokºó£¬ËùÒÔÄãÒÔΪֻҪ°ÑµØÖ·´Ó http://localhost:44073/Index.aspx ±ä³É http://shaoguoji.proxy.qqbrowser.cc/Index.aspx ¾ÍÄܳɹ¦´ÓÍâÍøͨ¹ýÓòÃû·ÃÎÊ£¿¹þ¹þ¹þ£¬ÎÒµ±³õÒ²ÊÇÕâôÈÏΪµÄ£¬Ò²³É¹¦ÁË£¡Êǵģ¬ÔÚʵÑéÊÒÓÃVS2010ÄÜÖ±½ÓÓ³É䣬µ«×Ô¼ºµçÄÔµÄVS2015¾Í²»ÐУ¬»áÕÒ²»µ½ÍøÒ³¡£Ï¹ÅªÒ»Í¨Ò²Ã»Õû³ö¸öËùÒÔÈ»£¬Ã»Ï뵽Ļºó¾¹Òþ²Ø×Å¡°localhostÓë127.0.0.1¡±µÄ´ó¿Ó¡£ ×¢£ºÈç¹ûÄãÖ±½Ó°Ñ¡°localhost:¶Ë¿ÚºÅ¡±Ìæ»»³ÉngrokÓòÃû¾ÍÄÜ·ÃÎÊÁË£¬ÄÇÄãÈËÆ·ÕæºÃ£¬²»ÓÃÕÛÌÚ¡£µ±È»£¬Ò²ÉÙÁËÒ»´Îѧϰ»ú»á¡£
С²åÇú¡ª¡ª¶Ô¡°localhostÓë127.0.0.1¡±µÄ˼¿¼¡
ngrokÓ³Éäµ½µÄIPÊÇ 127.0.0.1:44073 £¬¶øÆô¶¯ºóµØÖ·À¸ÉϵÄÊÇ http://localhost:44073/Index.aspx £¬³¢Ê԰ѵØÖ·»»³É http://127.0.0.1:44073/Index.aspx £¬ÄÉÄ᣿¾ÓÈ»²»ÐУ¡ÕâÁ©»õÄѵÀ²»ÊÇÒ»»ØÊÂô£¿£¿£¿ÓÚÊÇ¡¡ÎÒ¿ªÊ¼²é£¨huai£©ÕÒ£¨yi£©×Ê£¨ren£©ÁÏ£¨sheng£©¡£¡£¡£ Ò»·¬²éÕÒ¹ýºó£¬·¢ÏÖÆäʵ¡°localhost¡±Ö»ÊÇÒ»¸öÃû×Ö£¨ÓòÃû£©£¬Ö»ÓÐͨ¹ýhostÎļþ±»½âÎö³É¡°127.0.0.1¡±Ê±Á½Õ߲ŵȼۣ¬Ò»Î»ÍøÓÑ·ÖÎöµÄºÜºÃ£º
ÓÐÈË»á˵ÊDZ¾µØip£¬ÔøÓÐÈË˵£¬ÓÃ127.0.0.1±ÈlocalhostºÃ£¬¿ÉÒÔ¼õÉÙÒ»´Î½âÎö¡£
Ëä˵Ч¹û¿´ÆðÀ´ÊÇÒ»ÑùµÄ£¬¶¼ÊDZ¾µØIP£¬µ«Êµ¼ÊÉÏÇø±ðºÜ´ó£ºLocalhostµÄÒâ˼ÊDZ¾µØ·þÎñÆ÷£¬¶ø127.0.0.1ÊDZ¾»úµØÖ·£¬ËûÃǵĹØϵÊÇͨ¹ý²Ù×÷ϵͳÖеÄhostsÎļþ£¬½«Localhost½âÎöΪ127.0.0.1¡£¶øʵ¼Ê¹¤×÷ÖУ¬LocalhostÊDz»¾¹ýÍø¿¨´«ÊäµÄ£¬ËùÒÔ£¬Ëü²»ÊÜÍøÂç·À»ðǽºÍÓëÍø¿¨Ïà¹ØµÄÖÖÖÖÏÞÖÆ£»¶ø127.0.0.1ÔòҪͨ¹ýÍø¿¨´«ÊäÊý¾Ý£¬ÊDZØÐëÒÀÀµÍø¿¨µÄ¡£ÕâÒ»µãÊÇËüÃÇ×î´óµÄÇø±ð¡£ Ò»°ãÉèÖóÌÐòʱ£¬±¾µØ·þÎñÓÃLocalhostÊÇ×îºÃµÄ£¬Localhost²»»á½âÎö³ÉIP£¬Ò²²»»áÕ¼ÓÃÍø¿¨¡¢ÍøÂç×ÊÔ´¡£ÓÐʱºòÓÃLocalhost¿ÉÒÔ£¬µ«ÓÃ127.0.0.1¾Í²»¿ÉÒÔµÄÇé¿ö¾ÍÊÇÔÚÓÚ´Ë¡£
ÔÙ×ÐϸÏëÏë¾Í¶®ÁË£ºÔÀ´VS×Ô´øµÄIIS Express·þÎñÆ÷Ö»ÊÇ°ÑÍøÕ¾²¿Êðµ½ÁË localhost Ãû³Æ£¨Ö»ÊÇÃûÒåÉϵÄÖ÷»ú£©Ï£¬ÇÒÄÚ²¿Ã»ÓÐÓ³Éäµ½ 127.0.0.1 Õâ¸öIPÉÏ£¨Tomcat¾ÍÓУ¬Í»È»¸Ð¾õJavaºÃºÃŶ~£©£¬ÊÇÁ½¸ö²»Í¬µÄÊÀ½ç¡£µ«¼´Ê¹°ÑngrokÖ¸ÏòÁË localhost:44073 £¬Êµ¼ÊÉÏngrok»¹ÊÇ»á½âÎö³É 127.0.0.1:44073 ÔÙÖ¸ÏòËü,È»¶øÕâÏÂÃæɶҲûÓС¡
Ìí¼ÓIP°ó¶¨£¬ÈÃIIS ExpressÒ²Ö§³Ö¡°127.0.0.1¡±
½â¾ö°ì·¨Ò²ºÜ¼òµ¥£¬ÔÚ¡°127.0.0.1:44073¡±ÏÂÒ²²¿ÊðһϾͺÃÁË£¬Ò²¾ÍÊÇÈÃIIS ExpressÔٰ󶨵½Õâ¸öIPºÍ¶Ë¿ÚÉÏ£¬²Ù×÷ÈçÏ£º
ÔÚϵͳÍÐÅÌ´¦ÕÒµ½IIS Expressͼ±ê£¬ÓÒ¼üÑ¡Ôñ¡°ÏÔʾËùÓÐÓ¦ÓóÌÐò¡±£¬Ñ¡ÖÐÎÒÃǵÄÍøÕ¾£¬ÔÙµãÏÂÃæµÄ¡°ÅäÖᱵķ¾¶£¬¾Í»á´ò¿ªÒ»¸öÅäÖÃÎļþ¡£
ÀûÓòéÕÒ¹¤¾ßËÑË÷¡°localhost¡±¹Ø¼ü×Ö£¬ÕÒµ½ name ÊôÐÔΪÎÒÃÇÍøÕ¾ÃûµÄ <site> ±êÇ©£¬¸´ÖÆÔö¼ÓÒ»ÐÐ <binding> ±êÇ©£¬Ö»°ÑIP¸ÄΪ 127.0.0.1£¬±£´æÎļþ£¬Í˳öIIS Express£¬Ctrl+F5ÖØÆô Index.aspx Ò³Ãæ¡£
ÓòÃûÄܹ»Õý³£·ÃÎʺó£¬ÔÙ´ÎÀûÓýӿÚÔÚÏßµ÷ÊÔÖØÐÂÉèÖÃһϹ«ÖںŵIJ˵¥±êÌâºÍÁ´½Ó£¬Èð´Å¥µã»÷ºóÌøתµ½ÎÒÃÇÓòÃûϵÄÕ¾µã¡£Json²ÎÊýÈçÏ£º {
"button": [
{
"type": "view",
"name": "΢ÐÅÅäÍø²âÊÔ",
"url": "http://shaoguoji.proxy.qqbrowser.cc/Index.aspx"
}
]
}
¸´ÖÆ´úÂë
JSSDKʹÓò½ÖèÒ»¡¢¶þ£º°ó¶¨ÓòÃûºÍÒýÈëJSÎļþ
»¨Á˺ôóƪ·ùÖÕÓÚ°Ñ»·¾³´îÆðÀ´ÁË£¬ÄǽÓÏÂÀ´¾ÍÈÃÎÒÃÇ´ò¿ªJSSDK˵Ã÷Îĵµ£¬Ò»²½²½¿ªÊ¼¡°Î¢ÐÅÄÚÍøÒ³¡±µÄ±àд°É¡£ ²½ÖèÒ»£º°ó¶¨ÓòÃû
È·±£ngrokÓòÃû¿ÉÓúó£¬È¥µ½¹«Öںźǫ́µÄ¡°JS½Ó¿Ú°²È«ÓòÃû¡±Ñ¡Ïî´¦µã»÷¡°Ð޸ġ±£¬ÌîÈëngrokÓòÃû shaoguoji.proxy.qqbrowser.ccºóµã¡°Ìá½»¡±¾ÍÐÐÁË¡£
²½Öè¶þ£ºÒýÈëJSÎļþ
ÔÚÎÒÃÇÒ³ÃæµÄ <head> ±êÇ©ÄÚ¼ÓÉÏÒ»ÐÐ <script> ´úÂë¼´¿É¡£
<script type="text/java script" src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>
¸´ÖÆ´úÂë
JSSDKʹÓò½ÖèÈý£ºÍ¨¹ýconfig½Ó¿Ú×¢ÈëȨÏÞÑéÖ¤ÅäÖÃ
ÕâÒ»²½¾ø¶ÔÊÇJSSDKµÄºËÐÄ¡¢ËùÓнӿڵ÷ÓõĻù´¡²½Öè¡£¡°×¢ÈëȨÏÞ¡±ÊÇָͨ¹ý wx.config() ·½·¨£¨¶¨ÒåÔÚÒýÈëµÄJSÎļþÖУ©£¬°ÑappId¡¢Ç©ÃûºÍµ÷ÓýӿÚÁбíµÈÐÅÏ¢Ïò΢ÐÅ×¢²áµÄ¹ý³Ì¡£Ö»ÓÐ×¢ÈëÅäÖóɹ¦¡¢Í¨¹ýÁË΢ÐÅÇ©ÃûÈÏÖ¤µÄÒ³Ãæ²ÅÊǺϷ¨µÄ¡¢¿ÉÒÔµ÷ÓÃJS-SDK½Ó¿ÚµÄÒ³Ãæ¡£
wx.config({
debug: true, // ¿ªÆôµ÷ÊÔģʽ,µ÷ÓõÄËùÓÐapiµÄ·µ»ØÖµ»áÔÚ¿Í»§¶Ëalert³öÀ´
appId: '', // ±ØÌ¹«ÖںŵÄΨһ±êʶ
timestamp: , // ±ØÌÉú³ÉÇ©ÃûµÄʱ¼ä´Á
nonceStr: '', // ±ØÌÉú³ÉÇ©ÃûµÄËæ»ú´®
signature: '',// ±ØÌǩÃû£¬¼û¸½Â¼1
jsApiList: [] // ±ØÌÐèҪʹÓõÄJS½Ó¿ÚÁÐ±í£¬ËùÓÐJS½Ó¿ÚÁбí¼û¸½Â¼2
});
¸´ÖÆ´úÂë
¿ÉÒÔ¿´µ½config()·½·¨ÐèÒªÁù¸ö²ÎÊý£¬ÆäÖÐµÄ debug ¡¢ appId ¡¢ jsApiList ÊÇÒÑÖªµÄ£¬¶ø timestamp ¡¢ nonceStr ºÍ signature ÊǺǫ́ҪÌṩµÄ£¬Ò²ÕýÊÇÒªÓÃC#ºǫ́´úÂëʵÏֵġ£À´·Ö±ð¿´¿´ÕâÈý¸ö²ÎÊýÈçºÎÓôúÂëÉú³É¡£
Õ¹¿ª¡°½â¾ö·½°¸¹ÜÀíÆ÷¡±ÏÂÏîÄ¿ÖÐµÄ Index.aspx Îļþ£¬´ò¿ª Index.aspx.cs Îļþ±àдºǫ́´úÂ룬²»¶ÏÌíש¼ÓÍߣ¬ÊµÏÖÿ¸ö·½·¨¡£
1¡¢ÒýÈëËùÐèµÄÃüÃû¿Õ¼ä£º
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Web.Script.Serialization;
¸´ÖÆ´úÂë
2¡¢¶¨ÒåÓõ½µÄÊý¾ÝÀàÐÍ£º
public partial class Index : System.Web.UI.Page
{
public string appID = "¹«ÖÚºÅappID";
public string appsecret = "¹«ÖÚºÅappsecret";
public string timestamp; // Éú³ÉÇ©ÃûµÄʱ¼ä´Á
public string nonceStr; // Éú³ÉÇ©ÃûµÄËæ»ú´®
public string signature; // Ç©Ãû
class TokenResultMessage // ·â×°µ÷ÓÃaccess_token½Ó¿Ú·µ»ØµÄÊý¾Ý
{
public string access_token;
public string expires_in;
}
class JsapiResultMessage // ·â×°µ÷ÓÃjsapi_ticket½Ó¿Ú·µ»ØµÄÊý¾Ý
{
public string errcode;
public string errmsg;
public string ticket;
public string expires_in;
}
protected void Page_Load(object sender, EventArgs e)
{
}
}
¸´ÖÆ´úÂë
appID ºÍ appsecret ÌîÈë²âÊԺźǫ́µÄ¡°appID¡±ºÍ¡°appsecret¡±¡£ timestamp ¡¢ nonceStr ºÍ signature ÊÇÒª¸øǰ̨ÌṩµÄÊý¾Ý£¬Ã»Ê²Ã´ºÃ˵µÄ¡£¶øÁ½¸öÄÚ²¿Àà TokenResultMessage ºÍ JsapiResultMessage ÊǶԽӿڷµ»Ø½á¹ûµÄ·â×°£¬³ÉÔ±×Ö¶ÎÊǺͽӿڵķµ»Ø²ÎÊý£¨¼ûÎĵµ£©Ò»Ò»¶ÔÓ¦µÄ¡£Á½¸öÄÚ²¿ÀàÓõĺÜÇÉÃ¿É´ó´ó¼ò»¯ÎÒÃǵŤ×÷£¬ºóÃæ»áÔÙ·ÖÎö¡£
3¡¢Ôö¼ÓÁ½¸ö¹¤¾ß·½·¨£º
/// <summary>
/// GetÇëÇó·â×°
/// </summary>
/// <param name="url"></param>
/// <returns></returns>
public string GetWebUrl(string url)
{
WebClient client = new WebClient(); // ´´½¨ä¯ÀÀÆ÷
Stream stream = client.OpenRead(url); // ´«ÈëurlµØÖ·
return new StreamReader(stream).ReadToEnd(); // µÃµ½ÏìÓ¦×Ö·û´®
}
/// <summary>
/// sha1Ç©ÃûËã·¨
/// </summary>
/// <param name="str"></param>
/// <returns></returns>
public string Sha1(string str)
{
var sha1 = System.Security.Cryptography.SHA1.Create();
byte[] bytes = Encoding.UTF8.GetBytes(str);
byte[] bytesArr = sha1.ComputeHash(bytes);
StringBuilder sb = new StringBuilder();
foreach (var item in bytesArr)
{
sb.AppendFormat("{0:x2}", item);
}
return sb.ToString();
}
¸´ÖÆ´úÂë
GetWebUrl()·½·¨·â×°ÁËHTTPÐÒéGET·½·¨µÄÇëÇóÓëÏìÓ¦½á¹ûµÄ¶ÁÈ¡Óë·µ»Ø£¬´«Èëurl¼´¿ÉʹÓá£ÀýÈçÇëÇóµØÖ·https://www.baidu.com/¾Í»á·µ»Ø°Ù¶ÈÊ×Ò³µÄhtml´úÂ룬¶øÇëÇóÒ»¸ö½Ó¿Ú£¬Ôò·µ»ØJson½á¹û×Ö·û´®£¬ÓÃÓÚµ÷ÓÃHTTP½Ó¿Úʱ½á¹ûµÄ½ÓÊÕ¡£Sha1()ʵÏÖÁË×Ö·û´®µÄsha1Ç©Ãû£¬²¢°Ñ½á¹ûÒÔÊ®Áù½øÖÆ×Ö·ûµÄÐÎʽ·µ»Ø¡£
4¡¢Éú³ÉÇ©ÃûµÄʱ¼ä´Á
///
/// Éú³Éʱ¼ä´Á
///
private void GetTimeStamp()
{
TimeSpan ts = DateTime.UtcNow - new DateTime(1970, 1, 1);
timestamp = Convert.ToInt64(ts.TotalSeconds).ToString();
}
¸´ÖÆ´úÂë
ʱ¼ä´ÁÓÃÓÚÇø·Ö½Ó¿Úµ÷ÓõIJ»Í¬Ê±¿Ì£¬Ò»°ãËü±íʾ´Ó1970
Äê1ÔÂ1ÈÕ00:00:00 µ½µ±Ç°Ê±¼äµÄÃëÊýÖ®ºÍ£¨Unixʱ¼ä´Á£©¡£
5¡¢Éú³ÉÇ©ÃûµÄËæ»ú´®
///
/// Éú³É32λËæ»ú×Ö·û´®
///
private void GetRandomStr()
{
string strArr = ¡°0123456789QWERTYUIOPASDFGHJKLZXCVBNMqwertyuiopasdfghjklzxcvbnm¡±;
Random rand = new Random();
string randStr = "";
for (int i = 0; i < 32; i++)
{
int index = rand.Next(strArr.Length);
randStr += strArr.Substring(index, 1);
}
nonceStr = randStr;
}
¸´ÖÆ´úÂë
¿ÉÒÔ¿´µ½Éú³ÉËæ»ú´®Ê¹ÓÃÀàËÆÓÚ¡°³é½±¡±µÄ·½Ê½¡ª¡ª´ÓÊý×ֺʹóСд×ÖĸÖÐËæ»ú³éÈ¡32λ×é³É×Ö·û´®£¨ÎĵµÖжԽӿÚËæ»ú´®µÄÒªÇóÊÇ¡°²»³¤ÓÚ32λ¡£ÍƼöʹÓôóСд×ÖĸºÍÊý×Ö¡±£©¡£
6¡¢Éú³ÉÇ©Ãû
Ç©ÃûÊÇÒ³ÃæºÏ·¨ÐÔÑéÖ¤µÄÖØҪƾ֤£¬Ç°ÃæµÄʱ¼ä´Á¡¢Ëæ»ú´®¶¼ÊÇÓÃÀ´Éú³ÉÇ©ÃûµÄ£¬Îĵµ¶ÔÇ©ÃûËã·¨µÄ˵Ã÷ÈçÏ£º
Ç©ÃûÉú³É¹æÔòÈçÏ£º²ÎÓëÇ©ÃûµÄ×ֶΰüÀ¨noncestr£¨Ëæ»ú×Ö·û´®£©, ÓÐЧµÄjsapi_ticket, timestamp£¨Ê±¼ä´Á£©, url£¨µ±Ç°ÍøÒ³µÄURL£¬²»°üº¬#¼°ÆäºóÃ沿·Ö£© ¡£¶ÔËùÓдýÇ©Ãû²ÎÊý°´ÕÕ×Ö¶ÎÃûµÄASCII Âë´ÓСµ½´óÅÅÐò£¨×ÖµäÐò£©ºó£¬Ê¹ÓÃURL¼üÖµ¶ÔµÄ¸ñʽ£¨¼´key1=value1&key2=value2¡£©Æ´½Ó³É×Ö·û´®string1¡£ÕâÀïÐèҪעÒâµÄÊÇËùÓвÎÊýÃû¾ùΪСд×Ö·û¡£¶Ôstring1×÷sha1¼ÓÃÜ£¬×Ö¶ÎÃûºÍ×Ö¶ÎÖµ¶¼²ÉÓÃÔʼֵ£¬²»½øÐÐURL תÒå¡£
ÎÒÃÇËùÒª×öµÄ£¬¾ÍÊÇ°ÑÉÏÃæµÄÒ»´ó¶ÎÎÄ×Ö·Òë³É´úÂë¡£
///
/// Éú³ÉÇ©Ãû
///
private void GetSignatur()
{
// ͨ¹ýAPI»ñÈ¡access_token
string tokenUrl = ¡°https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=¡± + appID + ¡°&secret=¡± + appsecret;
var tokenInfo = new java scriptSerializer().Deserialize(GetWebUrl(tokenUrl));
// ͨ¹ýAPI»ñÈ¡jsapi_ticket
string jsapiUrl = "https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token=" + tokenInfo.access_token + "&type=jsapi";
var jsapiInfo = new java scriptSerializer().Deserialize<JsapiResultMessage>(GetWebUrl(jsapiUrl));
// µ±Ç°ÍøÒ³µÄURL£¬²»°üº¬#¼°ÆäºóÃ沿·Ö
string nowUrl = "http://shaoguoji.proxy.qqbrowser.cc/Index.aspx";
//string nowUrl = Request.Url.AbsoluteUri; // ²¿Êð·þÎñÆ÷ºóÓ¦¶¯Ì¬»ñÈ¡Ò³Ãæurl
// ÓÃDictionary¼¯ºÏ´æ´¢¸÷±äÁ¿
Dictionary<string, string> dic = new Dictionary<string, string>();
dic["timestamp"] = timestamp;
dic["noncestr"] = nonceStr;
dic["url"] = nowUrl;
dic["jsapi_ticket"] = jsapiInfo.ticket;
// ¶Ô±äÁ¿Ãû×ÖµäÅÅÐò
string[] arrKey = new string[] { "timestamp", "noncestr", "url", "jsapi_ticket" };
arrKey = arrKey.OrderBy(n => n).ToArray();
// Æ´½Ó×Ö·û´®
string signatureStr = "";
foreach (var item in arrKey)
{
signatureStr += item + "=" + dic[item] + "&";
}
signatureStr = signatureStr.Substring(0, signatureStr.Length - 1);
// ¶ÔÆ´½Ó´®sh1Ç©Ãû£¬µÃµ½×îÖÕÇ©Ãû
signature = Sha1(signatureStr);
}
¸´ÖÆ´úÂë
Ç©ÃûËã·¨¿´ËƸ´ÔÓ£¬ÆäʵֻÊǰѼ¸¸ö±äÁ¿ÃûºÍÖµ°´Ë³ÐòÆ´½Ó³É×Ö·û´®ÔÙ½øÐÐsh1Ç©Ãû¶øÒÑ¡£×¢Ò⵽ͨ¹ý½Ó¿Ú»ñÈ¡ access_tokenºÍ jsapi_ticket ´¦µÄÁ½ÐдúÂ룺
var tokenInfo = new java scriptSerializer().Deserialize(GetWebUrl(tokenUrl));
var jsapiInfo = new java scriptSerializer().Deserialize(GetWebUrl(jsapiUrl));
¸´ÖÆ´úÂë
ÎÒÃÇÖªµÀ£¬µ÷ÓÃÕâÁ½¸öHTTP½Ó¿Ú»á·µ»Ø½á¹ûJson×Ö·û´®£¬°üº¬Ðí¶àµÄ½á¹ûÐÅÏ¢¡£¶øÔõÑùÄõ½ËùÐèÒªµÄÄÇÒ»¸öÖµÄØ£¿»¹¼ÇµÃµ±³õÉùÃ÷µÄÁ½¸öÄÚ²¿Àà TokenResultMessage ºÍ JsapiResultMessage ô£¬¶øÕâÀï¾ÍÊÇͨ¹ýµ÷Óà ```java scriptSerializer```ÀàµÄ ```Deserialize<T>(String)``` ·½·¨¶ÔJson×Ö·û´®½øÐÐÐòÁл¯£¬²¢×ª»»ÎªÄÚ²¿Àà¶ÔÏó£¨Ç¿´óµÄ·ºÐÍ£©¡£ÕâÑù¾Í°ÑJson×Ö·û´®×ª»»Îª¶ÔÏóÁË£¬Ö±½ÓÓà ```tokenInfo.access_token``` ºÍ ```jsapiInfo.ticket``` µÄд·¨¾ÍÄÜ·½±ãµØʹÓÃËùÐèµÄ½Ó¿Ú½á¹ûÖµ¡£**´ËÍ⻹ÓÐÒ»µãÒªÌرð×¢Ò⣺ҳÃæµÄurlÓ¦¸Ã¶¯Ì¬»ñÈ¡¡£ÎĵµÖеÄ[¸½Â¼5-³£¼û´íÎó¼°½â¾ö·½·¨](https://mp.weixin.qq.com/wiki/11 ... 3.E6.96.B9.E6.B3.95)ҲдµÃ·Ç³£Çå³þ£º**> È·±£Äã»ñÈ¡ÓÃÀ´Ç©ÃûµÄurlÊǶ¯Ì¬»ñÈ¡µÄ£¬¶¯Ì¬Ò³Ãæ¿É²Î¼ûʵÀý´úÂëÖÐphpµÄʵÏÖ·½Ê½¡£Èç¹ûÊÇhtmlµÄ¾²Ì¬Ò³ÃæÔÚÇ°¶Ëͨ¹ýajax½«url´«µ½ºǫ́ǩÃû£¬Ç°¶ËÐèÒªÓÃjs»ñÈ¡µ±Ç°Ò³Ãæ³ýÈ¥'#'hash²¿·ÖµÄÁ´½Ó£¨¿ÉÓÃlocation.href.split('#')[0]»ñÈ¡,¶øÇÒÐèÒªencodeURIComponent£©£¬ÒòΪҳÃæÒ»µ©·ÖÏí£¬Î¢ÐÅ¿Í»§¶Ë»áÔÚÄãµÄÁ´½Óĩβ¼ÓÈëÆäËü²ÎÊý£¬Èç¹û²»ÊǶ¯Ì¬»ñÈ¡µ±Ç°Á´½Ó£¬½«µ¼Ö·ÖÏíºóµÄÒ³ÃæÇ©Ãûʧ°Ü¡£ÔÚµ÷ÊÔ»·¾³ÏÂÎÒдËÀÁË£¨·ñÔò»ñÈ¡µ½µÄ¾ÍÊÇ ```http://localhost:44073/Index.aspx``` £¬Ó빫Öںźǫ́°ó¶¨µÄÓòÃû²»Ò»Öµ¼ÖÂÇ©Ãûʧ°Ü£©£¬**µ«°ÑÍøÕ¾²¿Êð·þÎñÆ÷ºóÓ¦¸ÃʹÓà ```Request.Url.AbsoluteUri``` À´¶¯Ì¬»ñÈ¡¡£**µ½ÕâÀïºǫ́´úÂëµÄ±àд¾ÍÍê³ÉÁË£¬ÄÇÏÂÃæ¿´¿´ÈçºÎÔÚÒ³ÃæJSÖе÷Óúǫ́Éú³ÉµÄÊý¾Ý¡£**7¡¢±àдҳÃæJS´úÂë**ÒªÔÚJSʵÏÖÅäÖÃ×¢È룬°ÑÌṩµÄ ```config()``` ·½·¨Ä£°å¸´ÖƵ½Ò³ÃæÖÐÐ嵀 ```<script>``` ±êÇ©Ï ```window.onload``` ʼþÖУ¨Îĵµ¼ÓÔØÍêÖ´ÐУ©£¬ÌîÉ϶ÔÓ¦µÄ±äÁ¿Ãû£¨Óëºǫ́´úÂë¶ÔÓ¦£©±êÇ©¼´¿É¡£½Ó¿ÚÁбíÌî¡°»ñÈ¡¡®·ÖÏíµ½ÅóÓÑȦ¡¯°´Å¥µã»÷״̬¼°×Ô¶¨Òå·ÖÏíÄÚÈݽӿڡ±**onMenuShareTimeline**£º
<script type="text/java script">
window.onload = function () {
wx.config({
debug: true, // ¿ªÆôµ÷ÊÔģʽ,µ÷ÓõÄËùÓÐapiµÄ·µ»ØÖµ»áÔÚ¿Í»§¶Ëalert³öÀ´£¬ÈôÒª²é¿´´«ÈëµÄ²ÎÊý£¬¿ÉÒÔÔÚpc¶Ë´ò¿ª£¬²ÎÊýÐÅÏ¢»áͨ¹ýlog´ò³ö£¬½öÔÚpc¶Ëʱ²Å»á´òÓ¡¡£
appId: '<%=appID %>', // ±ØÌ¹«ÖںŵÄΨһ±êʶ
timestamp: '<%=timestamp %>', // ±ØÌÉú³ÉÇ©ÃûµÄʱ¼ä´Á
nonceStr: '<%=nonceStr %>', // ±ØÌÉú³ÉÇ©ÃûµÄËæ»ú´®
signature: '<%=signature %>',// ±ØÌǩÃû£¬¼û¸½Â¼1
jsApiList: ["onMenuShareTimeline"] // ±ØÌÐèҪʹÓõÄJS½Ó¿ÚÁÐ±í£¬ËùÓÐJS½Ó¿ÚÁбí¼û¸½Â¼2
});
};
</script>
¸´ÖÆ´úÂë
8¡¢²âÊÔÍøÒ³µÄÅäÖÃ×¢Èë
ºǫ́ºÍÒ³Ã涼дºÃºó¾ÍÀ´¼ûÖ¤³É¹û°É¡£Ctrl+F5ÔËÐÐÍøÒ³£¬´ò¿ª¡°Î¢ÐÅweb¿ª·¢Õß¹¤¾ß¡±£¨»òÊÖ»ú¹«ÖںŲ˵¥£©£¬ÊäÈëµØÖ·http://shaoguoji.proxy.qqbrowser.cc/Index.aspx ·ÃÎÊÎÒÃǵÄÒ³Ã棬ÈôÌáʾ {¡°errMsg¡±:¡±configk¡±}ÄǾÍ˵Ã÷×¢ÈëÅäÖóɹ¦ÁË£¡Í¬Ê±ÔÚ¡°JS-SDK¡±ºÍ¡°È¨ÏÞÁÐ±í¡±Ñ¡ÏÖпɲ鿴¸üÏêϸµÄÐÅÏ¢¡£ JSSDKʹÓò½ÖèËÄ£ºÍ¨¹ýready½Ó¿Ú´¦Àí³É¹¦ÑéÖ¤
¼ÈÈ»×¢ÈëȨÏÞÅäÖóɹ¦ÁË£¬ÄǾͿÉÒÔÈÎÐԵĵ÷ÓýӿÚÁ˹þ¹þ~~~¾ÍÓøոÕÔÚÁбíÀïдµÄonMenuShareTimeline½Ó¿Ú×ö²âÊÔ°É¡£ÓÉÓÚËùÓеĽӿڵ÷Óö¼ÒªÔÚ×¢ÈëÅäÖÃÖ®ºó£¬¶ÔÓÚÔÚÒ³Ãæ¼ÓÔØʱµ÷ÓõĽӿڣ¬Î¢ÐÅÌṩÁË ready() ·½·¨£º
configÐÅÏ¢ÑéÖ¤ºó»áÖ´ÐÐready·½·¨£¬ËùÓнӿڵ÷Óö¼±ØÐëÔÚconfig½Ó¿Ú»ñµÃ½á¹ûÖ®ºó£¬configÊÇÒ»¸ö¿Í»§¶ËµÄÒì²½²Ù×÷£¬ËùÒÔÈç¹ûÐèÒªÔÚÒ³Ãæ¼ÓÔØʱ¾Íµ÷ÓÃÏà¹Ø½Ó¿Ú£¬ÔòÐë°ÑÏà¹Ø½Ó¿Ú·ÅÔÚreadyº¯ÊýÖе÷ÓÃÀ´È·±£ÕýÈ·Ö´ÐС£¶ÔÓÚÓû§´¥·¢Ê±²Åµ÷ÓõĽӿڣ¬Ôò¿ÉÒÔÖ±½Óµ÷Ó㬲»ÐèÒª·ÅÔÚreadyº¯ÊýÖС£
ÔÚ <script> ±êÇ©µÄ¼ÓÈëready·½·¨£¬²¢ÔÚÆäÖж¨ÒåonMenuShareTimeline½Ó¿ÚҪʵÏÖµÄÄÚÈÝ£¨Ïê¼ûÎĵµ£©¡£ÕâÀïûÓÃʵÏÖ·ÖÏí¹¦ÄÜ£¬Ö»½èÖúͨÓòÎÊýʵÏÖÓû§²Ù×÷µÄµ¯´°Ìáʾ£¨´¦Àí²»Í¬°´Å¥µÄµã»÷ʼþ£©¡£
wx.ready(function(){
wx.onMenuShareTimeline({
title: '', // ·ÖÏí±êÌâ
link: '', // ·ÖÏíÁ´½Ó
imgUrl: '', // ·ÖÏíͼ±ê
trigger: function (res) {
alert('Óû§µã»÷·ÖÏíµ½ÅóÓÑȦ');
},
success: function (res) {
alert('ÒÑ·ÖÏíµ½ÅóÓÑȦ');
},
cancel: function (res) {
alert('ÒÑÈ¡Ïûµ½ÅóÓÑȦ');
},
fail: function (res) {
alert(JSON.stringify(res));
}
});
});
¸´ÖÆ´úÂë
ÖØÐÂË¢ÐÂÒ³Ã棬µã»÷²Ëµ¥°´Å¥µÄ·ÖÏíµ½ÅóÓÑȦ£¬ÔÚ´¥·¢²»Í¬°´Å¥Ê¼þʱÈç¹ûµ¯³öÏàÓ¦Ìáʾ£¬ÄÇô¾ÍÖ¤Ã÷½Ó¿Úµ÷Óóɹ¦À²£¬ÀíÂÛÉÏÀ´Ëµµ÷ÓÃÆäËû½Ó¿ÚÒ²ÊÇûÎÊÌâµÄ¡£
AirKissÓ¦Ó᪡ªÎ¢ÐÅÅäÍøJSAPI
Á˽âÁËJS-SDKµÄ»ù±¾Ê¹Óú󣬵÷ÓÃAirkissµÄJSAPIÄÇÊÇ·Ö·ÖÖÓµÄÊ¡¡
ÔÚJS-SDK³õʼ»¯µÄ»ù´¡ÉÏ£¬Çë°´ÈçÏ·½·¨Ê¹ÓÃ΢ÐÅÓ²¼þJSAPI£º
a.ÐèÒªÔÚwx.configµÄ·½·¨µÄ²ÎÊýjsApiListÊý×éÖУ¬´«ÈëÐèÒª¶îÍâʹÓõÄjsapiÃû³Æ¡£(ÔÚʹÓÃÈκÎjsapiµÄ½Ó¿ÚÇ°£¬±ØÐëÏȵ÷ÓÃwx.config·½·¨)¡£
b. ÐèÒªÔÚconfig·½·¨Öд«ÈëÒ»¸öbeta×ֶΣ¬²¢¸´ÖÆΪtrue£¬Ôò»áÔÚ×¢Èëwx.invoke·½·¨À´µ÷Óû¹Î´¿ª·ÅµÄjsapi·½·¨¡££¨Ò³Ãæ¼ÓÔØʱ¾Íµ÷ÓÃjsapi£¬Ôò±ØÐë·Åµ½wx.ready»Øµ÷ÖУ©¡£
ÐÞ¸Äconfig·½·¨
ÔÚÔÀ´µÄ config ÐÞ¸ÄÁ½´¦¼´¿É£º
window.onload = function () {
wx.config({
beta: true,
debug: true, // ¿ªÆôµ÷ÊÔģʽ,µ÷ÓõÄËùÓÐapiµÄ·µ»ØÖµ»áÔÚ¿Í»§¶Ëalert³öÀ´£¬ÈôÒª²é¿´´«ÈëµÄ²ÎÊý£¬¿ÉÒÔÔÚpc¶Ë´ò¿ª£¬²ÎÊýÐÅÏ¢»áͨ¹ýlog´ò³ö£¬½öÔÚpc¶Ëʱ²Å»á´òÓ¡¡£
appId: '<%=appID %>', // ±ØÌ¹«ÖںŵÄΨһ±êʶ
timestamp: '<%=timestamp %>', // ±ØÌÉú³ÉÇ©ÃûµÄʱ¼ä´Á
nonceStr: '<%=nonceStr %>', // ±ØÌÉú³ÉÇ©ÃûµÄËæ»ú´®
signature: '<%=signature %>',// ±ØÌǩÃû£¬¼û¸½Â¼1
jsApiList: ["onMenuShareTimeline", "configWXDeviceWiFi"] // ±ØÌÐèҪʹÓõÄJS½Ó¿ÚÁÐ±í£¬ËùÓÐJS½Ó¿ÚÁбí¼û¸½Â¼2
});
};
¸´ÖÆ´úÂë
ÒªÓõ½µÄÅäÍø½Ó¿ÚΪ configWXDeviceWiFi £¬¹Ù·½ËµÃ÷ÈçÏ£º
|º¯ÊýÃû|configWXDeviceWiFi|
|ÃèÐð|µ÷ÆðÔÉúAirKiss½çÃ棬²»ÐèÒªÏȵ÷Óã¨Ö»Ö§³ÖWIFIÉ豸£©openWXDeviceLib|
|²ÎÊý|key£¨¿ÉÑ¡£©£ºbase64 ±àÂëµÄAirKissµÄÃÜÔ¿|
|·µ»ØÖµ|configWXDeviceWiFik¡¡//ÅäÖóɹ¦
configWXDeviceWiFi:fail //³¬Ê±
configWXDeviceWiFi:cancel //Óû§È¡Ïû
//·µ»Øres.desc£¬È¡ÖµÈçÏ£º
wifi_not_connected //µ±res.err_msgΪconfig_wx_device_wifi:cancelʱ
//ÆäËüÇé¿öΪ¿Õ| µ÷ÓÃÅäÍø½Ó¿Ú
ÔÚ ready ·½·¨ÖÐÔö¼ÓÒ»ÐÐ wx.invoke('configWXDeviceWiFi'); ¼´¿É£¡¡£
ÓÉÓÚWeb¿ª·¢Õß¹¤¾ß²»Ö§³ÖJSAPIµÄÄ£Ä⣬ֻÄÜÓÃÊÖ»ú²âÊÔ£¬Ð§¹ûÈçÏ¡£
µ¯³öÔÉúAirKiss½çÃ棡ÎÒÃdzɹ¦ÁË£¡£¡
×¢£ºÒªÎªÉ豸ÅäÖõÄWiFi¾ÍÊÇÊÖ»úµ±Ç°Á¬½ÓµÄWiFi¡£Èç¹ûÊÖ»úδÁ¬½ÓWiFi»áÓÐÏàÓ¦Ìáʾ¡ª¡ªµ±È»£¬ÕⶼÊÇ΢ÐÅ°ïÎÒÃÇʵÏֵġ£
Ôö¼ÓÒýµ¼Ò³
Óû§Ò»Á³ã±ƵĿ´×ŵ¯³öµÄÅäÍø½çÃæ¿É²»ÊÇʲôºÃÊ£¬ÎÒÃÇ»¹Ó¦¸Ã¼ÓÉϲÙ×÷Ìáʾ£¬¸üºÎ¿öÕâÊÇÒªºÍÓ²¼þÅäºÏʹÓõŦÄÜ¡£
È¥µôÔÀ´µÄHello World£¬ÔÚÒ³ÃæÖмÓÈëÒýµ¼Ò³html´úÂ룬°üÀ¨Í¼±ê¡¢ÌáʾÐÅÏ¢¼°ÅäÖð´Å¥£¨¿É¸ù¾Ý¸öÈËϲºÃµ÷Õûͼ±ê¼°Ñùʽ£¬µ«Òª×¢ÒâÆÁÄ»ÊÊÅ䣩£¬²¢°ÑÔÚÒ³Ãæ¼ÓÔؾ͵÷ÓÃµÄ wx.invoke('configWXDeviceWiFi'); ·Åµ½°´Å¥µÄ onclick ʼþÄÚ£¬ÊµÏÖÏÈÏÔʾÒýµ¼Ò³£¬Óû§µã»÷°´Å¥ºóÔÙµ¯³öÅäÍø½çÃæµÄЧ¹û¡££º
<body>
<form id="form1" runat="server">
<div>
<div align="center"><img style="margin-top:7rem;"; src="http://odaps2f9v.bkt.clouddn.com/17-2-10/85209391-file_1486697604972_fa49.jpg"/></div>
<p style="text-align:center;font-size:50px;">Ç볤°´Ä£¿éÉϵÄÍøÂçÅäÖð´Å¥</p>
<p style="text-align:center;font-size:50px;">´ýºìÉ«LEDµãÁÁºó¼ÌÐø</p>
<div align="center"><button style="background-color:#343434;color:white;width:90%;height:10rem;font-size:5rem;"; onclick="wx.invoke('configWXDeviceWiFi')">¼ÌÐøÅäÖÃ</button></div>
</div>
</form>
</body>
¸´ÖÆ´úÂë
ºÃÁËÖ®ºóЧ¹ûÓ¦¸ÃÊÇÕâÑùµÄ£¨Ò²¿ÉÒÔɨÂë¹Ø×¢ÎҵIJâÊԺŲ鿴DEMO£©£º
×¢£ºÈ·±£¸÷ÏÄÜÕý³£ºó¾Í¿ÉÒÔͨ¹ýÉèÖà debug: false °Ñ·³È˵ĵ÷ÊÔµ¯´°ÐÅÏ¢¹ØµôÁË¡¡
ÖÁ´Ë£¬Î¢ÐÅÅäÍøÈí¼þ²¿·Ö¾ÍÍê³ÉÁË£¬ÖÁÓÚÄܲ»ÄÜÓã¬ÒªÄÃWiFiÄ£¿éÀ´ÊÔÊÔ²ÅÖªµÀ¡£
³É¹û¼ìÑ顪¡ªÓÃsscom²âÊÔWiFiÄ£¿éAirkiss¹¦ÄÜ
ÈçºÎÓÃдºÃµÄÒ³ÃæÀ´ÅäÖÃWiFiÄ£¿éÉÏÍøÄØ£¿Ê×ÏÈÒªÖªµÀ£¬WiFiÄ£¿é²¢²»ÊÇËæʱ¶¼ÄܽøÐÐÖÇÄÜÅäÖ㬶øÊÇҪͨ¹ý AT+CWSTARTSMART Ö¸ÁÆô¡°SmartConfig¡±ºó²ÅÄܽÓÊÕÀ´×ÔÊÖ»úµÄÎÞÏßssidºÍÃÜÂ룬Íê³ÉÅäÖú󻹱ØÐëÍ˳ö¡°SmartConfig¡±£¬Ó¦¸Ã˵ÖÇÄÜÅäÖÃÊǸöÁÙʱµÄ²Ù×÷¡£
°´ÕÕÒÔϲ½Öè²âÊÔWiFiÄ£¿éµÄÖÇÄÜÅäÖù¦ÄÜ£º
ÔÚsscomÈ·±£ATÖ¸ÁîÔËÐÐÕý³£ºó£¬·¢ËÍ AT+CWMODE=1 Ö¸ÁîÅäÖÃÄ£¿éΪstaģʽ¡£
·¢ËÍ AT+CWSTARTSMART ¿ªÆôÄ£¿éµÄ¡°SmartConfig¡±¹¦ÄÜ£¬·µ»ØOK£¬´Ëʱģ¿é´¦ÓÚ»ìÔÓģʽϽøÐÐÎÞÏß×¥°ü¡£
ÊÖ»úÁ¬½ÓWiFi£¬´ò¿ª¸Õ¸ÕдºÃµÄ΢ÐÅÒ³Ã棬µ¯³öÅäÍø½çÃæºóÊäÈëWiFiÃÜÂëºóµã»÷¡°Á¬½Ó¡±°´Å¥¡£
´ËʱÁôÒâµ½sscom£¬ÅäÍø¹ý³ÌÖÐÄ£¿é´®¿Ú»á´òÓ¡ÅäÖýø¶ÈµÈÐÅÏ¢£¬Á¬½Ó³É¹¦ºó¿Éͨ¹ý AT+CWJAP? Ö¸Áî²é¿´Ä£¿éÁ¬½ÓWiFiÇé¿ö¡£
·¢ËÍ ``AT+CWSTOPSMART``` Í£Ö¹ SmartConfig¡£
Èç¹û¿´µ½´®¿Ú´òÓ¡³ö Smartconfig connected WiFi ÄǾÍÖ¤Ã÷WiFiÄ£¿é³É¹¦Í¨¹ý΢ÐÅAirkissÁ¬½Óµ½ÁËÎÒÃÇÖ¸¶¨µÄWiFi£¨ÊÖ»úÁ¬½ÓµÄWiFi£©¡£
×¢Ò⣺
Óû§¿ÉÏò Espressif ÉêÇë SmartConfig µÄÏêϸ½éÉÜÎĵµ¡£
½öÖ§³ÖÔÚ ESP8266 µ¥ station ģʽϵ÷Óá£
ÏûÏ¢ Smart get WiFi info ±íʾ Smart Config ³É¹¦»ñÈ¡µ½APÐÅÏ¢¡£Ö®ºó ESP8266 ³¢ÊÔÁ¬½ÓAP£¬´òÓ¡Á¬½Ó¹ý³Ì¡£
ÏûÏ¢ Smartconfig connected WiFi ±íʾ³É¹¦Á¬½Óµ½AP£¬´Ëʱ¿ÉÒÔµ÷Óá°AT+CWSTOPSMART¡±Í£Ö¹ SmartConfig ÔÙÖ´ÐÐÆäËûÖ¸ÁעÒ⣬ÔÚSmartConfig ¹ý³ÌÖÐÇëÎðÖ´ÐÐÆäËûÖ¸Áî¡£
´Ó AT_v1.0 ¿ªÊ¼£¬ SmartConfig ¿ÉÒÔ×Ô¶¯»ñÈ¡ÐÒéÀàÐÍ£¬Airkiss»òÕß ESP-TOUCH¡£
ÎÞÂÛ SmartConfig ³É¹¦Óë·ñ£¬¶¼ÇëÓá°AT+CWSTOPSMART¡±ÊÍ·Å¿ìÁ¬Õ¼ÓõÄÄÚ´æ¡£
С½á
дÁËÄÇô³¤£¬´ó²¿·ÖÊÇÔÚ½²ÈçºÎµ÷³ö΢ÐÅÅäÍø½çÃæ¡£ÆäʵÈç¹ûÖ»ÊÇΪÁËʹÓõĻ°£¬ÄãÍêÈ«¿ÉÒÔÖ±½Ó¹Ø×¢ÎҵIJâÊԺţ¬ÓÃÎÒдµÄÒ³Ãæµ÷³öÅäÍø½çÃæ½øÐÐÅäÍø£¨Èç¹ûÄãʵÔڸ㲻¶¨µÄ»°£©£¬ÒòΪÕâ¸öÒ³ÃæÊÇ΢ÐÅÌṩµÄ£¬Ëµ÷³öÀ´µÄ¶¼Ò»Ñù¡£¶øWiFiÄ£¿éÒ²Ö»ÊÇÓõ½Á˼¸ÌõATÖ¸ÁËùÒÔʵ¼ÊÉϲ»ÐèÒª´òʲô´úÂëÒ²¿ÉÒÔÇáËÉʵÏÖ΢ÐÅÅäÍø¡£
Ô´ÂëÏÂÔØ£ºJS-SDK ÃÜÂëanlg£¬£¨ÔËÐÐÇ°Çë°Ñ¡°¹«ÖÚºÅappID¡±ºÍ¡°¹«ÖÚºÅappsecret¡±Ìæ»»³ÉÄã×Ô¼ºµÄ£¬·ñÔò±¨´í£© ÏÂһƪÀ´¿´¿´ÈçºÎÓõ¥Æ¬»úÄ£ÄâÊÖ¶¯ÊäÈëATÖ¸ÁîÀ´¿ØÖÆWiFiÄ£¿é¡£
²Î¿¼ÎÄÕ£º