Table of Contents
php development WeChat payment to obtain user address, php development to obtain user
Home Backend Development PHP Tutorial PHP development WeChat payment to obtain the user address, PHP development to obtain the user_PHP tutorial

PHP development WeChat payment to obtain the user address, PHP development to obtain the user_PHP tutorial

Jul 12, 2016 am 09:07 AM
WeChat Pay

php development WeChat payment to obtain user address, php development to obtain user

Using WeChat to obtain address information is applied together with WeChat payment. If the WeChat payment application is passed, you can use this function .

In WeChat Mall, using WeChat Pay to obtain the user's delivery address can omit the complicated process of users entering address information and improve user experience.

However, it may be because it involves user privacy, so during the use process, the user needs to actively choose to use this function, and only through a click operation can we obtain the user's delivery address. This should be noted of.

The operation process is as follows:

1. The user opens the shopping cart page, clicks checkout, and jumps to a WeChat oauth2 page at the address: https://open.weixin.qq.com/connect/oauth2/authorize

2.oauth2 page redirects the link to the settlement page, uses PHP to obtain the code parameter in the link, and obtains the accessToken value after processing. Generate a signature, assemble it into an array of parameters and pass it to the page.

3. The settlement page uses user click events and combines the array parameters generated in 2 to complete the function of obtaining the address. There can be a function here to record the obtained address into the database using ajax, so that the customer will not have to worry about it next time he or she makes a purchase.

Let’s talk about the points that need to be paid attention to in detail:

1. The step of jumping to WeChat oauth2 is not much different from the user's point of view, but there are a lot of things to do in the program. The first is the parameters of the oauth2 page, where appid is the WeChat appid, redirect_uri is the address of the order settlement page after urlencode, response_type is a fixed code, scope is a fixed snsapi_base, state can be filled in at will, and there is also a #wechat_redirect. Then the final look of the link is:

https://open.weixin.qq.com/connect/oauth2/authorize?appid=APPID&redirect_uri=Order settlement address&response_type=code&scope=snsapi_base&state=Feel free #wechat_redirect

2. The user accesses this address and is redirected to the order settlement address with the added code parameter. On this page, the accessToken needs to be obtained by the program. Note that the accessToken is the accessToken for obtaining user information and another access for interacting with WeChat. The tokens are not the same.

You can obtain the accessToken using GET request, you can use curl or file_get_contents. The request address is:

https://api.weixin.qq.com/sns/oauth2/access_token?appid=APPID&secret=APP_SECRET&code=CODE&grant_type=authorization_code;

One thing to note here is that sometimes WeChat has a seizure and requests the order settlement page multiple times in a row, causing the accessToken to become invalid and requires special handling.

The signature generation here is different from the signature in WeChat payment. It is much simpler. It just encrypts a string. The format is: accesstoken=ACCESSTOKEN&appid=APPID&noncestr=32-digit random string×tamp=timestamp&url=current page URL, and then perform sha1 encryption on the string.

A series of parameters need to be used in the front-end page to achieve the function of obtaining the address, namely appID, scope (default is jsapi_address), signType (default is sha1), addrSign (the string encrypted by sha1 above), timeStamp ( timestamp as above), nonceStr (random string as above).

3. On the front-end page, use the following js function to complete the operation of obtaining the user address:

function get_addr()
{
  WeixinJSBridge.invoke('editAddress',{
  "appId" : "<&#63;php echo $sign['appId']&#63;>",
  "scope" : "jsapi_address",
  "signType" : "sha1",
  "addrSign" : "<&#63;php echo $sign['addrSign']&#63;>",
  "timeStamp" : "<&#63;php echo $sign['timeStamp']&#63;>",
  "nonceStr" : "<&#63;php echo $sign['nonceStr']&#63;>",
  },function(res){
  if(res.err_msg == 'edit_address:ok')
  {
      
      
      //将地址信息存入数据库
      //将地址信息显示在当前页面
      
      document.getElementById("address_info").innerHTML="<b>收件人:"+res.userName+"</b>   <b>"+res.telNumber+"</b><br /> 收货地址:"+res.proviceFirstStageName+res.addressCitySecondStageName+res.addressCountiesThirdStageName+res.addressDetailInfo;
      
 } else{ alert("获取地址失败,请重新点击"); } }); }

Copy after login

At this point, the development of using WeChat to obtain user shared addresses is completed.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1058151.htmlTechArticlephp development WeChat payment to obtain the user address, php development to obtain the user's address information using WeChat is applied together with WeChat payment , if the WeChat payment application is passed, you can use this function. ...
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

If you forget your WeChat payment password, how to retrieve it? If you forget your WeChat payment password, how to retrieve it? Feb 23, 2024 pm 09:40 PM

In WeChat, users can enter their payment password to make purchases, but how do they retrieve their payment password if they forget it? Users need to go to My-Services-Wallet-Payment Settings-to recover their payment password if they forget it. This introduction to how to retrieve your payment password if you forget it will tell you the specific operation method. The following is a detailed introduction, so take a look! WeChat usage tutorial. How to find the WeChat payment password if you forget it? Answer: My-Service-Wallet-Payment Settings-Forgot payment password. Specific method: 1. First, click My. 2. Click on the service inside. 3. Click on the wallet inside. 4. Find the payment settings. 5. Click Forgot payment password. 6. Enter your own information for verification. 7. Then enter the new payment password to change it.

