preface

Recently, when I visited blogs, I found that many blogs have the reward function. Although there may be few people to reward, it is always a kind intention to let bloggers know that their articles are useful and can help people. So I also want to add a reward function~

analysis

However, after a tour of github, we found that the reward plug-in was basically the same: QQ scanning code/WeChat scanning code/Alipay scanning code.

 Button Donation

Some click each button to display each collection code

 QR code donation

Others show all the collection codes

WeChat scanning this, Alipay scanning that, not only need to load multiple QR codes, but also add CSS/js to make it look good. As a lazy program ape who doesn't want to write these things, this is no good.

Can you combine QQ WeChat Alipay into one by scanning a collection code?
One knowledge point involved here is User Agent. The webviews of Dachang will carry their own UA information, such as:

QQ: MQQBrowser/6.2 TBS/043221 Safari/537.36 QQ/7.0.0.3135
WeChat: MQQBrowser/6.2 TBS 043220 Safari/537.36 MicroMessenger/6.5.8.1060 NetType/4G Language/zh_CN
Alipay: UCBrowser/11.5.0.939 UCBS/2.10.1.6 Mobile Safari/537.36 AliApp(AP/10.0.15.051805) AlipayClient/10.0.15.051805 Language/zh-Hans

This makes it easy to distinguish between QQ, WeChat or Alipay scanning:

User Agent contains QQ/ For QQ
User Agent contains MicroMessenger WeChat
User Agent contains AlipayClient For Alipay

Since each software can be distinguished, it is possible to distribute different collection codes by creating a website, scanning the website generated by the QR code, and judging the UA of the browser

The general process is as follows:
Client code scanning ->the server judges the client type according to User Agent ->returns different processing

Start tossing

First decode the collection code generated by QQ, WeChat and Alipay. You can to this place, please Online decoding.

QQ: https://i.qianbao.qq.com/wallet/sqrcode.htm?m=tenpay&a=1&u=17878127&ac=E04BE442991E7FFED28B3B5C3E187148F063DC3C6DACAD2983C87B482FC9E7AD&n= Schrodinger's Cat&f=wallet
(https protocol, unable to wake QQ)
Alipay: HTTPS://QR. ALIPAY. COM/FKX03549OW666ME7BXWF7A
(https protocol, you can directly wake up Alipay APP)
WeChat: wxp://f2f09hjzo72AAYEITIBaolV-3cvGrDjE0q7k
(WeChat's own payment agreement, unable to wake up WeChat)

Now you can write the code directly to judge whether the User Agent will directly jump to Alipay if it is Alipay, or jump to QQ and WeChat if it is QQ and WeChat.

However, since QQ and WeChat can't directly wake up the APP, it directly outputs a QR code of QQ and WeChat, and then long press to scan the code to realize payment.

The codes are as follows:

 <? php $ua = $_SERVER['HTTP_USER_AGENT']; if (strpos($ua, 'MicroMessenger')) { $type = 'wepay'; $name='WeChat payment'; //WeChat payment link $url = ' wxp://f2f09hjzo72AAYEITIBaolV-3cvGrDjE0q7k '; $icon_img = '<img src=" https://sangsir.com/usr/uploads/sina/5e834b9da7b25.jpg " width="48px" height="48px" alt="'.$ name.' ">'; } elseif (strpos($ua, 'AlipayClient')) { //Alipay link $url = 'HTTPS://QR. ALIPAY. COM/FKX03479QJ0RVOS3UJLQAE'; header('location: ' . $url); } elseif (strpos($ua, 'QQ/')) { $type = 'qq'; $name='QQ wallet payment'; //QQ wallet payment link $url = ' https://i.qianbao.qq.com/wallet/sqrcode.htm?m=tenpay&a=1&u=17878127&ac=E04BE442991E7FFED28B3B5C3E187148F063DC3C6DACAD2983C87B482FC9E7AD&n= Schrodinger's Cat&f=wallet '; $icon_img = '<img src=" https://sangsir.com/usr/uploads/sina/5e834b9f9dd09.jpg " width="48px" height="48px" alt="'.$ name.' ">'; } else { $type = 'other'; $name='Reward the author'; $url = 'http://'.$_ SERVER['HTTP_HOST'].$_ SERVER['REQUEST_URI']; $icon_img = '<img src=" https://sangsir.com/usr/uploads/sina/5e834ba0ae5f8.jpg " width="48px" height="48px" alt="'.$ name.' ">'; } $qr_img = '<img src=" http://qr.liantu.com/api.php?text= '.urlencode($url).' ">'; ?> <! DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta name="renderer" content="webkit"> <meta http-equiv="X-UA-Compatible" content="IE=Edge, chrome=1"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title><?=$ name?></ title> <style type="text/css"> * {margin: auto;padding: 0;border: 0;} html {-ms-text-size-adjust: 100%;-webkit-text-size-adjust: 100%} body {font-family: -apple-system, SF UI Text, Arial, Microsoft YaHei, Hiragino Sans GB, WenQuanYi Micro Hei, sans-serif;color: #333;} img {max-width: 100%;} h3 {padding: 10px;} .container {text-align: center;} .title {padding: 2em 0;background-color: #fff;} .content {padding: 2em 1em;color: #fff;} .wepay {background-color: #23ac38;} .qq {background-color: #4c97d5;} .other {background-color: #ff7055;} </style> </head> <body class="<?=$type?>"> <div class="container"> <div class="title"><?=$ icon_img?>< h1><?=$ name?></ h1></div> <div class="content"><?=$ type=='other'?$ qr_img.'< H3>Please use Alipay, WeChat and QQ clients to scan the code for payment</h3>': $qr_img.'< H3>Scan or long press the QR code to pay TA</h3>'?></ div> </div> </body> </html>

Demo Demo

You can test by scanning the QR code at the bottom of the article, or click the following demo address:
http://lab.sangsir.com/api/donate.php

By the way, reward the author?

Last modification: February 26, 2018
If you think my article is useful to you, please feel free to appreciate it