Paying for knowledge online and subscribing to WeChat official account

Time:2022-4-21

Subscription notification is a notification capability that users actively subscribe and service numbers are issued on demand. Please observe the wechat public platform service agreement and wechat public platform operation specification during the use process. After the user actively subscribes in the above scenario, the service number can send subscription notices to the user through the interface, such as credit card dynamic account reminder, logistics arrival notice, etc. Subscription notification is divided into one-time subscription and long-term subscription. One-time subscription refers to that the user subscribes once, and the service number can send a corresponding subscription notification at any time; Long term subscription refers to that the user subscribes once, and the service number can issue notices for many times for a long time. Long term subscription notices are only open to public service fields such as government affairs, people’s livelihood and medical treatment.
The difference between wechat subscription messages and wechat template messages is that template messages can be sent directly to users regardless of users’ subjective consciousness; The subscription message must be approved by the user before it can be sent to the user. This avoids harassment to users.
Because wechat plans to use subscription messages to replace template messages, knowledge payment adds the function of subscribing to messages. The knowledge payment system can choose whether to use template messages or subscribe to messages. Now let’s take a look at how knowledge payment adds the function of subscribing to messages.
Through WeChat documents, we can see that the subscription information of WeChat official account is selected through the wx-open-subscribe tag. The following examples:
<wx-open-subscrib template=”TenvU22BA1jCp4YHfYEpRuESXYReQyDuhs4vbdWA99I” id=”subscribe-btn”>
<script type=”text/wxtag-template” slot=”style”>

<style>
  .subscribe-btn {
    color: #fff;
    background-color: #07c160;
  }
</style>

</script>
<script type=”text/wxtag-template”>

<button class="subscribe-btn">
  One time template message subscription              
</button>

</script>
</wx-open-subscribe>
<script>
var btn = document.getElementById(‘subscribe-btn’);
btn.addEventListener(‘success’, function (e) {
console.log(‘success’, e.detail);});
btn.addEventListener(‘error’,function (e) {
console.log(‘fail’, e.detail);
});
</script>
According to the example, we can know that you can use the Wx open subscribe tag to pass in the template attribute of the subscription message template ID that you need to pop up. Multiple are separated by English commas.
How is knowledge payment realized?
The first is front-end display, paying for knowledge online, selecting WeChat payment and then adjusting the WeChat subscription message, and index. in the root directory of the project, public/wap/first/zsff/components/payment. In HTML, we add the tag of subscription message and pass in the required template ID.
<wx-open-subscribe

v-if="isWechat && templateId"
:template="templateId"
@success="onSuccess"
@error="onError"
<script type="text/wxtag-template" slot="style">
    <style>
        button {
            display: block;
            width: 100%;
            height: 40px;
            border-radius: 20px;
            border: none;
            background-color: #2c8eff;
            font-family: inherit;
            font-weight: normal;
            font-size: 14px;
            color: #fff;
        }
      </style>
</script>
<script type="text/wxtag-template">
    < button > pay now < / button >
</script>

</wx-open-subscribe>

After the user completes the selection, the order function is executed, and the background sends the corresponding subscription message according to the user's selection results.
 In paying for knowledge online, there are all interfaces in RoutineTemplateService class of extend/service, which are subscribed to WeChat official account. SendTemplate is a way to send subscriptions to users. By this method, we can send various subscription messages.

The routinetemplate class in the root directory of knowledge payment application \ WAP \ model \ route is the sending method of each subscription message. The following is a subscription message sent successfully by the official account, where all the indexes in $data should be consistent with the subscription message added in WeChat public platform.
$data[‘character_string1’][‘value’] = $orderId;
$data[‘amount3’][‘value’] = $order[‘pay_price’];
$data’time2′ = date(‘Y-m-d H:i:s’,time());
$data ‘thing6’ = ‘the topic you purchased has been paid successfully!’;
RoutineTemplate::sendOrderSuccess($data,$order[‘uid’],$site_url . Url::build(‘wap/special/grade_list’));

In this way, we have realized the wechat message subscription function.
If you think this article is useful to you, please click Star:http://github.crmeb.net/u/defuesteem it a favor!