How do you obtain a WeChat access_token certificate from api.wechat.com?
Asked Answered
E

5

5

This site tries to explain the process: http://admin.wechat.com/wiki/index.php?title=Access_token

The problem is nowhere do they tell you where to get the AppID or what exactly the secret is.Has anyone else succeeded in communicating with WeChat?

Epileptic answered 18/12, 2013 at 11:22 Comment(0)
O
9

Essentially we @ WeChat have 2 types of accounts, subscription and service. Subscription account only gives you access to the Message API which allows for receiving messages and autoresponses and allows you to broadcast to your users once a day. Subscription accounts are also grouped in a category in your contacts under subscription.

A service account gives you an APP ID and APP SECRET which allows you to generate an access token which is needed for pretty much all the other API's apart from the Message API. A service account displays in the user's contact list under the main chats in between all your other normal contacts. You can only broadcast to each of your users once a month on a service account.

If you have a service account you will get the APP ID and APP SECRET from admin.wechat.com -> login -> function -> advanced -> developer mode -> Just under your token you will see the APP ID and APP SECRET

To see what type of account you have go to admin.wechat.com -> login and then look at the top right of the screen next to your account name you will see your account name and just above that it will either say subscription account or service account.

If you want to test all the API's I recommend going to the developer sandbox environment where you get full access to all the API's: How does link with href for Line and Wechat?

Please note your number needs to be in the international format so 072 111 2233 you have to enter as +27721112233

Okoka answered 11/4, 2014 at 2:14 Comment(5)
Hello sir I am new in wechat sdk can u please tell me fo what purpose exactly that access token use so that i can figure out whether this is useful for my task or notIgor
Access token gets used for most calls:Okoka
I have a situation to shre multiple images on wechat .... is this will be use full for that ?Igor
Please look this question ....getting cofused please help me #25286887Igor
I just need a direction to move forward but I m even confused that all these feature is feasible or not .... i did mail to wechat developer but dint got reply ...please help me... right now I am able to upload one image on wechat... but want multiple if possibleIgor
O
0
  1. Login http://admin.wechat.com
  2. [advanced] --> [Developer Mode], you will got your Appid & AppSecret.
  3. You don't have a wechat OA account?
Overthrust answered 13/2, 2014 at 7:21 Comment(1)
Thanks, but I got in contact with we chat and they said we have the wrong type of official account to get a AppID. So we had to change our account and sacrifice automatic replies.Epileptic
C
0

You may go to http://dev.wechat.com/ to sign up for a developer account.

After you sign up, you will get your App ID and AppKey via your signup email.

Then, you can go to http://admin.wechat.com/wiki/index.php?title=Main_Page to obtain more information.

Crosscountry answered 18/2, 2014 at 19:1 Comment(1)
I did that. I see my id and secret. Trying to use them to get access_token, and api says "invalid appid hint". What else should I do to make it work?Bellinger
K
0

I wrote a code snippet on github that explains the entire process. The code is for django but can be used with any python framework

here is a snippet

import xml.etree.ElementTree as ET

from wechat.views import WeChatView


MyCustomView(WeChatView):
    token = "ad4sf65weG7Db6ddWE"

    on_message(self, message):

        root = ET.fromstring(message)

        from = root[1].text
        message_type = root[3].text
        content = root[4].text

        print('from: {}'.format(from))
        print('message type: {}'.format(message_type))
        print('content: {}'.format(content))

The full code is here https://github.com/tawanda/django-wechat

Kirsten answered 26/11, 2015 at 8:26 Comment(0)
R
-1

Here's my code,maybe you can try it.

//Getting access_token from customize menus 
static function get_access_token($appid,$secret){  
$url="https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=".$appid."&secret=".$secret;  
    $json=http_request_json($url);//here cannot use file_get_contents  
    $data=json_decode($json,true);  
    if($data['access_token']){  
        return $data['access_token'];  
    }else{  
        return "Error occurred while geting the access_token";  
    }         
}  
//Though URL request is https',cannot use file_get_contents.Using CURL while asking the JSON data  
function http_request_json($url){    
$ch = curl_init();  
curl_setopt($ch, CURLOPT_URL,$url);  
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);  
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);  
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);  
$result = curl_exec($ch);  
curl_close($ch);  
return $result;    
}
Rennarennane answered 6/1, 2014 at 6:53 Comment(1)
Thanks for the reply, but I'm still unsure where to get the appid?Epileptic

© 2022 - 2024 — McMap. All rights reserved.