WeChat payment Development (6) Receiving address sharing interface and Wechat payment interface development

Source: Internet
Author: User

Payment Development (6) Receiving address sharing interface and payment interface development

Keywords: Payment and Receipt address sharing
Author: Fang Times studio
Original article: http://www.cnblogs.com/txw1958/p/weixin-editAddress.html

 

This article describes the development process of the shipping address sharing interface under payment.

I. Introduction

Shipping address sharing means that after you open a webpage in your browser and enter the address, you can quickly select or add or edit the address without entering it. This address is a user attribute and can be shared on the webpage of each merchant. Native controls are supported to enter the address, and the address data is transmitted to the merchant.

Address sharing is implemented based on JavaScript APIs and can only be used in Built-in browsers. Other browser calls are invalid. At the same time, version 5.0 is required. We recommend that you use the user agent to determine the current version number and then call the address interface. Take the iPhone version as an example. You can use useragent to obtain the following sample information: "Mozilla/5.0 (iphone; CPU iphone OS 5_1_1 like Mac OS X) AppleWebKit/534.46 (KHTML, like Geocko) mobile/9B206MicroMessenger/5.0 "5.0 indicates the version number installed by the user. The Merchant can determine whether the version number is higher than or equal to 5.0.

Address format
Data fields used for address sharing include:

  • Recipient Name
  • Level 3, region, province, city
  • Detailed address
  • Zip code
  • Contact number

The region corresponds to the third-level geocode of the national standard, for example, "Guangdong province-Guangzhou-Tianhe District", and the corresponding zip code is 510630. Http://www.stats.gov.cn/tjsj/tjbz/xzqhdm/201401/t20140116_501070.html for details

 

Ii. OAuth2.0 authorization

Before obtaining the shipping address, you must call the logon authorization interface to obtain the OAuth2.0 Access Token. Therefore, an authorization is required. The confirmation box is not displayed for this authorization.
The essence is that

http://www.fangbei.org/wxpay/js_api_call.php

Jump

https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx8888888888888888&redirect_uri=http://www.fangbei.org/wxpay/js_api_call.php&response_type=code&scope=snsapi_base&state=STATE#wechat_redirect

To obtain the code parameter, and obtain the authorized access_token and openid based on the code. This access token will be used for the shipping address sharing interface.

For details about the implementation process, refer to OAuth2.0 webpage authorization on the public platform development (71 ).

 

Ii. Obtain random strings

The method for generating random strings is as follows:

 

Iii. Generate a signature

The fields involved in the addrSign signature include: appId, url (webpage url that calls JavaScript APIs), timestamp, noncestr, and accessToken.
After all parameters to be signed are sorted in ascending order (lexicographically) according to the field name ASCII code, the format of the URL key-value pair is used (that is, key1 = value1 & key2 = value2 ...) Concatenate the string into string1.
Note that all parameter names are lowercase characters in the signature process. For example, if appId is sorted, the string is appid;
Use string1 as a signature algorithm. Both field names and Field Values use original values without URL escaping. The specific signature algorithm is addrSign = SHA1 (string1 ). The following is an example of generating an addrSign:

appId=wx17ef1eaef46752cburl=http://open.weixin.qq.com/timeStamp=1384841012nonceStr=123456accessToken=OezXcEiiBSKSxW0eoylIeBFk1b8VbNtfWALJ5g6aMgZHaqZwK4euEskSn78Qd5pLsfQtuMdgmhajVM5QDm24W8X3tJ18kz5mhmkUcI3RoLm7qGgh1cEnCHejWQo8s5L3VvsFAdawhFxUuLmgh5FRA

I: after sorting key-value pairs in process a, string1 is:

accesstoken=OezXcEiiBSKSxW0eoylIeBFk1b8VbNtfWALJ5g6aMgZHaqZwK4euEskSn78Qd5pLsfQtuMdgmhajVM5QDm24W8X3tJ18kz5mhmkUcI3RoLm7qGgh1cEnCHejWQo8s5L3VvsFAdawhFxUuLmgh5FRA&appid=wx17ef1eaef46752cb&noncestr=123456&timestamp=1384841012&url=http://open.weixin.qq.com/?code=CODE&state=STATE

Ii: after the signature of process B, you can obtain:

addrSign=SHA1(accesstoken=OezXcEiiBSKSxW0eoylIeBFk1b8VbNtfWALJ5g6aMgZHaqZwK4euEskSn78Qd5pLsfQtuMdgmhajVM5QDm24W8X3tJ18kz5mhmkUcI3RoLm7qGgh1cEnCHejWQo8s5L3VvsFAdawhFxUuLmgh5FRA&appid=wx17ef1eaef46752cb&noncestr=123456&timestamp=1384841012&url=http://open.weixin.qq.com/?code=CODE&state=STATE)=ca604c740945587544a9cc25e58dd090f200e6fb

The implementation code is as follows:

 

4. Obtain the shipping address

Edit and obtain the editAddress interface of the user's shipping address, which is called at the front-end of the webpage.
Parameter List:

Parameters Required Description
AppId Yes Public Account appID
Scope Yes Enter "jsapi_address" to obtain the edit address permission.
SignType Yes Signature method. Currently, only SHA1 is supported.
AddrSign Yes Signature. Each parameter is used for signature generation.
TimeStamp Yes Timestamp
NonceStr Yes Random string

The call method is as follows:

Parameter return:

Return Value Description
Err_msg Edit_address: OK. The shipping address is successfully edited.
Edit_address: fail failed to get and edit the shipping address.
Username Recipient Name
TelNumber Recipient's phone number
AddressPostalCode Zip code
ProviceFirstStageName National Standard Receiving address Level 1 Address
AddressCitySecondStageName Second-level Address of National Standard Receiving address
AddressCountiesThirdStageName National Standard Receiving address Level 3 address
AddressDetailInfo Detailed shipping address information
NationalCode Country code of the shipping address

 

 

V. Example

 

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.