See the micro-letter API documents added to the multi-customer service interface, you want to integrate its functions into the site's WP micro-letter plug-ins, the development process because of the misleading document, is really deceptive, micro-letter can not write documents seriously? But eventually, the final solution, first look at the effect of the picture:
Add a multiple Customer service account, you can also upload the avatar OH
The following is an API screenshot of the official document deceptive:
As pictured above, began to pay attention to the beginning of http://is wrong, but never thought, I checked the parameters and API URL is correct, incredibly give me the 48001 API is not authorized! I am depressed, I use more customer service of other add, update, Del interface is no problem, how this upload upload avatar is not authorized?
Helpless to find micro-letter official customer service, a silent question and answer after the final Solution! The original is the API URL of the/customservice/kfacount/in the Kfaccount less a C, really ah!!
The following code only for reference, after all, we write the way different, my process is to take the form data, first submitted to the add interface to many customer service, successful, then upload Avatar, and finally write into the database! The code for process processing is as follows:
/*
* Add multiple Customer service account
*/
Public Function Add_customer () {
$data = Array ();
foreach ($_post[' customer '] as $items) {
if (! empty ($items [' Value '])} {
$key = $items [' name '];
$val = $items [' value '];
if ($key = = ' Media_file ') {
$img _url = $val;
Continue
}
if ($key = = ' password ') {
$original _pass = $val;
$val = MD5 ($val);
}
$data [$key] = $val;
}
}
$res = $this->call ('/kfaccount/add ', $data, Self::json, Self::api_type_service);
if ($res) {
if ($img _url) {
$this->upload_customer_header ($img _url, $data [' Kf_account ']);
$data [' local_headimgurl '] = $img _url;
}
Global $wpdb;
$table = $wpdb->prefix. ' Wechat_customer ';
if (! empty ($original _pass)) $data [' password '] = $original _pass;
$wpdb->insert ($table, Array_merge ($data, Array (' Create_time ' => Time ()));
Exit (' OK ');
}
Exit (' Errcode: '. $this->_error_number. ' ErrMsg: '. $this->_error);
}
To change Wechat-json.php API class, add more customer Service Interface upload method:
Upload multiple customer service avatar must be JPG format, recommend 640*640 size of the picture to achieve the best results
Public Function Customerheaderupload ($file _full_path, $account = ') {
$this->_access_token = $this->getaccesstoken ();
$res = false;
if ($this->_access_token) {
$url = ' https://api.weixin.qq.com/customservice/kfaccount/uploadheadimg? ';
$url = $url. ' access_token= '. $this->_access_token. ' &kf_account= '. $account;
$res = $this->request ($url, Array (
' Media ' => ' @ $file _full_path,
), self::P ost);
}
return $res;
}