Home  >  Article  >  WeChat Applet  >  How to retrieve kintone record information in WeChat

How to retrieve kintone record information in WeChat

云朵
云朵Original
2017-11-29 14:13:273082browse

Summary

In recent years, more and more people are using WeChat official accounts, and our lifestyles have also undergone tremendous changes.

Kintone is naturally not to be left behind and keeps up with the times.

This article will introduce you to the method of retrieving kintone record information in the WeChat public account.

To put it simply, we will create a new application for managing corporate information in kintone, and then enter keywords in the WeChat official account to retrieve the information in the application.

Since the official public account requires certification, this time we temporarily use the WeChat public account test account.

What it looks like after completion

How to retrieve kintone record information in WeChat

##Preparation

kintone settings


First create based on the above idea kintone application. What I created is a simple version of an enterprise information management application.

Field typeField nameField codeRemarksCreatorCreatorCreatorCreation timeCreation TimeCreation time##Single-line text boxSet as requiredSingle-line text boxSingle line text boxSingle line text boxSingle line text box

After the application is successfully created, enter three pieces of data

How to retrieve kintone record information in WeChat

WeChat public account settings

1. Visit WeChat public platform and click "Enter the WeChat public account test account application system" and apply for the WeChat public account test account

How to retrieve kintone record information in WeChat

2. Enter the WeChat public test account

for testing In the account management page, we can see the appID and appsecret. Write down these two pieces of information, it will be useful later.

How to retrieve kintone record information in WeChat

3. Fill in the interface configuration information

This information requires its own server resources. There are many cloud server resources online, and everyone can choose freely.

If you have a server with a public IP, you can also use it. Below we mainly use the PHP environment (the specific server configuration method is omitted)

Next, write the server verification code to make it Can correctly respond to the Token verification sent by WeChat. For details, please refer to Access Guide.

How to retrieve kintone record information in WeChat

##Code

<?php
define("APPID", "wxcbfaxxxxxx1814d4");  //appID
define("APPSECRET", "604113xxxxxxxxxxxxxxx0bda2240c47"); //appsecret 
define("TOKEN", "cnDevNet"); //Token

require "./wechat.inc.php";
$wechat = new WeChat(APPID, APPSECRET, TOKEN);
$wechat->valid(); //Token验证
?>
class WeChat
{
    private $_appid;
    private $_appsecret;
    private $_token;
    
    public function __construct($appid, $appsecret, $token)
    {
        $this->_appid = $appid;
        $this->_appsecret = $appsecret;
        $this->_token = $token;
    }

    public function valid()
    {
        $echoStr = $_GET["echostr"];

        //valid signature , option

        if($this->checkSignature())

        {
            echo $echoStr;
            exit;
        }
    }

    private function checkSignature()
    {
        $signature = $_GET["signature"];
        $timestamp = $_GET["timestamp"];
        $nonce = $_GET["nonce"];

        $token = $this->_token;
        $tmpArr = array($token, $timestamp, $nonce);
        sort($tmpArr);
        $tmpStr = implode( $tmpArr );
        $tmpStr = sha1( $tmpStr );
        
        if( $tmpStr == $signature )
        {
            return true;
        }
        else
        {
            return false;
        }
    }
}

Click "Modify" of the interface configuration information, After filling in the URL and Token, click the "Submit" button.

If you see the following information, the configuration is successful.


How to retrieve kintone record information in WeChat

Associated with kintone

The following is the main schematic diagram. WeChat forwards the message to the server, and after the server interacts with kintone, the result is returned to the official account.


How to retrieve kintone record information in WeChat

To interact with kintone, we mainly use the curl tool and kintone's API to retrieve records. For details, please refer to

php documentation and kintone API: Get records in batches (specify conditions in the query) .

// 请求头部
$header = array(

    "Host: " . $this->_subDomain . ".cybozu.com:443",
    "X-Cybozu-API-Token: " . $this->_apiToken
);

$queryStr = &#39;company like "&#39;. $keyword. &#39;"&#39;;
$params = "?app=$this->_appId&query=".urlencode($queryStr)
            . "&fields[0]=". urlencode("company")
            . "&fields[1]=". urlencode("representative")
            . "&fields[2]=". urlencode("area")
            . "&fields[3]=". urlencode("address")
            . "&fields[4]=". urlencode("tel");

$url = "https://" . $this->_subDomain . ".cybozu.com/k/v1/records.json". $params;

$response = $this->_request($url, true, "get", null, $header); //curl提交
$result = json_decode($response, true);

if (count($result["records"]) > 0) {
    foreach($result["records"] as $value) {
        if ($contentStr != &#39;&#39;) {
            $contentStr .= "\n\n";
        }
        $contentStr .= "公司名:".     $value["company"]["value"]."\n"
                        . "公司代表:". $value["representative"]["value"]."\n"
                        . "地域:".     $value["area"]["value"]."\n"
                        . "所在地:".   $value["address"]["value"]."\n"
                        . "电话:".     $value["tel"]["value"];
    }
}
else {
    $contentStr = "未找到该企业信息";
}

Detailed code

All codes can be viewed here

Reference

WeChat public platform technical documentation



Company name company

The value is unique

Company representative representative
Region area
Location address
Company phone number tel

The above is the detailed content of How to retrieve kintone record information in WeChat. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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