Nowadays, WeChat provides fertile soil for various small mobile Web applications, so all kinds of applications have been born. Everyone can develop, but not everyone can develop good applications. What pitfalls should developers pay attention to during the development process? This article is reprinted from Shenhai's blog. He shared the details that need to be paid attention to in the specific development and implementation process of Html5 WebApp based on WeChat and how to implement it with code.
The full text is as follows:
Different from the traditional mobile game store download model, HTML5 mobile web games can be run directly in the built-in browser of WeChat.
During this period, the team has been doing some product design and development on WeChat, which of course also includes certain operational work. I have done a lot of things, including micro business cards, micro ticket grabbing, micro activities, micro recruitment and other small cases.
What I want to talk about today is the most active light game we play in WeChat - micro-scratch prizes. This thing can be used to scratch books, tickets, packages, and even customers can use it to scratch phone bills.
First, take the picture above to get a feel for the specific appearance:
And what I want to share are some pitfalls that we need to overcome in the specific development and implementation process of Html5 WebApp based on WeChat: The basic rules of this small game are: The limit is 2 times per day for users to scratch books (one free scratch and another scratch after sharing), and they can scratch prizes every day. For this reason, the idea we hope to achieve is to first limit the game to only WeChat. The implementation code is as follows:
if (!HttpContext.Current.Request.Browser.IsMobileDevice) { var result = new RedirectResult("url", true); filterContext.Result = result; return; } if (string.IsNullOrEmpty(HttpContext.Current.Request.UserAgent)) { var result = new RedirectResult("url", true); filterContext.Result = result; return; } if (HttpContext.Current.Request.UserAgent.IndexOf("MicroMessenger") == -1) { var result = new RedirectResult("url", true); filterContext.Result = result; return; }
This method of judging by UserAgent seems to be used by many people on the Internet, but there are still many pitfalls if you don’t use it:
1. Primary problem: There is no problem with iOS and mainstream Android machines, but when it comes to Windows Phone, just directly Can't play after being logged out of WeChat. The reason is that the default UserAgent in WeChat is MicroMessenger, which does not exist in the WeChat version of these machines, so in order to solve the problem of Windows Phone, we added the following code:
var useragent = HttpContext.Current.Request.UserAgent.ToLower(); if (useragent.IndexOf("Windows Phone".ToLower()) != -1) { base.OnActionExecuting(filterContext); return; }
2. Advanced problem: Some experts directly use some plug-in tools to fake MicroMessenger's UserAgent can theoretically be played in any browser that can open a web page. To solve this problem, we use the interface in WeChat's SDK: only when the user uses it in WeChat, the control initialization scratch operation is performed. Otherwise, browsing on other terminals will always be in the loading state.
dataForWeixin.callback = function () { //一些初始化的操作 }
Regarding the WeChat interface, please read the original text directly. I won’t post the code directly here, otherwise it won’t be posted.
The above idea has done a lot, but there is still a fatal bug that has not been solved for our business rules.
This bug is that as long as the user manually clears the cookies and cached information in WeChat, and then re-enters the event, he can scratch the prizes unlimited times. Theoretically, he will win 100% of the time. This is because my rules put the basis for judging whether the current WeChat user has scratched the prize in the cookie. It seems that there is no other way. We want to use openid, but our WeChat subscription account cannot get openid if we come from Moments. There is still an appeal problem.
In order to solve this problem, we finally found an idea, borrowing the authorization interface of the WeChat service account. The basic idea is as follows:
The user enters the page loading=》The program calls the authorization interface of another WeChat service account and returns openid= 》Save the openid into the cookie (if it does not exist or expires, re-execute the previous steps) =》According to the openid, determine how many times the current activity has been scraped from the database. At the same time, this process will automatically determine whether the user is playing games in WeChat, otherwise The callback will always be in the loading state. The whole process is relatively smooth after using it. Here is the authorization-related code:
#region 微信授權(quán) public ActionResult WeixinLogin(string CurrentUrl) { string url = WeixinOAuth2.Authorize(Server.UrlEncode(CurrentUrl)); return RedirectPermanent(url); } public ActionResult WeixinCallback() { if (!string.IsNullOrEmpty(Request["code"])) { // 獲取AccessToken參數(shù) var param = WeixinOAuth2.GetAccessToken(Request["code"]); string url = string.Format("{0}#access_token={1}&openid={2}&expires_in={3}&state={4}", ConfigHelper.GetValue("Weixin_Callback"), param.access_token,param.openid,param.expires_in, Server.UrlDecode(Request.QueryString["state"])); //重新跳轉(zhuǎn)到回調(diào)頁面,保持騰訊登錄相同風(fēng)格 return Redirect(url); } return View(); } /// <summary> /// 授權(quán)請(qǐng)求頁面 /// </summary> /// <param name="flag">0為獲取微信基本信息 1為獲取微信openid接口</param> /// <returns></returns> public static string Authorize(string ReturnUrl) { string url=string.Format("https://open.weixin.qq.com/connect/oauth2/authorize?appid={0}&redirect_uri={1}&response_type=code&scope=snsapi_base&state={2}#wechat_redirect", Weixin_AppKey, Weixin_GetOpenIDCallback, ReturnUrl); return url; } #endregion
At this point, it is basically possible to solve the problem of how to determine the uniqueness of the current user in WeChat. The only risk to this solution is the smoothness and stability of WeChat’s interface.
Of course, there are many other problems that need to be overcome one by one during the entire development process. For example, the implementation of callback after sharing on WeChat is used by many friends. For example, for this small game, we even need to support process access under grps. It is impossible to deal with those big game frameworks, how to do this, etc. I plan to write some articles to share these later.

Hot AI Tools

Undress AI Tool
Undress images for free

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Yes, but there are restrictions. ① You can log in to the same account on both iPhone and Android phones, but logging in to the latest device will cause the earliest session to be offline; ② You can log in at the same time on the mobile phone and the computer desktop, but the functions are not synchronized; ③ Although using third-party tools or dual-app functions can enable logging in between two mobile phones, it is unofficially supported and may violate regulations; ④ Alternative solutions include using web version/desktop version to match the main phone, or transferring chat records through cloud backup and file tools. Some Android machines can also use "dual applications" to run two account instances.

?As a stable digital asset pegged to the US dollar, USDT's value conversion and monetization are issues that many users are concerned about. This article will introduce the value composition of USDT in detail and provide practical tutorials on value conversion and monetization in mainland China. 1 USDT's cash value is approximately equal to the real-time dollar exchange rate, but the final delivery price through C2C trading will fluctuate slightly. The core of conversion is to select a merchant with good reputation and appropriate price to trade through the C2C function of a reliable platform.

The core method of building social sharing functions in PHP is to dynamically generate sharing links that meet the requirements of each platform. 1. First get the current page or specified URL and article information; 2. Use urlencode to encode the parameters; 3. Splice and generate sharing links according to the protocols of each platform; 4. Display links on the front end for users to click and share; 5. Dynamically generate OG tags on the page to optimize sharing content display; 6. Be sure to escape user input to prevent XSS attacks. This method does not require complex authentication, has low maintenance costs, and is suitable for most content sharing needs.

The stablecoin trading process includes the steps of registering an exchange, completing certification, buying or selling. First, choose a trusted exchange such as Binance, OKX, etc., and then complete KYC identity authentication, and then buy stablecoins through fiat currency recharge or OTC transactions. You can also transfer the stablecoins to the fund account and sell them through P2P transactions and withdraw them to the bank card or Alipay. When operating, you need to pay attention to choosing a regulated platform, confirm transaction security and handling fees.

HTML5, CSS and JavaScript should be efficiently combined with semantic tags, reasonable loading order and decoupling design. 1. Use HTML5 semantic tags, such as improving structural clarity and maintainability, which is conducive to SEO and barrier-free access; 2. CSS should be placed in, use external files and split by module to avoid inline styles and delayed loading problems; 3. JavaScript is recommended to be introduced in front, and use defer or async to load asynchronously to avoid blocking rendering; 4. Reduce strong dependence between the three, drive behavior through data-* attributes and class name control status, and improve collaboration efficiency through unified naming specifications. These methods can effectively optimize page performance and collaborate with teams.

USDT cash exchange needs to be operated through a trading platform that supports fiat currency withdrawal. 1. Prepare a trading platform account that supports fiat currency withdrawal (such as Binance, Ouyi, Huobi, etc.); 2. Complete KYC real-name authentication; 3. Bind bank cards or Alipay and other payment methods; 4. Log in to the account and ensure that USDT is in the fund account or spot account; 5. Enter the OTC or fiat currency area and choose to sell USDT; 6. Set the sales amount and match the buyer; 7. After confirming the other party’s payment, click “Confirm Coin Delivery” to complete the transaction. Withdrawal methods include OTC fiat currency transactions, bank card withdrawals and third-party payments, among which OTC is more efficient. Notes include making sure to verify that the money is received before releasing, avoiding frequent large withdrawals, and contacting customer service in time when encountering abnormalities. The key to the entire process is to choose

PHP ensures inventory deduction atomicity through database transactions and FORUPDATE row locks to prevent high concurrent overselling; 2. Multi-platform inventory consistency depends on centralized management and event-driven synchronization, combining API/Webhook notifications and message queues to ensure reliable data transmission; 3. The alarm mechanism should set low inventory, zero/negative inventory, unsalable sales, replenishment cycles and abnormal fluctuations strategies in different scenarios, and select DingTalk, SMS or Email Responsible Persons according to the urgency, and the alarm information must be complete and clear to achieve business adaptation and rapid response.

Bitcoin does not have an official app, and users mainly trade and manage them through third-party exchanges or account apps. 1. Binance has comprehensive functions and is suitable for all kinds of traders; 2. OKX provides integrated trading and Web3 accounts; 3. Huobi (HTX) is stable and reliable in the Asian market; 4. Gate.io is known for its rich currency; 5. KuCoin has diverse currencies and active communities; 6. Bybit is known for its derivatives trading. When downloading, you should visit the official website, scan the QR code, complete the installation according to the system, and set up security measures such as two-factor verification to ensure the security of the account.