What should I do if I forget my WeChat payment password? What should I do if I forget my WeChat payment password? Jan 08, 2024 pm 05:02 PM

Solution for forgetting WeChat payment password: 1. Open WeChat APP, click "I" in the lower right corner to enter the personal center page; 2. In the personal center page, click "Pay" to enter the payment page; 3. On the payment page , click "..." in the upper right corner to enter the payment management page; 4. In the payment management page, find and click "Forgot payment password"; 5. Follow the page prompts and enter personal information for identity verification. After successful verification, you can Choose the method of "retrieve by swiping your face" or "retrieve by verifying bank card information" to retrieve your password, etc.

How to set up WeChat payment for Meituan Takeout How to set up WeChat payment How to set up WeChat payment for Meituan Takeout How to set up WeChat payment Mar 12, 2024 pm 10:34 PM

There are many food and snack shops provided in the Meituan takeout app, and all mobile phone users log in through their accounts. Add your personal delivery address and contact number to enjoy the most convenient takeout service. Open the homepage of the software, enter product keywords, and search online to find the corresponding product results. Just swipe up or down to purchase and place an order. The platform will also recommend dozens of nearby restaurants with high reviews based on the delivery address provided by the user. The store can also set up different payment methods. You can place an order with one click to complete the order. The rider can arrange the delivery immediately and the delivery speed is very fast. There are also takeout red envelopes of different amounts for use. Now the editor is online in detail for Meituan takeout users. We show you how to set up WeChat payment. 1. After selecting the product, submit the order and click Now

How to set the order of deduction for WeChat payment How to set the order of deduction for WeChat payment Sep 06, 2023 am 11:11 AM

Steps to set the order of deductions for WeChat payment: 1. Open the WeChat APP, click on the "Me" interface, click on "Services", and then click on "Collect and Payment"; 2. Click on "Prioritize Use This Payment Method" under the payment code on the collection and payment interface; 3. Select the preferred payment method you need.

Can Xianyu pay with WeChat? How to change to WeChat payment method? Can Xianyu pay with WeChat? How to change to WeChat payment method? Mar 12, 2024 pm 12:19 PM

When everyone has nothing to do, they will choose to browse the Xianyu platform. Everyone can find that there are a large number of products on this platform, which can allow everyone to see various second-hand products. Although these products are second-hand products, there is absolutely no problem with the quality of these products, so everyone can buy them with confidence. The prices are very affordable, and they still allow everyone to face-to-face with these products. It is entirely possible for sellers to communicate and conduct some price bargaining operations. As long as everyone negotiates properly, then you can choose to conduct transactions, and when everyone pays here, they want to make WeChat payment, but it seems that the platform It's not allowed. Please follow the editor to find out what the specific situation is. Xianyu

Sharing the steps to apply for a refund with WeChat Pay Sharing the steps to apply for a refund with WeChat Pay Mar 25, 2024 pm 06:31 PM

1. First, we need to open the WeChat APP on the mobile phone, and then click to log in to the WeChat account, so that we enter the WeChat homepage. 2. Click the [Me] button in the lower right corner of the WeChat homepage, then select the [Payment] option. We click to enter the payment page. 3. After entering the [Payment] page, click the [Wallet] option to enter, and click [Bill] in the upper right corner of the [Wallet] page.

Does WeChat Pay need to bind a bank card? Does WeChat Pay need to bind a bank card? Nov 17, 2022 am 11:57 AM

WeChat Pay does not need to be bound to a bank card. WeChat payment can be used without binding a bank card, provided that real-name authentication is carried out. As long as the real-name authentication is passed, you can use WeChat change to send red envelopes, transfer, collect money, WeChat payment and other operations. It should be noted that WeChat cannot withdraw cash if it is not bound to a bank card, and there are limits on receipts, payments, transfers, etc., with a maximum of 200 yuan for a single transaction and daily, and a maximum of 500 yuan per month.

How to set up WeChat payment on Didi Chuxing How to set up WeChat payment How to set up WeChat payment on Didi Chuxing How to set up WeChat payment Mar 13, 2024 pm 01:22 PM

The Didi Chuxing app provides more convenience for everyone's daily travel. You can go wherever you want, and all Didi vehicles are on call. You no longer need to wait anxiously. Dozens of taxi red envelopes are available for free. Travel faster. Open the homepage of the software, enter the starting point and destination according to your personal itinerary, and freely choose from vehicles of different prices below. Place an order with one click and publish the itinerary. Didi drivers will receive the order in seconds and arrive at the designated location as quickly as possible. For the location, just check your mobile phone number before getting on the bus. Of course, there are many ways to pay for the fare, including WeChat and Alipay, but everyone usually uses WeChat. It is easy to set up payment with one click. Now the editor is online carefully paying for Didi one by one. Travel users bring how to set up WeChat payment. 1. We are on the mobile phone

See all articles