New knowledge of game API access

First of all, the API full name (Application Programming Interface, application programming interface) is some predefined functions, or the convention of connecting different components of a software system. The purpose is to provide applications and developers with the ability to access a set of routines based on certain software or hardware without having to access the source code or understand the details of the internal working mechanism.

API definition

For many product Xiaobai or job seekers, API is a professional term in the field of product and R & D. you may have touched the concept of API in the article or PRD.

In fact, the application of interface has been very extensive and mature. This concept is mainly active in the connection and docking of various systems within the company and the scene of cooperation between companies. If you can read this article carefully, I believe you will have a deeper understanding of API interface, even more than 90% of Xiaobai and job seekers.

Contents

  1. What is the API API interface of the game?
  2. Why do we need the API API interface?
  3. The core of API API interface

The core of API API interface

我们来以一个常见的数学公式理解API,比如y=x+2,当x=2的时候,y=4,对么?

At this time, we call y = x + 2 as the interface, x = 2 as the parameter, y = 4 as the return result. The function of this interface is to add 2 to the number we input (Note: Here you can find that the interface itself has logic).

类比地,我们来理解一个常见的场景,比如现在有一个可以把经纬度转化为城市的接口,那当我输入经度是55°,纬度是88°的时候,接口通过自己的逻辑运算,返回结果告诉我:杭州市。

In this way, you can clearly understand the official interpretation of Baidu Encyclopedia. The interface is a predefined function logic, which is used by other systems to request and return results.

2、 Why do we need game API?

Background: our business system involves many aspects. If we want a company or a system to finish all the business, is the workload too heavy? And if other systems or companies have better operational logic, we can consider using interfaces for development when designing functions.

Core requirements: using existing interfaces can reduce development costs and shorten development costs.

For example: for example, I am an app that makes games. Now I need to show the functions of games on my page. For our company, the cost of new development is too high. Then we can access the API provided by the open platform of ngapi interface provider. In this way, we only need to apply for API interface account opening, deploy and call ngapi interface API, so we can quickly launch a rich game platform on our page.

游戏API接口接入

3、 The core of API

For Xiaobai, at first glance, the API documents may be confused - where to look, how to look, and what is the problem in front of him.

In fact, for product managers, we should pay more attention to what kind of API services this company can provide. For example, I know that Gaud can provide map API and route planning API, so that we can think of calling their services or references in our design functions and work.

所以产品小白们看不懂也不用过于担心,未来工作中你也会更深入了解清楚,因为看懂并不复杂,以下是API接口的核心点,所有的说明文档离不开这5个核心点。

以下说明均以微信开放平台为例说明,文末有各开放平台的地址,大家有空可以去学习。好了,事不宜迟,现在我们来建立一个场景。

We now have an app that requires users to set up the wechat payment API to complete the purchase. Please enter the scene automatically and regard yourself as a product manager.

1. Interface address

Now, users click to pay. We need to tell wechat that we need to set up your cashier! But where to tell? This requires the interface address, which is equivalent to transferring the specified data to the wechat link.

A link address is not a page we understand, you can understand it is a phone number, Xiaobai people want to change this concept.

At this time, we can see that the interface document tells us that the link is as follows. Then we have already called wechat.

2. Request parameters (message)

Now we need to tell wechat that you want to call the cashier, right. Then we need to write it down. The message generated at this time is called a message, that is, what do you want to tell the content of this interface? Equivalent to the input x = 2 of the previous function.

Generally speaking, the format and content of the message are specified according to the interface document. For example, the following is the message requirements of wechat open platform for starting the cash register.

游戏API接口是什么

我们先来看前2个参数,你现在跟微信在对话,是不是应该先告诉微信,你是谁?这里微信的文档告诉你应该要用应用ID+商户号来确定你的身份,什么意思呢?

For example, if you are a merchant, there are three apps a, B and C below, so wechat needs to know which merchant you are and which app below needs to use the cash register. This is very important. After wechat, you need to type the received money into the corresponding account and statistics.

那我们就在报文里面写下这两句话:

  • ≪ appid & gt; wx2421b1c4370ec43b & lt; / appid & gt; (my app ID is wx2421 ).
  • ≪ MCH & ID & gt; 10000100 & lt; / MCH & ID & gt; (my merchant ID is 10000 ).

OK, now that wechat knows who you are, you need to tell wechat how much money you need to pay for you, right? The currency type and total amount are defined here, that is, what currency and how much money to collect.

游戏API接口是什么

Here you can see whether the currency type must be filled in, that is to say, you can also not tell what the wechat payment currency type is, because he noted that the default is RMB later.

好的,那我们写下两段报文

  • ≪ Free U type & gt; CNY & lt; / Free U type & gt
  • ≪ total fee & gt; 1 & lt; / total fee & gt

好了,现在微信知道你是谁,也知道要收多少钱了,那接下来微信支付要把收钱结果告诉你呀,因为你得知道用户是成功支付了才能继续发货,服务啊等等的。所以这里我们用到通知地址,就是告诉微信,等下完事了他去哪里告诉你支付结果。那我们把地址写好:

<notify_url>http://wxpay.wxutil.com/pub_v2/pay/notify.v2.php</notify_url>

3. Return results

Just now, wechat payment has gone to collect money. Now he will tell us the result in the notice address we left. There are only two results: successful collection? Collection unsuccessful?

(1) Success

很顺利,现在用户成功付钱了,并且微信也把成功的消息告诉我们了,并且他还把用户支付的一些信息也告诉我们。

This is the information that wechat tells us after the payment is successful.

游戏API接口是什么

App appid, merchant No.: tell you which merchant and which appid transaction I successfully deducted.

Business result: success or failure

(2) Failure

In product design, we often pay attention to failure. When collection fails, wechat will also tell you the reasons for failure, as shown in the figure below. There are many reasons for failure. When designing, we often analyze the reasons for each failure, and design pages and user prompts for the reasons of each failure to ensure that users can understand.

游戏API接口是什么

The above is the understanding of the basic operation mode of API. Next, I will continue to update some more in-depth and detailed key elements of API, such as request mode / signature / encryption and decryption, etc.

comment0

请先

Login / registration
Administrator Login