Send message notification when license expired
To glue the bits you have together you need to relate your to-be-expiring-soon license with a uid which can feed into message_create. So something like this in your hook_cron call...

//...after assigning $license_ids

foreach($license_ids as $license_id) {

   //...@TODO: checks on previous alert messages

   $uid = db_select('commerce_license','cl')
     -&gt;fields('cl', array('uid'))
     -&gt;condition('license_id', $license_id)
     -&gt;execute()-&gt;fetchField();

   //...@TODO: code for executing message_notify_send_message and sending message to $uid
}