Stemmit mention tool -- Add wechat account valid function to bind steemit name to wechat account

in #utopian-io7 years ago (edited)

New Features

What feature(s) did you add?

  • Connect bot server to Wechat server

  • Get wechat account input and check the valid code to bind the Wechat account with the Steemit name

    图片.png

    图片.png

    图片.png

    图片.png

    图片.png


How did you implement it/them?

  • SteemitWechatBot/V0.2/Interface/application/index/common.php
function checkSignature()
  {
      //four parameters got from the wecaht server
      $signature = $_GET['signature'];
      $timestamp = $_GET['timestamp'];
      $nonce = $_GET['nonce'];
      //create a array to save the parameters
      $tempArr = array($nonce,$timestamp,TOKEN);
      //sorting 
      sort($tempArr,SORT_STRING);
      //change into string
      $tmpStr = implode($tempArr);
      //encryption with sha1
      $tmpStr = sha1($tmpStr);
      //Determine whether the request comes from the WeChat server, versus $tmpStr and $signature.
      if($tmpStr == $signature)
      {
          return true;
      }
      else
      {
          return false;
      }
  }   

Check bot server signature to connect to Wechat server.

  • SteemitWechatBot/V0.2/Interface/application/index/controller/Index.php
 public function validwechat()
    {
        define("TOKEN","weixin");
        if (isset($_GET['echostr'])) {
            valid();
        }else{
            $postData = $GLOBALS[HTTP_RAW_POST_DATA];
            if(!$postData)
            {
                echo  "error";
                exit();
            }
            $object = simplexml_load_string($postData,"SimpleXMLElement",LIBXML_NOCDATA);
            $MsgType = $object->MsgType;
            switch ($MsgType) { 
            case 'text':
                $content = $object ->Content;
                $openid = $object ->FromUserName;
                if (strstr($content, "valid"))
                {
                    $validcode = substr($content,6);
                    $valid = db('steemitaccount')->where('validcode', $validcode)->find();
                    if(!empty($valid))
                    {
                        $steemitname = $valid['steemitname'];
                        db('steemitname')->where('validcode',$valid)->update(['openid' => $openid]);
                        $reply = "Successfully bind your wechat to steemitname{{$steemitname}}";
                    }
                    else
                    {
                        $reply = "Please input the right valid code.";
                    }
                }
                else
                {
                     $reply = "Still in developing";
                }
                return replyText($obj,$reply);
                break;
            default: 
                break;
            }
        }
    }

After checking to connect to Wechat server , get wechat account input and valid the valid code to bind wechat account to the Steemit name ,which is put int the Web UI.

$replyXml = "
<xml>
<ToUserName><![CDATA[%s]]></ToUserName>
<FromUserName><![CDATA[%s]]></FromUserName>
<CreateTime>%s</CreateTime>
<MsgType><![CDATA[text]]></MsgType>
<Content><![CDATA[%s]]></Content>
</xml>";
//return a xml format data
$resultStr = sprintf($replyXml,$obj->FromUserName,$obj->ToUserName,time(),$content);
return $resultStr;        

Following the wechat message data xml format ,reply to wechat account to confirm.


Roadmap

  • Update wechat python bot to get the mention list .
  • Register a formal Wechat public service account to replace my testing account.

How to contribute?

Github: https://github.com/Cha0s0000/SteemitWechatBot

  • Fork it!
  • Create your feature branch: git checkout -b my-new-feature
  • Commit your changes: git commit -am 'Add some feature'
  • Push to the branch: git push origin my-new-feature
  • Submit a pull request.



Posted on Utopian.io - Rewarding Open Source Contributors

Sort:  

Thank you for the contribution. It has been approved. Please try to add more features in the future contributions.

You can contact us on Discord.
[utopian-moderator]

Thanks . I try to do it . But the development should go step by step because of the limit of time and different parts of function

Just a little note from me: I would recommend to write your code comments in English. ;)

Oh. Yeah ..I will change it . :D. Thanks for noticing

Hey @cha0s0000 I am @utopian-io. I have just upvoted you!

Achievements

  • You have less than 500 followers. Just gave you a gift to help you succeed!
  • Seems like you contribute quite often. AMAZING!

Community-Driven Witness!

I am the first and only Steem Community-Driven Witness. Participate on Discord. Lets GROW TOGETHER!

mooncryption-utopian-witness-gif

Up-vote this comment to grow my power and help Open Source contributions like this one. Want to chat? Join me on Discord https://discord.gg/Pc8HG9x

Coin Marketplace

STEEM 0.19
TRX 0.18
JST 0.034
BTC 89118.52
ETH 3131.33
USDT 1.00
SBD 2.76