WeChat Public Accounts များကိုကျယ်ကျယ်ပြန့်ပြန့်အသုံးပြုခြင်းဖြင့်ကုမ္ပဏီများနှင့်လူပုဂ္ဂိုလ်တစ် ဦး ချင်းစီသည်အကြောင်းအရာများကိုအကြောင်းအရာများကိုဖြည့်ဆည်းပေးရန်နှင့်ဓာတ်ပုံများကိုဂရပ်ဖစ်မက်ဆေ့ခ်ျများသို့ 0 င်ရောက်ရန်မျှော်လင့်ကြသည်။ ဤဆောင်းပါးသည် PHP ကို အသုံးပြု. PHP ကိုမည်သို့အသုံးပြုရမည်ကိုမိတ်ဆက်ပေးပြီး 0 င်ရောက်ခြင်း,
ဖွံ့ဖြိုးမှုမစတင်မီအောက်ပါပြင်ဆင်မှုများကိုဖြည့်ရန်လိုအပ်သည်။
WeChat တရားဝင်အကောင့် interface ကိုမခေါ်မီသင် access_token ကိုရယူရန်လိုအပ်သည်။ ၎င်းသည် WorChat interface မှ Global Crertential ဖြစ်သည်။ အောက်ပါသည် PHP နမူနာကုဒ်ဖြစ်သည်။
function getAccessToken($appId, $appSecret) {
$url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=".$appId."&secret=".$appSecret;
$result = file_get_contents($url);
$result = json_decode($result, true);
return $result['access_token'];
}
$appId = "your_app_id";
$appSecret = "your_app_secret";
$accessToken = getAccessToken($appId, $appSecret);
သင်၏တရားဝင်အကောင့်၏အမှန်တကယ် parameters များနှင့်သင်၏ trapp_id နှင့် your_app_secret ကိုအစားထိုးပါ။
access_token ကိုရယူပြီးနောက်ဂရပ်ဖစ်မက်ဆေ့ခ်ျ၏အချက်အလက်ဖွဲ့စည်းပုံကိုသင်ပြင်ဆင်နိုင်သည်။ ဂရပ်ဖစ်မက်ဆေ့ခ်ျတစ်ခုစီတွင်ခေါင်းစဉ်, ဖော်ပြချက်, image link နှင့်ခုန်ချိတ်ဆက်မှုပါ 0 င်သည်။ ဥပမာများမှာအောက်ပါအတိုင်းဖြစ်သည် -
$articles = array(
array(
'title' => "ဂရပ်ဖစ်မက်ဆေ့ခ်ျကိုခေါင်းစဉ်1",
'description' => "ဂရပ်ဖစ်မက်ဆေ့ခ်ျကိုဖော်ပြချက်1",
'url' => "http://example.com/article1",
'picurl' => "http://example.com/article1.jpg"
),
array(
'title' => "ဂရပ်ဖစ်မက်ဆေ့ခ်ျကိုခေါင်းစဉ်2",
'description' => "ဂရပ်ဖစ်မက်ဆေ့ခ်ျကိုဖော်ပြချက်2",
'url' => "http://example.com/article2",
'picurl' => "http://example.com/article2.jpg"
),
);
သတင်းအချက်အလက်များကိုပိုမိုတွန်းအားပေးရန်အတွက်လိုအပ်သည့်ဂရပ်ဖစ်အကြောင်းအရာများစွာကိုသင်ထည့်နိုင်သည်။
ဂရပ်ဖစ်အကြောင်းအရာများကိုတည်ဆောက်ပြီးနောက်၎င်းကို WeChat ၏ Group Sending interface မှတဆင့်တွန်းအားပေးနိုင်သည်။ အောက်ဖော်ပြပါသည် PUPT တောင်းဆိုမှုဥပမာတစ်ခုမှာ Php ဖြစ်သည်။
function sendArticles($accessToken, $articles) {
$url = "https://api.weixin.qq.com/cgi-bin/message/mass/send?access_token=".$accessToken;
$data = array(
'touser' => "@all",
'msgtype' => "news",
'news' => array('articles' => $articles)
);
$jsonData = json_encode($data);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonData);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
return $response;
}
$response = sendArticles($accessToken, $articles);
Push ကိုအောင်မြင်ရန်ရရှိသော access_token နှင့်အတူ variable ကို $ accesStens နှင့်အတူအစားထိုးပါ။
အထက်ပါအဆင့်များမှတစ်ဆင့်သင် WeChat တရားဝင်အကောင့်၏ပုံနှင့်စာသားမက်ဆေ့ခ်ျကို function ကိုနားလည်သဘောပေါက်နိုင်သည်။ PHP နှင့် WeChat API တို့၏ပေါင်းစပ်မှုကိုအသုံးပြုခြင်းသည်အချက်အလက်များကိုနောက်လိုက်များထံထိရောက်စွာတွန်းအားပေးနိုင်ပြီးအများပြည်သူဆိုင်ရာအကောင့်များနှင့်အသုံးပြုသူအပြန်အလှန်အတွေ့အကြုံများတိုးတက်လာသည်။
အမှန်တကယ်အသုံးပြုမှုတွင် ကျေးဇူးပြု. WeChat ၏တရားဝင် interface သို့ခေါ်ဆိုမှုအကြိမ်ရေအကန့်အသတ်နှင့်စနစ်တည်ငြိမ်မှုကိုသေချာစေရန်တွန်းအားပေးခြင်းများကိုဂရုပြုပါ။